MyBatis集合查询易错

来源:互联网 发布:vua软件 编辑:程序博客网 时间:2024/06/04 18:47

关于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" />    <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一样,这就是一条数据。对于第二种写法,所有字段合成一个字段。
0 0
原创粉丝点击