多对一
1.1语法
多对一: 需要使用one属性和@One注解
@Result( property = "多表JavaBean属性名", column = "多表字段名", one = @One(select ="1表Mapper的方法签名") )
1.2 例子
UserMapper:
/**
* 通过id查询详情
* @param uid
* @return
*/
@Select("select * from user where uid = #{uid}")
@ResultMap("userResult")
public User selectById(@Param("uid") String uid);
OrderMapper:
/**
*
* @param id
* @return
*/
@Select("select * from orders where oid = #{oid}")
@Results({
@Result(property="oid" , column="oid"),
@Result(property="ordertime" , column="ordertime"),
@Result(property="total" , column="total"),
@Result(property="state" , column="state"),
@Result(property="address" , column="address"),
@Result(property="name" , column="name"),
@Result(property="telephone" , column="telephone"),
@Result(property="uid" , column="uid"),
@Result(property="user" ,
one=@One(select="com.czxy.ssm.mapper.UserMapper.selectById") , column="uid"),
})
public Order selectById(@Param("oid") String id);