src/main/java/com/whyc/app/controller/ServerController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/app/service/ServerService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/mapper/ServerMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/pojo/Server.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/ServerMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/whyc/app/controller/ServerController.java
New file @@ -0,0 +1,36 @@ package com.whyc.app.controller; import com.whyc.app.service.ServerService; import com.whyc.dto.Response; import com.whyc.pojo.Server; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.*; @RestController("APP-ServerController") @RequestMapping("phone/server") @Api(tags = "服务器IP") public class ServerController { @Qualifier("SER-ServerService") @Autowired ServerService serverService ; @GetMapping("ip") @ApiOperation(value = "获取服务器IP") public Response getServerIP(){ return serverService.getServerIP(); } @PutMapping("ip") @ApiOperation(value = "更新服务器IP") public boolean updateServerIP(@RequestParam String ip){ return serverService.updateServerIP(ip); } } src/main/java/com/whyc/app/service/ServerService.java
New file @@ -0,0 +1,38 @@ package com.whyc.app.service; import com.whyc.dto.Response; import com.whyc.mapper.ServerMapper; import com.whyc.pojo.Server; import org.springframework.stereotype.Service; import javax.annotation.Resource; @Service("SER-ServerService") public class ServerService { @Resource private ServerMapper mapper; public boolean updateServerIP(String ip) { Server entity = new Server(1, ip); Integer integer = mapper.selectCount(null); if (integer > 0) { return mapper.updateById(entity) > 0; } else { return mapper.insert(new Server(1, ip)) > 0; } } public Response<Server> getServerIP() { Server server = mapper.selectById(1); Response<Server> response = new Response<>(); response.set(1); if (null == server) { response.setData(new Server(1, "127.0.0.1")); } else { response.setData(server); } return response; } } src/main/java/com/whyc/mapper/ServerMapper.java
New file @@ -0,0 +1,6 @@ package com.whyc.mapper; import com.whyc.pojo.Server; public interface ServerMapper extends CustomMapper<Server> { } src/main/java/com/whyc/pojo/Server.java
New file @@ -0,0 +1,44 @@ package com.whyc.pojo; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.apache.ibatis.type.Alias; import java.util.Date; /** * 设备的通讯状态 */ @Alias("Server") @TableName(schema = "`db_3.5mw_web`",value = "tb_server") @ApiModel public class Server { private Integer id; private String ip; public Server() { } public Server(Integer id, String ip) { this.id = id; this.ip = ip; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } } src/main/resources/mapper/ServerMapper.xml
New file @@ -0,0 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.whyc.mapper.ServerMapper" > <!-- app --> </mapper>