Dao接口中的方法中,使用@Results
public interface IOrdersDao {
//查询所有订单
@Select("select * from orders")
@Results({
@Result(id=true,column = "id",property = "id"),
@Result(column = "orderNum",property = "orderNum"),
@Result(column = "orderTime",property = "orderTime"),
@Result(column = "orderStatus",property = "orderStatus"),
@Result(column = "peopleCount",property = "peopleCount"),
@Result(column = "payType",property = "payType"),
@Result(column = "orderDesc",property = "orderDesc"),
@Result(column = "productId",property = "product",one = @One(select = "dao.IProductDao.findById"))
})
public List<Orders> findAll() throws Exception;
}
在上述最后一个@Result中,one对应的包中查询方法findById,将查询的结果返回,此时会传入本次查询的id到findById.
@Component
public interface IProductDao {
//根据id查询用户
@Select("select * from product where id=#{id}")
public Product findById(String id) throws Exception;
}