wrapper+ xml文件进行SQL编写

如何使用 wrapper+ xml文件进行SQL编写:

service层

多表联查时可以通过指定表名的方式,最终在mapper.xml会进行解析。

java 复制代码
QueryWrapper<SysMenu> wrapper = Wrappers.query();
wrapper.eq("sur.user_id", userId)
       .orderByAsc("m.parent_id")
       .orderByAsc("m.order_num");
menuList = baseMapper.selectMenuListByUserId(wrapper);

mapper接口

重点:@Param(Constants.WRAPPER)

java 复制代码
List<SysMenu> selectMenuListByUserId(@Param(Constants.WRAPPER) Wrapper<SysMenu> queryWrapper);

mapper.xml

重点:${ew.getCustomSqlSegment}或者使用${ew.sqlSegment} 获取的sql片段还可以使用表达式,如:${ew.sqlSegment.split('ORDER BY')[0]}

xml 复制代码
<select id="selectMenuListByUserId" resultMap="SysMenuResult">
	select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query_param, m.visible, m.status,
	                m.perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
	from sys_menu m
	left join sys_role_menu rm on m.menu_id = rm.menu_id
	left join sys_user_role sur on rm.role_id = sur.role_id
	left join sys_role ro on sur.role_id = ro.role_id
       ${ew.getCustomSqlSegment}
</select>
相关推荐
indexsunny11 小时前
互联网大厂Java面试实战:Spring Boot、MyBatis与Kafka在电商场景中的应用
java·spring boot·面试·kafka·mybatis·电商·技术栈
神の愛13 小时前
mybatis什么时候不走 缓存??
spring·缓存·mybatis
小哇6661 天前
MybatisPlus-JSON类型处理器 存取 数据库的JSON 字段数据
mybatis
難釋懷1 天前
缓存同步
spring·缓存·mybatis
阿丰资源1 天前
SpringBoot+MySQL+MyBatis-Plus+Vue前后端分离仓库管理系统 (附资料)
spring boot·mysql·mybatis
等....2 天前
Redis使用
数据库·redis·mybatis
卓怡学长2 天前
m326数据结构课程网络学习平台的设计与实现+vue
java·spring·tomcat·maven·intellij-idea·mybatis