一个<resultMap>
<resultMap id="BaseResultMap" type="com.commnetsoft.admin.model.cav.LogCrash">
<id column="ID" property="id" jdbcType="INTEGER" />
<result column="DEVICEID" property="deviceid" jdbcType="VARCHAR" />
<result column="DEVICEBRAND" property="devicebrand" jdbcType="VARCHAR" />
<result column="DEVICETYPE" property="devicetype" jdbcType="VARCHAR" />
<result column="OS" property="os" jdbcType="VARCHAR" />
<result column="VERSIONID" property="versionid" jdbcType="INTEGER" />
<result column="FILEID" property="fileid" jdbcType="INTEGER" />
<result column="CREATETIME" property="createtime" jdbcType="TIMESTAMP" />
<association property="appVersion" javaType="com.commnetsoft.admin.model.cav.AppVersion" >
<id column="ID" property="id" jdbcType="INTEGER" />
<result column="TAG" property="tag" jdbcType="VARCHAR" />
<result column="CODE" property="code" jdbcType="INTEGER" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
</association>
</resultMap>
一个查询
<select id="select" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
*
from cav_log_crash c
left join cav_appversion t
on c.VERSIONID = t.id
<include refid="Base_Where_Clause" />
</select>
设置查询条件
<sql id="Base_Where_Clause">
<where>
<trim prefixOverrides="and">
<if test="id != null"> and id =#{id}</if>
<if test="deviceid != null"> and deviceid = #{deviceid}</if>
<if test="devicebrand != null"> and devicebrand = #{devicebrand}</if>
<if test="devicetype != null"> and devicetype = #{devicetype}</if>
<if test="os != null"> and os = #{os}</if>
<if test="versionid != null"> and versionid = #{versionid}</if>
<if test="fileid != null"> and fileid = #{fileid}</if>
<if test="createtime != null"> and createtime = #{createtime}</if>
<if test="name!= null"> and name = #{name}</if>
<if test="deviceidLike != null"> and deviceid like CONCAT("%",#{deviceidLike},"%")</if>
<!-- <if test="nameLike != null">and t.name =#{nameLike}</if> -->
<if test="code != null">and t.code = #{codeLike}</if>
<if test="codeLike != null">and t.code like CONCAT("%",#{codeLike},"%")</if>
</trim>
<!-- or 查询 主要用与数据权限控制 -->
<if test="dataLimit != null">
<foreach item="item" index="index" collection="dataLimit" open="and (" separator=" or " close=")">
${item}
</foreach>
</if>
</where>
<if test="sorting != null">order by c.${sorting}</if>
</sql>
最后别忘记在主表的实体类中关联一下字表的实体类 例如 private AppVersion appVersion