背景:很多外国的设计是不合适国内的使用习惯,就比方说人员选择器和组选择器,他们都是id和第一个名字,中国哪里能看的懂呀,所以我们自定义修改一下。
1、自定义组选择器
@RestController @RequestMapping("/app") public class EditorGroupsResource { @Autowired protected IdmIdentityService idmIdentityService; @RequestMapping(value = "/rest/editor-groups", method = RequestMethod.GET) public ResultListDataRepresentation getGroups(@RequestParam(required = false, value = "filter") String filter) { if (StringUtils.isNotBlank(filter)) { filter = filter.trim(); String sql = "select * from act_id_group where NAME_ like #{name}"; filter = "%" + filter + "%"; List<Group> groups = idmIdentityService.createNativeGroupQuery().sql(sql).parameter("name", filter).listPage(0, 10); List<GroupRepresentation> result = new ArrayList<>(); for (Group group : groups) { result.add(new GroupRepresentation(group)); } return new ResultListDataRepresentation(result); } return null; } }
2、自定义人员选择器
@RestController @RequestMapping("/app") public class EditorUsersResource { @Autowired protected IdmIdentityService idmIdentityService; @Autowired protected ManagementService managementService; @RequestMapping(value = "/rest/editor-users", method = RequestMethod.GET) public ResultListDataRepresentation getUsers(@RequestParam(value = "filter", required = false) String filter) { if (StringUtils.isNotBlank(filter)) { filter = filter.trim(); String sql = "select * from act_id_user where ID_ like #{id} or LAST_ like #{name}"; filter = "%"+filter+"%"; List<User> matchingUsers = idmIdentityService.createNativeUserQuery().sql(sql).parameter("id",filter).parameter("name",filter).listPage(0, 10);List<UserRepresentation> userRepresentations = new ArrayList<>(matchingUsers.size()); for (User user : matchingUsers) { userRepresentations.add(new UserRepresentation(user)); } return new ResultListDataRepresentation(userRepresentations); } return null; } }
3、效果: