SpringBoot case - department management - delete

Table of contents

View the page prototype and clarify the requirements

page prototype

need 

Read the interface documentation

Idea analysis

Functional interface development

Control layer (Controllre class)

Business layer (Service class)

Persistence layer (Mapper class)

interface test

Front-end and back-end joint debugging 


View the page prototype and clarify the requirements

page prototype

need 

Delete department information according to department ID

Read the interface documentation

[Tencent Documentation] The link to the documents required for the SpringBoot case is as follows:
https://docs.qq.com/doc/DUkRiTWVaUmFVck9N

Idea analysis

After reading the interface document, you can know that the operation of deleting department information according to id, where id is a path parameter,

 For the reception of path parameters, refer to the previous article Request Response - Reception of Path Parameters_Entropy 240 Blog-CSDN Blog

 That is, use the annotation @PathVariable

Use the request annotation as @DeleteMapping

Functional interface development

Control layer (Controllre class)

The specific key codes are as follows:

    /**
     * 根据id部门id删除部门信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/depts/{id}")// id为一个路径参数
    public Result deleteByID(@PathVariable Integer id) {
        log.info("根据id删除部门信息:{}", id);
        deptService.deleteByID(id);
        return Result.success();
    }

Business layer (Service class)

The specific key codes are as follows:

business interface

    /**
     * 根据id删除部门信息
     * @param id
     */
    void deleteByID(Integer id);

Realize the business interface

    @Override
    public void deleteByID(Integer id) {
        deptMapper.deleteByID(id);
    }

Persistence layer (Mapper class)

The specific key codes are as follows:

    /**
     * 根据id删除部门信息
     * @param id
     */
    @Delete("delete from dept where id =#{id}")
    void deleteByID(Integer id);

interface test

Still use postman for interface testing. After starting the SpringBoot project, send a delete request in postman .

Delete the department information with id=1, id is the path parameter 

The specific operation results are as follows

 

 

perfect run successfully

Front-end and back-end joint debugging 

Still after running the provided nginx file, visit

http://localhost:90/http://localhost:90/

The results of the visit are as follows:

 Among them, I clicked the delete button and successfully deleted a department.

Guess you like

Origin blog.csdn.net/weixin_64939936/article/details/132239666