mybatis-plus的${ew.sqlSegment},${ew.sqlSelect},${ew.sqlSet},${ew.customSqlSegment}使用与区别
ew是mapper方法里的@Param(Constants.WRAPPER) Wrapper queryWrapper对象。
·
说明:
ew是mapper方法里的@Param(Constants.WRAPPER) Wrapper queryWrapper对象
1、${ew.customSqlSegment} 会直接在前面添加 where
@Select(select * from sys_user ${ew.customSqlSegment})
List<SysUser> listPage(@Param(Constants.WRAPPER) QueryWrapper queryWrapper)
2、${ew.sqlSegment} 就只有条件语句
@Select(select * from sys_user where ${ew.sqlSegment})
List<SysUser> listPage@Param(Constants.WRAPPER) QueryWrapper queryWrapper)
3、${ew.sqlSelect} 就是 queryWrapper.select(****) 你所定义需要查询的字段
实例1:
@Select(select ${ew.sqlSelect} from sys_user )
List<SysUser> listPage(@Param(Constants.WRAPPER) QueryWrapper queryWrapper)
实例2:
<select id="selectUser" resultType="com.example.demo.entity.User">
select
<if test="ew != null and ew.sqlSelect != null and ew.sqlSelect != ''">
${ew.sqlSelect}
</if>
from
sys_user
where is_deleted != 1
<if test="ew != null">
<if test="ew.nonEmptyOfWhere">
AND
</if>
${ew.sqlSegment}
</if>
</select>
4、${ew.sqlSet}用于update语句
boolean updateById(@Param("tableName") String tableName,@Param(Constants.WRAPPER) Wrapper wrapper);
实例1
<update id="updateById">
update ${tableName} set ${ew.sqlSet} ${ew.customSqlSegment};
</update>
实例2
<update id="updateUser">
update sys_user
set ${ew.sqlSet}
where ${ew.sqlSegment}
</update>
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)