1

增删改查 语句sql
@Mapper
public interface GoodsDao {


 @Update("update tb_goods set name=#{name},remark=#{remark} where id=#{id} ")
 int updateGoods(Goods goods);

 @Insert("insert into tb_goods(name,remark,createdTime) values (#{name},#{remark},#{createdTime})")
 int insertGoods(Goods goods);

 @Select("select id,name,remark,createdTime from tb_goods where id=#{id}")
 Goods findById(Integer id);
 
 @Select("select id,name,remark,createdTime from tb_goods")
 List<Goods> findGoods();
 
 @Delete("delete from tb_goods where id=#{id}")
 int deleteById(Integer id);

}

连接层;;;;;;;;;;;
@Controller
@RequestMapping("/goods/")
public class GoodsController {

 @Autowired
 private GoodsService goodsService;
 
 @RequestMapping("doGoodsAddUI")
 public String doGoodsAddUI() {
     return "goods-add";
 }
 
 @RequestMapping("doFindById/{id}")
 public String doFindById(@PathVariable Integer id,Model model) {
     Goods goods=goodsService.findById(id);
     model.addAttribute("goods",goods);
     return "goods-update";//此view由谁解析?ViewResolver(ThymeleafViewResolver)
     //这里的ThymeleafViewResolver做了什么?
     //1)在viewname的基础上添加前缀和后缀(/templates/pages/goods-update.html),并找到对应的view(真正的页面对象)
     //2)将model中的数据取出,然后填充到view上(/templates/pages/goods-update.html)
     //3)将view交给DispatcherServlet
 }
 
 @RequestMapping("doUpdateGoods")
 public String doUpdateGoods(Goods goods) {
     goodsService.updateGoods(goods);
     return "redirect:/goods/doGoodsUI";
 }
 
 @RequestMapping("doSaveGoods")
 public String doSaveGoods(Goods goods) {
     goodsService.saveGoods(goods);
     return "redirect:/goods/doGoodsUI";
 }
 
 @RequestMapping("doDeleteById/{id}")
 public String doDeleteById(@PathVariable Integer id) {
     goodsService.deleteById(id);
     return "redirect:/goods/doGoodsUI";
 }
 
 @RequestMapping("doGoodsUI")
 public String doFindGoods(Model model) {
     List<Goods> list=goodsService.findGoods();
     model.addAttribute("list", list);
     return "goods";
 }
 

}

333333333333333

查看 加删除
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>The Goods Page</h1>
添加商品

id name remark createdTime operation
1 AAA AAAAA 2020/09/01 delete update

</body>
</html>

添加
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
ul li {list-style-type: none}
</style>
</head>
<body>
<h1>The Goods Add Page</h1>
<form th:action="@{/goods/doSaveGoods}" method="post">

 <ul>
    <li>name:
    <li><input type="text" name="name">
    <li>remark:
    <li><textarea cols="30" rows="5" name="remark"></textarea>
    <li><input type="submit" value="Save Goods">
 </ul>

</form>
</body>
</html>

33333333333333333

修改加查看在加一个查看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
ul li {list-style-type: none}
</style>
</head>
<body>
<h1>The Goods Update Page</h1>
<form th:action="@{/goods/doUpdateGoods}" method="post">

 <input type="hidden" name="id" th:value="${goods.id}">
 <ul>
    <li>name:
    <li><input type="text" name="name" th:value="${goods.name}">
    <li>remark:
    <li><textarea cols="30" rows="5" name="remark" th:text="${goods.remark}"></textarea>
    <li><input type="submit" value="Update Goods">
 </ul>

</form>
</body>
</html>


CV战士
7 声望1 粉丝