您的位置:首页 > 其它

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