案例-员工管理-删除员工
package com.itheima.controller;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.time.Period;
import java.util.List;
@Slf4j
@RestController
public class EmpController {
@Autowired
EmpService empService;
/*批量删除员工*/
@DeleteMapping("/emps/{ids}")
public Result delete(@PathVariable List<Integer> ids) {
log.info("批量删除操作:ids:{}", ids);
empService.delete(ids);
return Result.success();
}
}
package com.itheima.service;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import java.time.LocalDate;
import java.util.List;
public interface EmpService {
/*批量删除员工*/
void delete(List<Integer> ids);
}
package com.itheima.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
@Autowired
private EmpMapper empMapper;
/*批量删除员工*/
@Override
public void delete(List<Integer> ids) {
empMapper.delete(ids);
}
}
package com.itheima.mapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDate;
import java.util.List;
@Mapper
public interface EmpMapper {
/*批量删除员工*/
void delete(List<Integer> ids);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">
<!--批量删除员工-->
<delete id="delete">
delete
from emp
where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
</mapper>