增删改查 语句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 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 list=goodsService.findGoods();
model.addAttribute("list", list);
return "goods";
}
}333333333333333
查看 加删除
Insert title hereThe Goods Page
添加商品 id
name
remark
createdTime
operation
1
AAA
AAAAA
2020/09/01
添加
Insert title hereul li {list-style-type: none}
The Goods Add Page
- name:
- remark:
33333333333333333
修改加查看在加一个查看
Insert title hereul li {list-style-type: none}
The Goods Update Page
- name:
- remark: