service
@Override
public List<Admin> getAllAdmins(String keywords) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("a.id",AdminUtils.getCurrentAdmin().getId());
// queryWrapper.like("a.name",keywords);
// queryWrapper.orderByAsc("a.id");
return adminMapper.getAllAdmins(queryWrapper);
}
mapper
/**,ar.admin_id aradminId,ar.rid arrid
* 獲取所有操作員
* @return
*/
@Select("select a.* from t_admin a ")
@Results({
@Result(column="id",property="id"),
@Result(column="address",property="address"),
@Result(column="create_time",property="createTime"),
@Result(column="name",property="name"),
@Result(column="phone",property="phone"),
@Result(column="remark",property="remark"),
@Result(column="telephone",property="telephone"),
@Result(column="update_time",property="updateTime"),
@Result(column="user_face",property="userFace"),
@Result(column="username",property="username"),
@Result(column="admin_id",property="aradminId"),
@Result(column="rid",property="arrid"),
@Result(column="name",property="name"),
@Result(column="name_zh",property="nameZh"),
//這里的id是不能寫錯,對應的是property,我以為是寫數據庫的字段名,原來是寫別名字段 如果修改使用了別名字段,需要用到別名
@Result(column="id",property="roles",many=@Many(select="getAllRoles",**fetchType= FetchType.EAGER**)),
})
List<Admin> getAllAdmins(@Param(Constants.WRAPPER) Wrapper wrapper);
@Select("select * from t_admin_role ar left join t_role r on ar.rid = r.id where ar.admin_id = #{id}")
List<Role> getAllRoles(@Param("id") Long id);
FetchType.LAZY =除非您通過getter方法調用它,否則不會加載關系。
FetchType.EAGER =這將加載所有關系。
這兩種類型的利弊。
Lazy initialization 通過避免不必要的計算來提高性能並減少內存需求。
Eager initialization 需要更多的內存消耗,並且處理速度很慢。