service
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 a.* from t_admin a ")
({
(column="id",property="id"),
(column="address",property="address"),
(column="create_time",property="createTime"),
(column="name",property="name"),
(column="phone",property="phone"),
(column="remark",property="remark"),
(column="telephone",property="telephone"),
(column="update_time",property="updateTime"),
(column="user_face",property="userFace"),
(column="username",property="username"),
(column="admin_id",property="aradminId"),
(column="rid",property="arrid"),
(column="name",property="name"),
(column="name_zh",property="nameZh"),
//这里的id是不能写错,对应的是property,我以为是写数据库的字段名,原来是写别名字段 如果修改使用了别名字段,需要用到别名
(column="id",property="roles",many= (select="getAllRoles",**fetchType= FetchType.EAGER**)),
})
List<Admin> getAllAdmins( (Constants.WRAPPER) Wrapper wrapper);
("select * from t_admin_role ar left join t_role r on ar.rid = r.id where ar.admin_id = #{id}")
List<Role> getAllRoles( ("id") Long id);
FetchType.LAZY =除非您通过getter方法调用它,否则不会加载关系。
FetchType.EAGER =这将加载所有关系。
这两种类型的利弊。
Lazy initialization 通过避免不必要的计算来提高性能并减少内存需求。
Eager initialization 需要更多的内存消耗,并且处理速度很慢。
数据展示