import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DeptMapper {
DepartMent findById(Integer deptno);
List findAll();
}
import java.util.List;
public interface DeptService {
DepartMent findById(Integer deptno);
List findAll();
}
7 创建serviceImpl
mport org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
@Autowired
private EmpMapper empMapper;
@Override
public List findAll() {
return empMapper.findAll();
}
@Override
public void add(Emp emp) {
empMapper.add(emp);
}
@Override
public void deleteAll(Integer[] empnos) {
empMapper.deleteAll(empnos);
}
@Override
public void deleteById(Integer empno) {
empMapper.deleteById(empno);
}
@Override
public void updateById(Emp emp) {
empMapper.updateById(emp);
}
@Override
public Emp_Department findById(Integer empno) {
Emp_Department emp_department = empMapper.findById(empno);
return emp_department;
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
@Autowired
private DeptMapper deptMapper;
@Override
public DepartMent findById(Integer deptno) {
DepartMent departMent = deptMapper.findById(deptno);
return departMent;
}
@Override
public List findAll() {
List list = deptMapper.findAll();
return list;
}
}
8 创建controller
EmpController
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("emp")
public class EmpController {
@Autowired
private EmpService empService;
@RequestMapping("findAll")
public List findAll(){
return empService.findAll();
}
@RequestMapping("findByPage")
public PageInfo findByPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "3") Integer pageSize){
PageHelper.startPage(pageNum,pageSize);
List list = empService.findAll();
PageInfo listPageInfo = new PageInfo<>(list);
return listPageInfo;
}
@RequestMapping("findById")
public Emp_Department findById(@RequestParam(value = "empno") Integer empno){
Emp_Department emp_department = empService.findById(empno);
return emp_department;
}
@RequestMapping("addEmp")
public String add(@RequestBody Emp emp){
empService.add(emp);
return "Success";
}
@RequestMapping("deleteById")
public String deleteById(Integer empno){
empService.deleteById(empno);
return "Success";
}
@RequestMapping("deleteAll")
public String deleteAll(Integer[] empnos){
empService.deleteAll(empnos);
return "Success";
}
@RequestMapping("update")
public String updateById(@RequestBody Emp emp){
empService.updateById(emp);
return "Success";
}
}
DeptController
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("dept")
public class DeptController {
@Autowired
private DeptService deptService;
@RequestMapping("findAll")
public List findAll(){
List list = deptService.findAll();
return list;
}
@RequestMapping("findById")
public DepartMent findById(@RequestParam("deptno") Integer deptno){
DepartMent departMent = deptService.findById(deptno);
return departMent;
}
}
评论列表(0条)