MyBatisPlus 只更新指定字段
原理
MyBatisPlus提供的update方法的第一个参数是实体对象,传入null时表示不更新实体中的其他字段:
default boolean update(T entity, Wrapper updateWrapper)
示例代码
@SpringBootTest
public class DemoTest {@Resourceprivate FunctionService functionService;@Testvoid fun() {functionService.update(null, Wrappers.<Function>lambdaUpdate().set(Function::getState, FunctionStateEnum.ENABLE).eq(Function::getId, 56L));}}