mybatis collection 多条件查询
来源:互联网 发布:个人网盘系统源码 编辑:程序博客网 时间:2024/05/17 04:37
业务需要通过mybatis 查询返回嵌套集合,嫌多次查询太麻烦,用自带的高级查询解决问题,下边是代码,已测试通过。
说下自己的理解,就是一个主查询结果集里面嵌套了子查询的结果集,可以是多个子查询,每个子查询的条件从主查询结果集中获取,返回值各自定义。
collection 标签的property是主查询里面集合的名字,如果有多个就再写个collection,column是子查询参数,单参数直接写主查询结合返回结果,例如直接写上user_id,要是数据库的字段,多条件就封装下,例如{userId=user_id,theme=theme},然后子查询的parameterType写"java.util.Map",多条件查询好像只有mybatis3.0以后才有,看网上资料说的,没验证过,ofType是集合里的对象,select是对应下面的语句
<resultMap id="BaseResultMap" type="web.model.UserMessage" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="user_id" property="userId" jdbcType="INTEGER" /> <result column="theme" property="theme" jdbcType="VARCHAR" /> <result column="status" property="status" jdbcType="INTEGER" /> <result column="theme_time" property="themeTime" jdbcType="TIMESTAMP" /> <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> <result column="yn" property="yn" jdbcType="INTEGER" /> </resultMap><resultMap id="BaseVoResultMap" type="web.model.vo.UserMessageVo" extends="BaseResultMap"> <collection property="userMessageDetailList" column="{userId=user_id,theme=theme}" javaType="java.util.ArrayList" ofType="web.model.UserMessageDetail" select="selectUserMessageDetailById"/> </resultMap><resultMap id="BaseDetailResultMap" type="web.model.UserMessageDetail" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="user_message_id" property="userMessageId" jdbcType="INTEGER" /> <result column="sponsor_id" property="sponsorId" jdbcType="INTEGER" /> <result column="user_id" property="userId" jdbcType="INTEGER" /> <result column="user_type" property="userType" jdbcType="INTEGER" /> <result column="provider_id" property="providerId" jdbcType="INTEGER" /> <result column="message" property="message" jdbcType="VARCHAR" /> <result column="status" property="status" jdbcType="INTEGER" /> <result column="message_time" property="messageTime" jdbcType="TIMESTAMP" /> <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> <result column="yn" property="yn" jdbcType="INTEGER" /> </resultMap> <select id="selectUserMessageById" resultMap="BaseVoResultMap" parameterType="java.lang.Integer"> select * from user_message where user_id = #{userId,jdbcType=INTEGER} </select> <select id="selectUserMessageDetailById" resultMap="BaseDetailResultMap" parameterType="java.util.Map"> select * from user_message_detail where user_id = #{userId,jdbcType=INTEGER} and message = #{theme,jdbcType=VARCHAR} </select>
selectUserMessageById,这个是主查询,VO只多了个 private List<UserMessageDetail> userMessageDetailList,这个属性,下面是返回值结构截图
0 0
- mybatis collection 多条件查询
- MyBatis多条件查询
- Mybatis 多条件查询
- mybatis的多条件查询
- Mybatis 多条件动态查询
- mybatis多条件语句查询
- mybatis的多条件查询
- mybatis多条件的模糊查询解决方案
- mybatis中mysql多条件查询
- MyBatis--Map实现多条件查询
- MyBatis--索引号实现多条件查询
- mybatis中根据多条件list查询
- MyBatis级联多条件分页查询
- mybatis笔记-多条件动态查询
- mybatis 智能标签+多条件查询
- Mybatis 注解形式多条件查询
- Mybatis中动态sql(多条件查询)
- Mybatis多个条件的查询
- 下级不能比上级工资高吗?
- JAVA多线程
- mybatis中 insert into select 批量生成uuid时 用replace去掉"-"只生成一个uuid
- 云时代的分布式数据库:阿里分布式数据库服务DRDS
- 关于Fragment中嵌套不能包含include自定义标题的解决方案.txt
- mybatis collection 多条件查询
- 如何提高自己代码的质量(新手篇)
- redis禁用keys命令做模糊匹配
- ionic开发——点击图片查看大图
- 最强大脑!windows7系统下载给你不一般的体验!
- 网络精灵
- Mac下无法通过localhost连接数据库解决方法
- swift的字符串
- Java反射机制介绍