SpringBoot + Vue 前后端分离项目 微人事(九)

news/2024/7/24 9:24:53 标签: spring boot, vue.js, 后端

职位管理后端接口设计

在controller包里面新建system包,再在system包里面新建basic包,再在basic包里面创建PositionController类,在定义PositionController类的接口的时候,一定要与数据库的menu中的url地址到一致,不然会出现没有权限访问的问题

PositionController

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

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

        return positionsService.getAllPositions();
    }
 }

PositionService类

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

    return positionsService.getAllPositions();

}

PositionMapper接口

在这里插入图片描述

    List<Position> getAllPositions();

PositionMapper.xml

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

打开Postman测试查询所有的position,效果如下图:
在这里插入图片描述
再把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);
    }
}

PositionMapper接口和PositionMapper.xml和前面那个是一样的,测试的添加效果如下图所示:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


http://www.niftyadmin.cn/n/4952964.html

相关文章

【Redis】Redisson分布式锁原理与使用

【Redis】Redisson分布式锁原理与使用 什么是Redisson&#xff1f; Redisson - 是一个高级的分布式协调Redis客服端&#xff0c;能帮助用户在分布式环境中轻松实现一些Java的对象&#xff0c;Redisson、Jedis、Lettuce 是三个不同的操作 Redis 的客户端&#xff0c;Jedis、Le…

MATLAB打开excel读取写入操作例程

本文使用素材含代码测试用例等 MATLAB读写excel文件历程含&#xff0c;内含有测试代码资源-CSDN文库 打开文件 使用uigetfile函数过滤非xlsx文件&#xff0c;找到需要读取的文件&#xff0c;首先判断文件是否存在&#xff0c;如果文件不存在&#xff0c;程序直接返回&#x…

代码随想录算法训练营第53天|动态规划part14

8.19周六 1143.最长公共子序列 1035.不相交的线 53. 最大子序和 动态规划 详细布置 1143.最长公共子序列 题目&#xff1a;两个字符串&#xff0c;问最长的公共子序列多长&#xff08;不连续&#xff09; 题解&#xff1a; 1、dp[i][j]&#xff1a;长度为[0, i - 1]的字…

论文《LoRA: Low-Rank Adaptation of Large Language Models》阅读

论文《LoRA: Low-Rank Adaptation of Large Language Models》阅读 BackgroundIntroducitonProblem StatementMethodology Δ W \Delta W ΔW 的选择 W W W的选择 总结 今天带来的是由微软Edward Hu等人完成并发表在ICLR 2022上的论文《LoRA: Low-Rank Adaptation of Large Lan…

react之react-redux的介绍、基本使用、获取状态、分发动作、数据流、reducer的分离与合并等

react之react-redux的介绍、基本使用、获取状态、分发动作、数据流、reducer的分离与合并等 一、react-redux介绍二、React-Redux-基本使用三、获取状态useSelector四、分发动作useDispatch五、 Redux 数据流六、代码结构七、ActionType的使用八、Reducer的分离与合并九、购物挣…

spring aop 的适用场景

Spring AOP&#xff08;Aspect-Oriented Programming&#xff09;是Spring框架提供的一种面向切面编程的机制&#xff0c;它可以通过在应用程序中定义横切关注点&#xff08;Cross-cutting Concerns&#xff09;&#xff0c;将这些关注点模块化&#xff0c;并将它们与核心业务逻…

Oracle/PL/SQL奇技淫巧之Lable标签与循环控制

在一些存储过程场景中&#xff0c;可能存在需要在满足某些条件时跳出循环的场景&#xff0c; 但是在PL/SQL中&#xff0c;不能使用break语句直接跳出循环, 但是可以通过lable标签的方式跳出循环&#xff0c;例&#xff1a; <<outer_loop>> FOR i IN 1..5 LOOPDBMS…

【C++】做一个飞机空战小游戏(十)——子弹击落炮弹、炮弹与飞机相撞

[导读]本系列博文内容链接如下&#xff1a; 【C】做一个飞机空战小游戏(一)——使用getch()函数获得键盘码值 【C】做一个飞机空战小游戏(二)——利用getch()函数实现键盘控制单个字符移动【C】做一个飞机空战小游戏(三)——getch()函数控制任意造型飞机图标移动 【C】做一个飞…