• 前置条件

    在开发之前,请确保

    介绍

    demo需涉及api层的 dto 以及 controller

    编写DTO

    编写Controller

    Controller 类相关标签

    UserController.java代码

    package io.choerodon.todo.api.controller.v1;
    
    // 省略 import
    
    @RestController
    @RequestMapping(value = "/v1/users")
    public class UserController {
        private UserService userService;
    
        public UserController(UserService userService) {
            this.userService = userService;
        }
    
        @PostMapping()
        @Permission(level = ResourceLevel.SITE)
        @ApiOperation(value = "创建todo 用户")
        private ResponseEntity<UserDTO> create(@RequestBody UserDTO userDTO) {
            return new ResponseEntity<>(userService.create(userDTO), HttpStatus.OK);
        }
    }
    
    

    TaskController.java代码

    package io.choerodon.todo.api.controller.v1;
    
    // 省略 import
    
    @RestController
    @RequestMapping(value = "/v1/tasks")
    public class TaskController {
        private TaskService taskService;
    
        public TaskController(TaskService taskService) {
            this.taskService = taskService;
        }
    
        @PostMapping()
        @Permission(level = ResourceLevel.SITE)
        @ApiOperation(value = "创建task")
        public ResponseEntity<TaskDTO> create(@RequestBody TaskDTO taskDTO) {
            return new ResponseEntity<>(taskService.create(taskDTO), HttpStatus.OK);
        }
    
        @DeleteMapping("/{id}")
        @Permission(level = ResourceLevel.SITE)
        @ApiOperation(value = "根据id删除task")
        public void delete(@PathVariable Long id) {
            taskService.deleteById(id);
        }
    
        @DeleteMapping("/taskNumber/{taskNumber}")
        @Permission(level = ResourceLevel.SITE)
        @ApiOperation(value = "根据TaskNumber删除task")
        public void deleteByTaskNumber(@PathVariable String taskNumber) {
            taskService.deleteByTaskNumber(taskNumber);
        }
    
        @PutMapping("/{id}")
        @Permission(level = ResourceLevel.SITE)
        @ApiOperation(value = "更新task")
        public ResponseEntity<TaskDTO> update(@PathVariable Long id, @RequestBody TaskDTO taskDTO) {
            taskDTO.setId(id);
            return new ResponseEntity<>(taskService.update(taskDTO), HttpStatus.OK);
        }
    
        @GetMapping("/{id}")
        @Permission(level = ResourceLevel.SITE)
        @ApiOperation(value = "查询task")
        public ResponseEntity<TaskDTO> query(@PathVariable Long id) {
            return new ResponseEntity<>(taskService.queryById(id), HttpStatus.OK);
        }
    
    }