View the page prototype and clarify the requirements
page prototype
There is batch delete and delete single data
need
View interface documentation
Links to the interface documentation are as follows:
[Tencent Documents] Documents required for SpringBoot cases
https://docs.qq.com/doc/DUkRiTWVaUmFVck9N
Idea analysis
To delete a single data, pass the id of the employee information to be deleted to the backend, and the backend deletes the employee data through the id. According to the interface document, the frontend passes the id to the backend in the form of path parameters, and how the backend receives the path For parameters, refer to the article for details: Request Response - Reception of Path Parameters_Entropy 240's Blog-CSDN Blog
Due to the operation of batch deletion, the received path parameters are set or array data types , so the writing of the SQL statement needs to traverse the received path parameters. The writing of the dynamic SQL statement needs to use the <foreach> tag. How to use it , refer to the article: MyBatis-Dynamic SQL-foreach_Entropy 240 Blog-CSDN Blog
Interface function realization
Control layer (Controller class)
specific key code
@DeleteMapping("/emps/{ids}") // {ids}为一个路径参数
/**
* 根据id删除员工信息
* @return
*/
// TODO 使用@PathVariable表示使用ids来接收前端的路径参数
public Result DeleteByID(@PathVariable List<Integer> ids) {
log.info("根据id删除员工信息,参数ids:{}", ids);
empService.DeleteByID(ids);
return Result.success();
}
Business layer (Service class)
business class
void DeleteByID(List<Integer> ids);
business realization class
@Override
public void DeleteByID(List<Integer> ids) {
empMapper.DeleteByID(ids);
}
Persistence layer (Mapper class)
The specific key code is as follows
void DeleteByID(List<Integer> ids);
Mapper.xml mapping file
The specific key code is as follows
<!-- todo 删除操作-->
<delete id="DeleteByID">
delete
from emp
where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
interface test
Start the SpringBoot project and use postman to test the interface function. The request address and request parameters are as follows:
The result of the operation is as follows:
Front-end and back-end joint debugging
Start the ngnix project provided by the course, and the running results are as follows:
Perform individual employee data deletion
delete the first data
The result of the operation is as follows:
Delete employee information in batches
Delete the first three data information
The result of the operation is as follows