mapper.xml写法举例

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="maserati.dao.meta.list.ListSchemaMapper">
<resultMap id="BaseResultMap" type="maserati.dao.meta.list.entity.ListSchemaEntity">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="mod_name" property="modName" jdbcType="VARCHAR"/>
<result column="prop_name" property="propName" jdbcType="VARCHAR"/>
<result column="prop_desc" property="propDesc" jdbcType="VARCHAR"/>
<result column="del_flag" property="delFlag" jdbcType="BIT"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
</resultMap> <resultMap id="ListMeta" type="maserati.dao.meta.list.entity.ListMeta">
<result column="mod_name" property="modName" jdbcType="VARCHAR"/>
<result column="mod_desc" property="modTitle" jdbcType="VARCHAR"/>
<collection property="tHeads" ofType="maserati.dao.meta.list.entity.PropMeta"
select="selectTableHeads" column="mod_name" javaType="ArrayList"/>
</resultMap>
<resultMap id="TableHead" type="maserati.dao.meta.list.entity.PropMeta">
<result property="propName" column="prop_name" jdbcType="VARCHAR"/>
<result property="propDesc" column="prop_desc" jdbcType="VARCHAR"/>
<result property="propType" column="prop_type" jdbcType="VARCHAR"/>
</resultMap> <sql id="Base_Column_List">
id, mod_name, prop_name, prop_desc, del_flag, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from t_list_schema
where id = #{id,jdbcType=INTEGER}
</select> <select id="selectAllProdListMeta" resultMap="ListMeta">
select
distinct mod_name,mod_desc
from t_list_schema where mod_name in ('loan','credit_card','other_prod') and del_flag = 0
</select> <select id="selectTableHeads" resultMap="TableHead" parameterType="java.lang.String">
select prop_name,prop_desc,prop_type
from t_list_schema where mod_name='${value}' and del_flag = 0 order by sort_index
</select> <select id="selectPropNameByModName" resultType="java.lang.String" parameterType="java.lang.String">
select prop_name from t_list_schema where mod_name=#{value} and del_flag=0
order by sort_index
</select> <select id="selectTableHeadsByModName" resultMap="TableHead" >
select prop_name,prop_desc,prop_type from t_list_schema where mod_name=#{value} and del_flag=0
order by sort_index
</select>
</mapper>
05-11 15:08