以前一直用mybatis,后来单位框架改成mybatis-plus之后,真的开阔了世界,非常好用,这里简单说一下用 update吧
首先是 interface service 中继承 extends IService<实体类>
然后对应的 impl 中记得使用 @Service 注解
然后就可以在有 @RestController 的类中肆意 @Autowired 了
注入:
@Autowired
private Service service;
调用:
UpdateWrapper<实体类> updateWrapper = new UpdateWrapper<>();
updateWrapper
.set("a", "1")
.set("b", "2")
.eq("c", "3");
service.update(null, updateWrapper); // 完成调用
上述功能等于是写了一个 update sql :
update 实体类对应的表
set a = '1',b = '2'
where c = '3';