whycxzp
2021-03-12 4865806a1a39b79b9b4edfa3cd84f618fa237250
更新应用接口
1个文件已修改
4个文件已添加
133 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/ApplicationController.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/Response.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/ApplicationMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/Application.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ApplicationService.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ApplicationController.java
New file
@@ -0,0 +1,40 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.pojo.Application;
import com.whyc.service.ApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * 应用管理
 */
@RestController
@RequestMapping("application")
@Api(tags = "应用管理")
public class ApplicationController {
    @Autowired
    private ApplicationService service;
    @PostMapping
    @ApiOperation(value = "创建")
    public Response create(@RequestBody Application app){
        return service.insert(app);
    }
    @GetMapping("all")
    @ApiOperation(value = "查询所有")
    public Response getAll(){
        return service.getAll();
    }
    @PutMapping
    @ApiOperation(value = "更新应用名称")
    public Response update(@RequestBody Application app){
        return service.update(app);
    }
}
src/main/java/com/whyc/dto/Response.java
@@ -34,6 +34,12 @@
        return this;
    }
    public Response<T> setMsg(Integer code,String msg) {
        this.code = code;
        this.msg = msg;
        return this;
    }
    public Response<T> set(Integer code,T data,String msg) {
        this.code = code;
        this.data = data;
src/main/java/com/whyc/mapper/ApplicationMapper.java
New file
@@ -0,0 +1,7 @@
package com.whyc.mapper;
import com.whyc.pojo.Application;
public interface ApplicationMapper extends CustomMapper<Application> {
}
src/main/java/com/whyc/pojo/Application.java
New file
@@ -0,0 +1,41 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.TableName;
import org.apache.ibatis.type.Alias;
/**
 * 应用
 */
@Alias("Application")
@TableName( schema = "`db_app_sys`",value = "`tb_application`")
public class Application {
    private Integer id;
    private String name;
    /**背景图片*/
    private String bgImg;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getBgImg() {
        return bgImg;
    }
    public void setBgImg(String bgImg) {
        this.bgImg = bgImg;
    }
}
src/main/java/com/whyc/service/ApplicationService.java
New file
@@ -0,0 +1,39 @@
package com.whyc.service;
import com.whyc.dto.Response;
import com.whyc.mapper.ApplicationMapper;
import com.whyc.pojo.Application;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class ApplicationService {
    @Resource
    private ApplicationMapper mapper;
    public Response insert(Application app) {
        int res = mapper.insert(app);
        if(res==1){
            return new Response<>().setMsg(1,"创建成功");
        }else{
            return new Response<>().setMsg(0,"创建失败");
        }
    }
    public Response getAll() {
        List<Application> applications = mapper.selectList(null);
        return new Response<>().set(1,applications);
    }
    public Response update(Application app) {
        int res = mapper.updateById(app);
        if(res==1){
            return new Response<>().setMsg(1,"更新成功");
        }else{
            return new Response<>().setMsg(0,"更新失败");
        }
    }
}