• 前置条件

    在开发之前,请确保

    介绍

    demo需涉及api层的 dto 以及 controller

    编写api层的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(type = ResourceType.SITE, permissionLogin = true)
        @ApiOperation(value = "创建todo用户")
        private ResponseEntity<UserDTO> create(@RequestBody UserDTO userDTO) {
            return new ResponseEntity<>(userService.createOne(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(type = ResourceType.SITE)
        @ApiOperation(value = "创建Task")
        public ResponseEntity<TaskDTO> create(@RequestBody TaskDTO taskDTO) {
            return new ResponseEntity<>(taskService.createOne(taskDTO), HttpStatus.OK);
        }
    
    
        @GetMapping("/{id}")
        @Permission(type = ResourceType.SITE)
        @ApiOperation(value = "根据Id查询task")
        public ResponseEntity<TaskDTO> queryById(@PathVariable Long id) {
            return new ResponseEntity<>(taskService.queryById(id), HttpStatus.OK);
        }
    
        @GetMapping("/taskNumber/{taskNumber}")
        @Permission(type = ResourceType.SITE)
        @ApiOperation(value = "根据TaskNumber查询task")
        public ResponseEntity<TaskDTO> queryByTaskNumber(@PathVariable String taskNumber) {
            return new ResponseEntity<>(taskService.queryByTaskNumber(taskNumber), HttpStatus.OK);
        }
    
        @DeleteMapping("/{id}")
        @Permission(type = ResourceType.SITE)
        @ApiOperation(value = "根据Id删除ask")
        public void delete(@PathVariable Long id) {
            taskService.deleteById(id);
        }
    
    
        @PutMapping("/{id}")
        @Permission(type = ResourceType.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);
        }
    }