SpringBoot + Vue front-end separation project micro-personnel (9)

Job management backend interface design

Create a new system package in the controller package, then create a new basic package in the system package, and then create a PositionController class in the basic package. When defining the interface of the PositionController class, it must be consistent with the url address in the menu of the database, otherwise it will There is a problem of unauthorized access

PositionController

@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    
    

    @Autowired
    PositionsService positionsService;
    @GetMapping("/")
    public List<Position> getAllPositions(){
    
    

        return positionsService.getAllPositions();
    }
 }

PositionService class

@Autowired
PositionsService positionsService;
@GetMapping("/")
public List<Position> getAllPositions(){
    
    

    return positionsService.getAllPositions();

}

PositionMapper interface

insert image description here

    List<Position> getAllPositions();

PositionMapper.xml

  <select id="getAllPositions" resultMap="BaseResultMap">
    select  * from position;
  </select>

Open Postman to test and query all the positions, the effect is as shown in the figure below:
insert image description here
Then write the addition, deletion and modification of the three interfaces of the position

PositionController


@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    
    

    @Autowired
    PositionsService positionsService;
    @GetMapping("/")
    public List<Position> getAllPositions(){
    
    

        return positionsService.getAllPositions();

    }

    @PostMapping("/")
    public RespBean addPosition(@RequestBody Position position) {
    
    

        if (positionsService.addPosition(position) == 1) {
    
    
           return RespBean.ok("添加成功!");
        }
            return RespBean.err("添加失败!");
    }


    @PutMapping("/")
    public RespBean updatePositions(@RequestBody Position position){
    
    

        if(positionsService.updatePositions(position)==1){
    
    
            return RespBean.ok("更新成功");
        }
        return RespBean.err("更新失败");
    }



    @DeleteMapping("/{id}")
    public RespBean deletePositionById(@PathVariable Integer id){
    
    
        if(positionsService.deletePositionById(id)==1){
    
    
            return RespBean.ok("删除成功");
        }
        return RespBean.err("删除失败");
    }

}

PositionService

@Service
public class PositionsService {
    
    
    @Autowired
    PositionMapper positionMapper;
    public List<Position> getAllPositions() {
    
    

        return positionMapper.getAllPositions();
    }

    public Integer addPosition(Position position) {
    
    
        position.setEnabled(true);
        position.setCreatedate(new Date());
        return positionMapper.insert(position) ;
    }

    public int updatePositions(Position position) {
    
    

        return positionMapper.updateByPrimaryKeySelective(position);
    }


    public int deletePositionById(Integer id) {
    
    

        return positionMapper.deleteByPrimaryKey(id);
    }
}

The PositionMapper interface and PositionMapper.xml are the same as the previous one, and the effect of adding the test is shown in the figure below:
insert image description here

insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_45709416/article/details/132351829