接口层
public interface IOrdersDao {
//查询所有订单信息
@Select("select o.id,o.ordernum,p.productname,p.productprice,o.ordertime,o.orderstatus " +
"from orders o ,product p where o.productid=p.id")
@Results({
@Result(column = "productname",property = "product.productName"),
@Result(column = "productprice",property = "product.productPrice")
})
List<Orders> findAll();
//根据订单ID查询订单信息
@Select("select * from orders o,member m,product p where o.memberid=m.id and o.productid=p.id and o.id=#{id}")
@Results({
@Result(column = "name",property = "member.name"),
@Result(column = "nickname",property = "member.nickname"),
@Result(column = "phoneNum",property = "member.phoneNum"),
@Result(column = "email",property = "member.email"),
@Result(column = "productname" ,property ="product.productName"),
@Result(column = "cityname" ,property ="product.cityName"),
@Result(column = "productprice" ,property ="product.productPrice"),
@Result(column = "departuretime" ,property ="product.departureTime"),
@Result(column = "id",property = "travellers", many=@Many(select = "com.qyf.dao.ITravellerDao.findByTraveller"))
})
Orders findById(String id);
}
通过many实现封装某个对象的集合
public interface ITravellerDao {
@Select("select * from traveller where id in " +
"(select travellerid from order_traveller where orderid=#{orderId})")
List<Traveller> findByTraveller(String orderId);
}
多个同类型参数,使用@Param(‘a’) @Param(‘b’)实现参数传递的区分
public interface IRoleDao {
//根据用户ID查询处所有对应的角色和角色对应的权限
@Select("select * from role where id in(select roleid from users_role where userid=#{userid})")
@Results({
@Result(column = "id",property = "permissions",many = @Many(select = "com.qyf.dao.IPermissionDao.findByRoleId"))
})
List<Role> findByUserId(String userId);
@Select("select * from role")
List<Role> findAll();
@Insert("insert into role(id,rolename,roledesc)values(default,#{roleName},#{roleDesc})")
void save(Role role);
@Select("select * from role where id=#{roleId}")
Role findByRoleId(String roleId);
@Select("select * from permission where id not in(select permissionid from role_permission where roleid=#{roleId})")
List<Permission> findPermissionsByRoleId(String roleId);
@Insert("insert into role_permission(permissionid,roleid)values(#{permissionid},#{roleId})")
void savePermissionsByRoleId(@Param("roleId") String roleId,@Param("permissionid") String permissionId);
}