1、南 阳 理 工 学 院Java企业级开发学院(系) : 软件学院 专 业 : 移动 1班 完成日期 2018 年 12 月目录1、项目简介2、项目需求分析3、功能模块分析4、概要设计 1. 功能模块图2. 数据库 ER 图3. 数据表5、项目实现1. 项目关键代码2. 界面抓图1、项目简介主要是根据需求分析,该实验实现了浏览器和浏览器服务器的交互,浏览器能够就行网页浏览,在浏览器中需要地址栏对指定页面进行访问,需要专门的按钮进行跳转,在前后浏览页面之间要能够进行跳转,并且连接数据库完成增删改查的操作,开发这个网站可以正常实现连接 TomCat 网络,能够进行网页浏览,并且能够查看页面源代码。页
2、面源代码查看,前进,后退,主页,停止,刷新等功能。Tomcat 服务器则实现了 IP 设置,根目录设置,统计信息展示等。在操作不当的情况下有相应的信息提示,错误处理机制完备.系统各个模块之间都有相应错误处理机制,功能模块之前划分比较细致,有利于发现问题后的及时解决,在做好完备的功能模块详细设计之后,系统的开发时间会大幅减少。2、项目需求分析该实验设计是基于 Windows 操作系统平台设计并实现的电商网站开发系统,其主要目的就是用户能够使用该系统进行商品的增删改查操作,以及用户的注册与登陆,同时方便系统管理员在网络直接进行各种商品操作。1.用户登陆与注册管理模块Login + Regist2.
3、网站商品管理模块Goods三、功能模块分析1、DAO 层: 持久层 主要与数据库进行交互DAO 层首先会创建 DAO 接口,也就是说 DAO 层里面有一个专门写接口的类,然后会在配置文件(xml 文件,也就是写 SQL 语句的文件,所以说 DAO 层是与数据库进行交互的层)中定义该接口的实现类,接着就可以在模块中就可以调用 DAO 的接口进行数据业务的而处理,并且不用关注此接口的具体实现类是哪一个类。DAO 层的数据源和数据库连接的参数都是在配置文件中进行配置的。2、Entity 层: 实体层 数据库在项目中的类3、Service 层:业务层 控制业务Service 层主要负责业务模块的逻辑应
4、用设计。和 DAO 层一样都是先设计放接口的类,再创建实现的类,然后在配置文件中进行配置其实现的关联。接下来就可以在 service 层调用接口进行业务逻辑应用的处理。封装 Service 层的业务逻辑有利于业务逻辑的独立性和重复利用性。4、Controller 层: 控制层 控制业务逻辑Controller 层负责具体的业务模块流程的控制,其实就是与前台互交,把前台传进来的参数进行处理,controller 层主要调用Service 层里面的接口控制具体的业务流程,控制的配置也需要在配置文件中进行。四、概要设计1.功能模块图2.数据库 ER 图3.数据表Goods 表Goods_user 表
5、已存储的商品信息表五、项目实现Controller 层商品实现代码:Controller 层用户实现代码:Dao 层商品实现代码:对应的 mapper 文件Dao 层商品实现代码:对应的 mapper 文件对应的实体:Service 层:controller 层:Goods:package com.controller;import java.util.List;import javax.servlet.http.HttpServletRequest;import org.springframework.beans.factory.annotation.Autowired;import org
6、.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.entity.Goods;import com.service.GoodsService;ControllerRequestMapping(“/goods“)public class GoodsController Autowiredprivate GoodsService goodsService;public GoodsService getGoodsService()
7、 return goodsService;public void setGoodsService(GoodsService goodsService) this.goodsService = goodsService;RequestMapping(“/selectAll“)public String selectAll(HttpServletRequest request) throws ExceptionList goods = goodsService.selectAll();request.setAttribute(“goods“, goods);return “forward:/pro
8、duct/productlist.jsp“;RequestMapping(“/save“)public String save(Goods goods)goodsService.save(goods);return “forward:/goods/selectAll.do“;RequestMapping(“/delete“) public String delete(Integer id) throws ExceptiongoodsService.delete(id);return “forward:/goods/selectAll.do“;RequestMapping(“/selectByI
9、D“)public String selectByID(Integer id,HttpServletRequest request)Goods goods = goodsService.selectByID(id);request.setAttribute(“goods“, goods);return “forward:/product/update.jsp“;RequestMapping(“/updateGoods“)public String updateGoods(Goods goods)System.out.println(goods);goodsService.updateGoods
10、(goods);return “forward:/goods/selectAll.do“;User:package com.controller;import javax.servlet.http.HttpSession;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.entit
11、y.User;import com.service.UserService;ControllerRequestMapping(“/user“)public class UserController Autowiredprivate UserService userService;public UserService getUserService() return userService;public void setUserService(UserService userService) this.userService = userService;/注册RequestMapping(“/re
12、gister“) /接受数据public String register(User user) throws Exception/调用 Service 中的注册功能userService.register(user);/跳转器return “forward:/user/login.html“;/登录RequestMapping(“/login“)public String login(String user_name,String password,HttpSession session) throws ExceptionUser user = userService.login(user_n
13、ame, password);if(user!=null)session.setAttribute(“name“, user.getUser_name();String name = (String)session.getAttribute(“name“);System.out.println(name);/跳转页面return “forward:/goods/selectAll.do“;elsereturn “forward:/user/login.html“;dao 层Goods:package com.dao;import java.util.List;import com.entity
14、.Goods;public interface GoodsDAO /查询所有商品public List selectAll();/添加商品public void save(Goods goods);/删除商品public void delete(Integer id);/通过 ID 查询public Goods selectByID(Integer id);/修改商品信息public void updateGoods(Goods goods);对应 mapper 文件select * from goods order by idselect * from goods where id=#ids
15、elect a.nextval from dualinsert into goods(id,name,price,description) values(#id,#name,#price,#description)delete from goods where id=#id update goodsname=#name,price=#price,description=#descriptionwhere id =#idUser:package com.dao;import org.apache.ibatis.annotations.Param;import com.entity.User;pu
16、blic interface UserDAO /插入一条数据public void save(User user);/通过 user_name 和 password 查询public User selectByUsernameAndPassword(Param(“u“)String user_name,Param(“p“)String password);对应 mapper 文件insert into goods_user (user_name,name,age,password,sex) values(#user_name,#name,#age,#password,#sex)select *
17、 from goods_user where user_name=#u and password=#pEntity 层:goods:package com.entity;public class Goods private Integer id;private String name;private double price;private String description;public Integer getId() return id;public void setId(Integer id) this.id = id;public String getName() return na
18、me;public void setName(String name) this.name = name;public double getPrice() return price;public void setPrice(double price) this.price = price;public String getDescription() return description;public void setDescription(String description) this.description = description;public Goods(Integer id, St
19、ring name, double price, String description) this.id = id;this.name = name;this.price = price;this.description = description;public Goods() super();/ TODO Auto-generated constructor stubOverridepublic String toString() return “Goods id=“ + id + “, name=“ + name + “, price=“ + price+ “, description=“
20、 + description + “;User:package com.entity;public class User private String user_name;private String name;private int age;private String password;private String sex;public String getUser_name() return user_name;public void setUser_name(String user_name) this.user_name = user_name;public String getNa
21、me() return name;public void setName(String name) this.name = name;public int getAge() return age;public void setAge(int age) this.age = age;public String getPassword() return password;public void setPassword(String password) this.password = password;public String getSex() return sex;public void set
22、Sex(String sex) this.sex = sex;public User(String user_name, String name, int age, String password,String sex) this.user_name = user_name;this.name = name;this.age = age;this.password = password;this.sex = sex;public User() super();/ TODO Auto-generated constructor stubOverridepublic String toString
23、() return “User user_name=“ + user_name + “, name=“ + name + “, age=“+ age + “, password=“ + password + “, sex=“ + sex + “;service 层Goods:package com.service;import java.util.List;import com.entity.Goods;public interface GoodsService /查询所有商品public List selectAll();/增加商品public void save(Goods goods);
24、/删除商品public void delete(Integer id);/通过 ID 查询public Goods selectByID(Integer id);/修改public void updateGoods(Goods goods);对应服务层接口:package com.service;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springfram
25、ework.transaction.annotation.Propagation;import org.springframework.transaction.annotation.Transactional;import com.dao.GoodsDAO;import com.entity.Goods;ServiceTransactionalpublic class GoodsServiceImpl implements GoodsServiceAutowiredprivate GoodsDAO goodsDAO;public GoodsDAO getGoodsDAO() return go
26、odsDAO;public void setGoodsDAO(GoodsDAO goodsDAO) this.goodsDAO = goodsDAO;Override/提高查询效率Transactional(propagation=Propagation.SUPPORTS,readOnly=true)public List selectAll() List goods = goodsDAO.selectAll();return goods;Overridepublic void save(Goods goods) goodsDAO.save(goods);Overridepublic void
27、 delete(Integer id) goodsDAO.delete(id);Overridepublic Goods selectByID(Integer id) Goods goods = goodsDAO.selectByID(id);return goods;Overridepublic void updateGoods(Goods goods) goodsDAO.updateGoods(goods);User;package com.service;import java.util.List;import com.entity.User;public interface UserS
28、ervice /注册public void register(User user);/登录public User login(String user_name , String password);对应服务层接口:package com.service;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Propagation;imp
29、ort org.springframework.transaction.annotation.Transactional;import com.dao.UserDAO;import com.entity.User;ServiceTransactionalpublic class UserServiceImpl implements UserService Autowiredprivate UserDAO userDAO;public UserDAO getUserDAO() return userDAO;public void setUserDAO(UserDAO userDAO) this.
30、userDAO = userDAO;Overridepublic void register(User user) userDAO.save(user);Override/提高查询效率Transactional(propagation=Propagation.SUPPORTS,readOnly=true)public User login(String user_name, String password) User user = userDAO.selectByUsernameAndPassword(user_name, password);return user;结束语:本次实验的设计与开发,是对本学期学习的一种很好的总结,在本学期的实验中,本次实验很具有挑战性,因此我选择了这个项目作为我的实验项目,在完成了实验的时候,我也遇到了许多困难与错误,在需求不明确的时候盲目的开发造成错误百出,某些知识点的掌握还不够,也有一些地方与预期不相符,我不得不查询各种资料,在一次次探讨之中,我慢慢的掌握的许多知识,在这些知识的认识之下,完成了该实验的设计与开发,技术与业务能力也有所提高,这对以后的事业发展有一定的积极影响作用