以Update更新为例,如果传统sql语句,我们只是更新部分数据,需要加许多判断。
为了解决这个问题, 我们引入了动态更新sql的方法:
1.创建一个包 XXXProvider
//添加方法 public String updateVideo(final Video video)
{ return new SQL(){{
UPDATE("video");
//条件写法
if(video.getTitle()!= null){
SET("title=#{title}"); }
WHERE("id=#{id}"); }}.toString(); }
2.修改数据访问层
添加注释
@UpdateProvider(type= VideoProvider.class,method = "updateVideo")
//第一个是包名,第二个是方法名
3.修改完成之后,我们使用postman进行json验证,采用put形式, json格式要注意别写错,通过json传递部分数据进行验证update功能。