@Test public void testUpdate() throws Exception { String id = "{}"; Role role = new Role(); String content = objectMapper.writeValueAsString(role); String result = mockMvc.perform(put("/sys/role/" + id) .header(HttpHeaders.AUTHORIZATION, String.join(" ", accessToken.getTokenType(), accessToken.getValue())) .content(content) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) .andExpect(jsonPath("$.data.id").isNotEmpty()) .andReturn().getResponse().getContentAsString(); log.info("{}",result); }
@Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新角色") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") public Result<Role> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, @RequestBody Role model) { return super.update(id, model); }
RoleController extends LeftTreeRightTableControllerImpl<Department, Role> { @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新角色") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") public Result<Role> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, @RequestBody Role model) { return super.update(id, model); } }
RoleController extends LeftTreeRightTableControllerImpl<Department, Role> { @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新角色") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") public Result<Role> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, @RequestBody Role model) { return super.update(id, model); }  }
RoleController extends LeftTreeRightTableControllerImpl<Department, Role> { @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新角色") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") public Result<Role> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, @RequestBody Role model) { return super.update(id, model); }  @Autowired void setRoleService(RoleService roleService); @Override @GetMapping("/dict") @ApiOperation("获取角色的数据字典") @PreAuthorize("hasAnyAuthority('" + LIST_PERM + "')") Result<TableInfo> getTableInfo(); @Override @PostMapping @ApiOperation("保存角色") @PreAuthorize("hasAnyAuthority('" + ADD_PERM + "')") Result<Role> save(@Valid @RequestBody Role model); @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除角色") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新角色") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") Result<Role> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, /*@Valid*/@RequestBody Role model) {; @Override @GetMapping @ApiOperation("查询角色列表") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<List<Role>> findAll(Role model); @Override @GetMapping("/{page:[0-9]+}/{size:[0-9]+}") @ApiOperation("分页查询角色列表") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<QueryResult<Role>> query(@ApiParam(value = "页码", required = true) @PathVariable("page") int page, @ApiParam(value = "每页数据条数", required = true) @PathVariable("size") int size, Role model) {; @Override @GetMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("根据ID查询角色") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<Role> findById(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @Override @PostMapping("/batch") @ApiOperation("批量操作数据") @PreAuthorize("hasAuthority('" + ADD_PERM +"') and hasAuthority('" + EDIT_PERM +"') and hasAuthority('" + DELETE_PERM +"')") Result batch(@RequestBody BatchModel<Role> batch); @PostMapping(value = "/setPermissions/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("分配权限") @PreAuthorize("hasAnyRole('ADMIN')") Result<Role> setPermissions(@ApiParam("角色id") @PathVariable String id, @ApiParam("权限id数组") @RequestBody String[] permissions) {; @GetMapping(value = "/noPermissions/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("得到角色未拥有权限") @PreAuthorize("hasAnyRole('ADMIN')") Result<List<Menu>> noPermissions(@ApiParam("角色id") @PathVariable String id) {; @Override @PostMapping("/import") @ApiOperation("从文件导入角色") @PreAuthorize("hasAnyAuthority('" + IMPORT_PERM + "')") Result<List<Role>> importData(MultipartFile file); @Override @GetMapping("/export") @ApiOperation("导出角色到文件") @PreAuthorize("permitAll()") void exportData(@RequestBody(required = false) List<String> ids, HttpServletResponse response); @Override @GetMapping("/leftTree") @ApiOperation("获取左树数据") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<List<Department>> leftTreeData(); }
RoleController extends LeftTreeRightTableControllerImpl<Department, Role> { @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新角色") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") public Result<Role> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, @RequestBody Role model) { return super.update(id, model); }  @Autowired void setRoleService(RoleService roleService); @Override @GetMapping("/dict") @ApiOperation("获取角色的数据字典") @PreAuthorize("hasAnyAuthority('" + LIST_PERM + "')") Result<TableInfo> getTableInfo(); @Override @PostMapping @ApiOperation("保存角色") @PreAuthorize("hasAnyAuthority('" + ADD_PERM + "')") Result<Role> save(@Valid @RequestBody Role model); @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除角色") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新角色") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") Result<Role> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, /*@Valid*/@RequestBody Role model) {; @Override @GetMapping @ApiOperation("查询角色列表") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<List<Role>> findAll(Role model); @Override @GetMapping("/{page:[0-9]+}/{size:[0-9]+}") @ApiOperation("分页查询角色列表") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<QueryResult<Role>> query(@ApiParam(value = "页码", required = true) @PathVariable("page") int page, @ApiParam(value = "每页数据条数", required = true) @PathVariable("size") int size, Role model) {; @Override @GetMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("根据ID查询角色") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<Role> findById(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @Override @PostMapping("/batch") @ApiOperation("批量操作数据") @PreAuthorize("hasAuthority('" + ADD_PERM +"') and hasAuthority('" + EDIT_PERM +"') and hasAuthority('" + DELETE_PERM +"')") Result batch(@RequestBody BatchModel<Role> batch); @PostMapping(value = "/setPermissions/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("分配权限") @PreAuthorize("hasAnyRole('ADMIN')") Result<Role> setPermissions(@ApiParam("角色id") @PathVariable String id, @ApiParam("权限id数组") @RequestBody String[] permissions) {; @GetMapping(value = "/noPermissions/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("得到角色未拥有权限") @PreAuthorize("hasAnyRole('ADMIN')") Result<List<Menu>> noPermissions(@ApiParam("角色id") @PathVariable String id) {; @Override @PostMapping("/import") @ApiOperation("从文件导入角色") @PreAuthorize("hasAnyAuthority('" + IMPORT_PERM + "')") Result<List<Role>> importData(MultipartFile file); @Override @GetMapping("/export") @ApiOperation("导出角色到文件") @PreAuthorize("permitAll()") void exportData(@RequestBody(required = false) List<String> ids, HttpServletResponse response); @Override @GetMapping("/leftTree") @ApiOperation("获取左树数据") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<List<Department>> leftTreeData();  }