Mybatis之collection嵌套查询mapper文件写法
mapper.xml写法举例
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 3 <mapper namespace="maserati.dao.meta.list.ListSchemaMapper"> 4 <resultMap id="BaseResultMap" type="maserati.dao.meta.list.entity.ListSchemaEntity"> 5 <id column="id" property="id" jdbcType="INTEGER"/> 6 <result column="mod_name" property="modName" jdbcType="VARCHAR"/> 7 <result column="prop_name" property="propName" jdbcType="VARCHAR"/> 8 <result column="prop_desc" property="propDesc" jdbcType="VARCHAR"/> 9 <result column="del_flag" property="delFlag" jdbcType="BIT"/> 10 <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> 11 <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/> 12 </resultMap> 13 14 15 <resultMap id="ListMeta" type="maserati.dao.meta.list.entity.ListMeta"> 16 <result column="mod_name" property="modName" jdbcType="VARCHAR"/> 17 <result column="mod_desc" property="modTitle" jdbcType="VARCHAR"/> 18 <collection property="tHeads" ofType="maserati.dao.meta.list.entity.PropMeta" 19 select="selectTableHeads" column="mod_name" javaType="ArrayList"/> 20 </resultMap> 21 <resultMap id="TableHead" type="maserati.dao.meta.list.entity.PropMeta"> 22 <result property="propName" column="prop_name" jdbcType="VARCHAR"/> 23 <result property="propDesc" column="prop_desc" jdbcType="VARCHAR"/> 24 <result property="propType" column="prop_type" jdbcType="VARCHAR"/> 25 </resultMap> 26 27 28 <sql id="Base_Column_List"> 29 id, mod_name, prop_name, prop_desc, del_flag, create_time, update_time 30 </sql> 31 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer"> 32 select 33 <include refid="Base_Column_List"/> 34 from t_list_schema 35 where id = #{id,jdbcType=INTEGER} 36 </select> 37 38 <select id="selectAllProdListMeta" resultMap="ListMeta"> 39 select 40 distinct mod_name,mod_desc 41 from t_list_schema where mod_name in ('loan','credit_card','other_prod') and del_flag = 0 42 </select> 43 44 <select id="selectTableHeads" resultMap="TableHead" parameterType="java.lang.String"> 45 select prop_name,prop_desc,prop_type 46 from t_list_schema where mod_name='${value}' and del_flag = 0 order by sort_index 47 </select> 48 49 <select id="selectPropNameByModName" resultType="java.lang.String" parameterType="java.lang.String"> 50 select prop_name from t_list_schema where mod_name=#{value} and del_flag=0 51 order by sort_index 52 </select> 53 54 <select id="selectTableHeadsByModName" resultMap="TableHead" > 55 select prop_name,prop_desc,prop_type from t_list_schema where mod_name=#{value} and del_flag=0 56 order by sort_index 57 </select> 58 </mapper>