说明:
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>