1@one注解方式
@ResultMap({
@Result(id = true,property = "id",column = "id"),
/*......*/
//property 是 实体类中的属性 column为要查询用的参数 可供@One中的select使用
@Result(property = "product" ,column = "productId",
javaType = Product.class,
one = @One(select = "cn.zg.dao.ProductDao.findById"))
})
2使用mapper.xml实现
<!--resultMap-->
<resultMap id="orders" type="cn.zg.domain.Orders">
<!--字段与属性一一对应,不用重写-->
<!--一对一多表查询-->
<association property="product" javaType="cn.zg.domain.Product" column="productId"
select="cn.zg.dao.ProductDao.findById" >
</association>
</resultMap>
<select id="findAll" resultMap="orders">
select * from orders
</select>
ProductDao中的配置
<select id="findById" resultType="cn.zg.domain.Product">
select * from product where id=#{id}
</select>