1.业务形容:
将数据库中的商品信息从数据库查问进去,而后进行删除、修 改、增加等操作。
2.技术架构设计:整体仍旧基于“分而治之”的设计思维,采纳MVC分层对业务进行技术实现。
3.基于特定架构下技术选型:
1)SpringBoot 治理依赖,提供根底配置,实现开箱即用
2)HikariCP 定义连接池
3)MyBatis 实现数据的长久操作
4)Spring IOC 实现资源整合
5)Spring Web 模块实现申请响应解决
6)Thymeleaf 基于此对象实现html模板解析
4.外围API(接口和类)的设计
1)pojo (Goods)
2)dao (GoodsDao,GoodsMapper.xml)
3)service(GoodsService,GoodsServiceImpl)
4)controller (GoodsController)
商品信息的查问并出现:
1)Goods (id,name,remark,createdTime)
2)GoodsDao (@Mapper):List<Goods> findGoods();
3)GoodsMapper.xml(mapper/goods/GoodsMapper.xml)
4)GoodsService,GoodsServiceImpl (@Service)
5)GoodsController(@Controller): String doFindGoods(){return goods;}
6)goods.html (templates/modules/)
第一步:定义商品pojo对象Goods,基于此对象封装商品数据。
public class Goods { private Integer id; private String name; private String remark; private Date createdTime; @Override public String toString() { return "Goods{" + "id=" + id + ", name='" + name + '\'' + ", remark='" + remark + '\'' + ", createdTime=" + createdTime + '}';}public Integer getId() { return id;}public void setId(Integer id) { this.id = id;}public String getName() { return name;}public void setName(String name) { this.name = name;}public String getRemark() { return remark; }public void setRemark(String remark) { this.remark = remark; }public Date getCreatedTime() { return createdTime; }public void setCreatedTime(Date createdTime) { this.createdTime = createdTime; }}
第二步:定义GoodsDao接口及查询方法
package com.cy.pj.goods.dao;@Mapperpublic interface GoodsDao{ List<Goods> findGoods(String name);}
第三步:定义GoodsMapper.xml文件并增加查问SQL映射
...<mapper namespace="com.cy.pj.goods.dao.GoodsDao"> <select id="findGoods" resultType="com.cy.pj.goods.pojo.Goods"> select * from tb_goods <where> <if test="name!=null and name!=''"> name like concat ("%",#{name},"%") </if> </where> </select></mapper>
第四步:定义GoodsService接口及查询方法
定义GoodsService接口及查询方法
package com.cy.pj.goods.service;public interface GoodsService{ List<Goods> findGoods(String name);}
定义GoodsService接口实现类GoodsServiceImpl并重写相干办法
package com.cy.pj.goods.service.impl;@Servicepublic class GoodsServiceImpl implements GoodsService{ @Autowired private GoodsDao goodsDao; public List<Goods> findGoods(String name){ return goodsDao.findGoods(name); } }
第五步:定义GoodsController类及解决查问申请的办法
package com.cy.pj.goods.controller;@Controller@RequestMapping("/goods/")public class GoodsController{ @Autowired private GoodsService goodsService; @RequestMapping("doFindGoods") public String doFindGoods(String name,Model model){ List<Goods> list=goodsService.findGoods(name); model.addAttribute("list",list); return "goods"; }}