1、Goods1、DAO层: 持久层 主要与数据库进行交互DAO层首先会创建DAO接口,也就是说DAO层里面有一个专门写接口的类,然后会在配置文件(xml文件,也就是写SQL语句的文件,所以说DAO层是与数据库进行交互的层)中定义该接口的实现类,接着就可以在模块中就可以调用DAO 的接口进行数据业务的而处理,并且不用关注此接口的具体实现类是哪一个类。DAO 层的数据源和数据库连接的参数都是在配置文件中进行配置的。2、Entity层: 实体层 数据库在项目中的类3、Service层:业务层 控制业务Service层主要负责业务模块的逻辑应用设计。和DAO层一样都是先设计放接口的类,再创建实现的类,然
2、后在配置文件中进行配置其实现的关联。接下来就可以在service层调用接口进行业务逻辑应用的处理。封装Service层的业务逻辑有利于业务逻辑的独立性和重复利用性。4、Controller层: 控制层 控制业务逻辑Controller层负责具体的业务模块流程的控制,其实就是与前台互交,把前台传进来的参数进行处理,controller层主要调用Service层里面的接口控制具体的业务流程,控制的配置也需要在配置文件中进行。四、概要设计Goods表Goods_user表已存储的商品信息表Controller层商品实现代码:用户实现代码:Dao层对应的mapper文件对应的实体:Service层:c
3、ontroller层:Goods:package ;import /goods)public class GoodsController Autowired private GoodsService goodsService; public GoodsService getGoodsService() return goodsService; public void setGoodsService(GoodsService goodsService) = goodsService; RequestMapping(/selectAll public String selectAll(HttpSe
4、rvletRequest request) throws Exception List goods = (); (goods, goods); return forward:/product/;/save public String save(Goods goods) (goods);/goods/delete) public String delete(Integer id) throws Exception (id);/selectByID public String selectByID(Integer id,HttpServletRequest request) Goods goods
5、 = (id);/updateGoods public String updateGoods(Goods goods) (goods);User:/userpublic class UserController private UserService userService; public UserService getUserService() return userService; public void setUserService(UserService userService) = userService; / mapper namespace= select * from good
6、s order by id/selectselectByID select * from goods where id=#idinsert id=save insert into goods(id,name,price,description) values(#id,#name,#price,#description)/insertdelete id=delete delete from goods where id=#id /deleteupdate id=updateGoods update goodsset price! price=#price,description descript
7、ion=#description where id =#id/set/update/mapperimport interface UserDAO insert into goods_user (user_name,name,age,password,sex) values(#user_name,#name,#age,#password,#sex)selectByUsernameAndPasswordUser select * from goods_user where user_name=#u and password=#pEntity层:goods:public class Goods pr
8、ivate Integer id; private String name; private double price; private String description; public Integer getId() return id; public void setId(Integer id) = id; public String getName() return name; public void setName(String name) = name; public double getPrice() return price; public void setPrice(dou
9、ble price) = price; public String getDescription() return description; public void setDescription(String description) = description; public Goods(Integer id, String name, double price, String description) public Goods() super(); / TODO Auto-generated constructor stub Override public String toString(
10、) Goods id= + id + , name= + name + , price= + price + , description= + description + public class User private String user_name; private int age; private String password; private String sex; public String getUser_name() return user_name; public void setUser_name(String user_name) = user_name; publi
11、c int getAge() return age; public void setAge(int age) = age; public String getPassword() return password; public void setPassword(String password) = password; public String getSex() return sex; public void setSex(String sex) = sex; public User(String user_name, String name, int age, String password
12、, String sex) public User() User user_name= + user_name + , age= + age + , password= + password + , sex= + sex + service层import interface GoodsService /查询所有商品 public List selectAll(); /增加商品 public void save(Goods goods); /删除商品 public void delete(Integer id); /通过ID查询 public Goods selectByID(Integer i
13、d); /修改 public void updateGoods(Goods goods);对应服务层接口:import class GoodsServiceImpl implements GoodsService private GoodsDAO goodsDAO; public GoodsDAO getGoodsDAO() return goodsDAO; public void setGoodsDAO(GoodsDAO goodsDAO) = goodsDAO; /提高查询效率 Transactional(propagation=,readOnly=true) selectAll() re
14、turn goods; public void save(Goods goods) public void delete(Integer id) public Goods selectByID(Integer id) public void updateGoods(Goods goods) (goods);User;import interface UserService /注册 public void register(User user); /登录 public User login(String user_name , String password);import class User
15、ServiceImpl implements UserService private UserDAO userDAO; public UserDAO getUserDAO() return userDAO; public void setUserDAO(UserDAO userDAO) = userDAO; public void register(User user) (user); public User login(String user_name, String password) User user = (user_name, password); return user;结束语:本次实验的设计与开发,是对本学期学习的一种很好的总结,在本学期的实验中,本次实验很具有挑战性,因此我选择了这个项目作为我的实验项目,在完成了实验的时候,我也遇到了许多困难与错误,在需求不明确的时候盲目的开发造成错误百出,某些知识点的掌握还不够,也有一些地方与预期不相符,我不得不查询各种资料,在一次次探讨之中,我慢慢的掌握的许多知识,在这些知识的认识之下,完成了该实验的设计与开发,技术与业务能力也有所提高,这对以后的事业发展有一定的积极影响作用
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1