• SpringBoot封装增删改查接口


    封装了一个科室管理的增删改查接口:

    科室列表、科室详情、添加科室、修改科室、删除科室

    service层:

    package com.yutangzongcai.demo.service;
    
    import com.alibaba.fastjson.JSONObject;
    import com.yutangzongcai.demo.entity.DepartmentEntity;
    import com.yutangzongcai.demo.mapper.DepartmentMapper;
    import com.yutangzongcai.demo.tool.Res;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.transaction.annotation.Transactional;
    import org.springframework.validation.annotation.Validated;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestBody;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("admin-api/department")
    public class DepartmentService {
    
        @Autowired
        private DepartmentMapper departmentMapper;
    
        @PostMapping("list")
        public JSONObject list(@Validated(value = {DepartmentEntity.List.class}) @RequestBody DepartmentEntity departmentEntity) {
            return Res.list(departmentMapper.count(departmentEntity), departmentMapper.list(departmentEntity));
        }
    
        @PostMapping("detail")
        @Transactional(rollbackFor = Exception.class)
        public JSONObject detail(@Validated(value = {DepartmentEntity.Detail.class}) @RequestBody DepartmentEntity departmentEntity) {
            return Res.detail(departmentMapper.detail(departmentEntity.getId()));
        }
    
        @RequestMapping("create")
        @Transactional(rollbackFor = Exception.class)
        public JSONObject create(@Validated(value = {DepartmentEntity.Create.class}) @RequestBody DepartmentEntity departmentEntity) {
            return Res.row(departmentMapper.create(departmentEntity), "添加");
        }
    
        @PostMapping("update")
        @Transactional(rollbackFor = Exception.class)
        public JSONObject update(@Validated(value = {DepartmentEntity.Update.class}) @RequestBody DepartmentEntity departmentEntity) {
            return Res.row(departmentMapper.update(departmentEntity), "修改");
        }
    
        @PostMapping("delete")
        @Transactional(rollbackFor = Exception.class)
        public JSONObject delete(@Validated(value = {DepartmentEntity.Detail.class}) @RequestBody DepartmentEntity departmentEntity) {
            return Res.row(departmentMapper.delete(departmentEntity.getId()), "删除");
        }
    
    }

    dto层、entity层、mapper层、provider层可根据需求自行定义

  • 相关阅读:
    JZOJ 5728. 简单计数|| (容斥+动态规划)
    6638. 【GDOI2020.5.16模拟】Seat (队列)
    JZOJ 5750. 青青草原播种计划 (小性质+线段树)
    JZOJ 5753. 完全二叉树 (可持久化线段树维护hash值)
    JS框架-React.js
    flexbox弹性盒子布局
    压缩js和css文件的原理
    JS判断数据类型的方式
    JS数据类型
    ES6新特性
  • 原文地址:https://www.cnblogs.com/phpyangbo/p/15714389.html
Copyright © 2020-2023  润新知