1、配置resultMap:
1
2
3
4
5
6
7
8
9
10 |
<resultMap id= "BaseResultMap"
type= "cn.iautos.manager.entity.mybatis.MallSafeguardService"
> <id column= "id"
property= "id"
jdbcType= "INTEGER"
/> <result column= "safeguard_id"
property= "safeguardId"
jdbcType= "INTEGER"
/> <result column= "service_id"
property= "serviceId"
jdbcType= "INTEGER"
/> <result column= "create_time"
property= "createTime"
jdbcType= "TIMESTAMP"
/> <result column= "isdel"
property= "isdel"
jdbcType= "TINYINT"
/> 这个是主要的配置。如果两个表中的字段名称相同则会出现数据异常。解决方法,可以使用别名的形式,对相同的字段赋值 <association property= "service"
column= "id"
javaType= "cn.iautos.manager.entity.mybatis.MallService"
resultMap= "cn.iautos.manager.repository.MallServiceDAO.BaseResultMap" /> </resultMap> |
2、查询语句:
1
2
3
4
5 |
<select id= "selectSafeServiceBySafeId"
resultMap= "BaseResultMap"
parameterType= "cn.iautos.manager.entity.mybatis.MallSafeguardService"
> SELECT mss.*,ms.* from mall_safeguard_service mss LEFT JOIN mall_service ms on mss.service_id = ms.id where mss.safeguard_id=#{safeguardId} </select> |
原文:http://www.cnblogs.com/xuzhenmin/p/3601024.html