MyBatis集合查询易错
2016-05-30 11:24
453 查看
关于collection
第一种写法<resultMap id="BaseResultMap" type="com.ihefe.nurses.entity.common.OptTypeBean" > <id column="ih_opt_type_id" property="ihOptTypeId" jdbcType="INTEGER" /> <result column="opt_type_name" property="optTypeName" jdbcType="VARCHAR" /> <result column="opt_category" property="optCategory" jdbcType="VARCHAR" /> <result column="hospital_id" property="hospitalId" jdbcType="INTEGER" /> <result column="multi_value" property="multiValue" jdbcType="INTEGER" /> <result column="recordItemId" property="recordItemId" jdbcType="INTEGER" /> <collection property="optCdList" ofType="OptCdBean" resultMap="CdBaseResultMap"/> </resultMap>
第二种写法
<resultMap id="BaseResultMap" type="com.ihefe.nurses.entity.common.OptTypeBean" > <result column="ih_opt_type_id" property="ihOptTypeId" jdbcType="INTEGER" /> <result column="opt_type_name" property="optTypeName" jdbcType="VARCHAR" /> 4000 <result column="opt_category" property="optCategory" jdbcType="VARCHAR" /> <result column="hospital_id" property="hospitalId" jdbcType="INTEGER" /> <result column="multi_value" property="multiValue" jdbcType="INTEGER" /> <result column="recordItemId" property="recordItemId" jdbcType="INTEGER" /> <collection property="optCdList" ofType="OptCdBean" resultMap="CdBaseResultMap"/> </resultMap>
上面的第一种写法使用了MyBatis了的id(主键),这样一来mybatis只要认为id一样,这就是一条数据。对于第二种写法,所有字段合成一个字段。
相关文章推荐
- 深入浅析mybatis oracle BLOB类型字段保存与读取
- MyBatis MapperProvider MessageFormat拼接批量SQL语句执行报错的原因分析及解决办法
- SpringMVC整合mybatis实例代码
- oracle+mybatis 使用动态Sql当插入字段不确定的情况下实现批量insert
- MyBatis学习笔记(二)之关联关系
- 浅析Mybatis 在CS程序中的应用
- Java Mybatis框架入门基础教程
- Windows下Java+MyBatis框架+MySQL的开发环境搭建教程
- Mybatis与Ibatis的区别
- MyBatis学习教程(二)―如何使用MyBatis对users表执行CRUD操作
- MyBatis学习教程(四)-如何快速解决字段名与实体类属性名不相同的冲突问题
- Java简单实现SpringMVC+MyBatis分页插件
- MyBatis批量添加、修改和删除
- MyBatis与Hibernate的比较
- 浅析mybatis和spring整合的实现过程
- 在Java的MyBatis框架中建立接口进行CRUD操作的方法
- 整理Java的MyBatis框架中一些重要的功能及基本使用示例
- mybatis的动态sql详解(精)
- MyBatis实践之动态SQL及关联查询
- 详解Mybatis动态sql