Commit bef33545 authored by zengtianlai3's avatar zengtianlai3

修改格式

parent 673dae1d
......@@ -34,8 +34,8 @@ public class DeviceController {
*/
@PostMapping("add")
public BaseResult addDevice(@RequestBody JSONObject jsonObject) {
int userId = jsonObject.getInteger("user_id");
int typeId = jsonObject.getInteger("type_id");
int userId = jsonObject.getInteger("userId");
int typeId = jsonObject.getInteger("typeId");
int count = jsonObject.getInteger("count");
boolean res = deviceService.addDevice(userId, typeId,count);
if (res) {
......@@ -54,10 +54,10 @@ public class DeviceController {
* @return
*/
@GetMapping("list")
public PageResult getDeviceList(@RequestParam("page_no") int pageNo,
@RequestParam("page_size") int pageSize,
@RequestParam(value = "type_name",required = false) String typeName,
@RequestParam(value = "user_id",required = false) Integer userId) {
public PageResult getDeviceList(@RequestParam("pageNo") int pageNo,
@RequestParam("pageSize") int pageSize,
@RequestParam(value = "typeName",required = false) String typeName,
@RequestParam(value = "userId",required = false) Integer userId) {
PageInfoModel<DeviceTypeVo> records = deviceService.getDeviceList(pageNo,pageSize,typeName,userId);
int total = records.getTotal();
int pages = total/pageSize;//pages为总页数
......
......@@ -2,7 +2,7 @@ package iot.sixiang.license.controller;
import iot.sixiang.license.entity.DeviceType;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.service.DeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -32,9 +32,9 @@ public class DeviceTypeController {
* @return
*/
@GetMapping("type")
public RespResult getDeviceTypeList() {
public ResResult getDeviceTypeList() {
List<DeviceType> records = deviceTypeService.getDeviceTypeList();
return RespResult.success().record(records);
return ResResult.success().record(records);
}
}
......@@ -4,7 +4,7 @@ package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.entity.License;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.service.LicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -33,9 +33,9 @@ public class LicenseController {
*/
@PostMapping("add")
public BaseResult addLicense(@RequestBody JSONObject jsonObject){
String appId = jsonObject.getString("app_id");
String appKey = jsonObject.getString("app_key");
String userId = jsonObject.getString("user_id");
String appId = jsonObject.getString("appId");
String appKey = jsonObject.getString("appKey");
String userId = jsonObject.getString("userId");
boolean res = licenseService.addLicense(appId,appKey,userId);
if (res) {
return BaseResult.success();
......@@ -50,7 +50,7 @@ public class LicenseController {
* @return
*/
@PostMapping("delete")
public BaseResult deleteLicense(@RequestParam("app_id") String appId) {
public BaseResult deleteLicense(@RequestParam("appId") String appId) {
boolean res = licenseService.deleteLicense(appId);
if (res) {
return BaseResult.success();
......@@ -66,9 +66,9 @@ public class LicenseController {
*/
@PostMapping("update")
public BaseResult updateLicense(@RequestBody JSONObject jsonObject){
String appId = jsonObject.getString("app_id");
String appKey = jsonObject.getString("app_key");
String userId = jsonObject.getString("user_id");
String appId = jsonObject.getString("appId");
String appKey = jsonObject.getString("appKey");
String userId = jsonObject.getString("userId");
boolean res = licenseService.updateLicense(appId,appKey,userId);
if (res) {
return BaseResult.success();
......@@ -84,9 +84,9 @@ public class LicenseController {
* @return
*/
@GetMapping("list")
public RespResult getLicenseList(@RequestParam("page_no") int pageNo, @RequestParam("page_size") int pageSize) {
public ResResult getLicenseList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
List<License> records = licenseService.getLicenseList(pageNo,pageSize);
return RespResult.success().record(records);
return ResResult.success().record(records);
}
......
......@@ -33,7 +33,7 @@ public class LoginController {
*/
@GetMapping("login")
public ResResult login(@RequestParam("user_name") String userName, @RequestParam("password") String password) {
public ResResult login(@RequestParam("userName") String userName, @RequestParam("password") String password) {
// @RequestBody JSONObject jsonObject
LoginUser user = new LoginUser();
user.setUser_name(userName);
......@@ -53,7 +53,7 @@ public class LoginController {
}
@GetMapping("logout")
public ResResult logout(@RequestParam("user_name") String userName, @RequestParam("password") String password) {
public ResResult logout(@RequestParam("userName") String userName, @RequestParam("password") String password) {
// @RequestBody JSONObject jsonObject
LoginUser user = new LoginUser();
user.setUser_name(userName);
......
......@@ -4,7 +4,7 @@ package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.entity.Server;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.RespResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -33,7 +33,7 @@ public class ServerController {
*/
@PostMapping("add")
public BaseResult addServer(@RequestBody JSONObject jsonObject) {
String serverIp = jsonObject.getString("server_ip");
String serverIp = jsonObject.getString("serverIp");
int port = jsonObject.getInteger("port");
boolean res = serverService.addServer(serverIp,port);
if (res) {
......@@ -49,7 +49,7 @@ public class ServerController {
* @return
*/
@PostMapping("delete")
public BaseResult deleteServer(@RequestParam("server_ip") String serverIp) {
public BaseResult deleteServer(@RequestParam("serverIp") String serverIp) {
boolean res = serverService.deleteServer(serverIp);
if (res) {
return BaseResult.success();
......@@ -65,7 +65,7 @@ public class ServerController {
*/
@PostMapping("update")
public BaseResult updateServer(@RequestBody JSONObject jsonObject) {
String serverIp = jsonObject.getString("server_ip");
String serverIp = jsonObject.getString("serverIp");
int port = jsonObject.getInteger("port");
boolean res = serverService.updateServer(serverIp,port);
if (res) {
......@@ -83,9 +83,9 @@ public class ServerController {
* @return
*/
@GetMapping("list")
public RespResult getServerList(@RequestParam("page_no") int pageNo, @RequestParam("page_size") int pageSize) {
public ResResult getServerList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
List<Server> records = serverService.getServerList(pageNo,pageSize);
return RespResult.success().record(records);
return ResResult.success().record(records);
}
}
......@@ -35,7 +35,7 @@ public class UserController {
*/
@PostMapping("add")
public BaseResult addUser(@RequestBody JSONObject jsonObject) {
String userName = (String) jsonObject.get("user_name");
String userName = (String) jsonObject.get("userName");
String company = (String) jsonObject.get("company");
String password = CommonUtil.genRandomNum(18);
boolean res = userService.addUser(userName, company, password);
......@@ -52,7 +52,7 @@ public class UserController {
* @return
*/
@PostMapping("delete")
public BaseResult deleteUser(@RequestParam("user_id") int userId) {
public BaseResult deleteUser(@RequestParam("userId") int userId) {
boolean res = userService.deleteUser(userId);
if (res) {
return BaseResult.success();
......@@ -68,7 +68,7 @@ public class UserController {
*/
@PostMapping("update")
public BaseResult updateUser(@RequestBody JSONObject jsonObject) {
int userId = jsonObject.getInteger("user_id");
int userId = jsonObject.getInteger("userId");
String password = jsonObject.getString("password");
boolean res = userService.updateUser(userId, password);
if (res) {
......@@ -86,8 +86,8 @@ public class UserController {
* @return
*/
@GetMapping("list")
public PageResult getUserList(@RequestParam("page_no") int pageNo, @RequestParam("page_size") int pageSize,
@RequestParam(value = "user_name",required = false) String userName, @RequestParam(value = "company",required = false) String company) {
public PageResult getUserList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize,
@RequestParam(value = "userName",required = false) String userName, @RequestParam(value = "company",required = false) String company) {
PageInfoModel<UserVo> records = userService.getUserList(pageNo,pageSize,userName,company);
int total = records.getTotal();
int pages = total/pageSize;//pages为总页数
......
......@@ -7,14 +7,13 @@ import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@Slf4j
@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
//@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
public class JwtFilter implements Filter {
......
package iot.sixiang.license.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespResult {
private int code;
private String msg;
private Object data;
public static RespResult success() {
RespResult respResult = new RespResult();
respResult.setCode(200);
respResult.setMsg("success");
return respResult;
}
public static RespResult fail() {
RespResult respResult = new RespResult();
respResult.setCode(400);
respResult.setMsg("fail");
return respResult;
}
public RespResult msg(String message) {
this.msg = message;
return this;
}
public RespResult record(Object data){
this.data = data;
return this;
}
}
package iot.sixiang.license.model.vo;
import iot.sixiang.license.entity.User;
import lombok.Data;
/**
* Created by m33 on 2022/6/8 17:26
*/
@Data
public class UserVo extends User {
public int count;
}
......@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.User;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceTypeVo;
import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.JsonUtil;
......
package iot.sixiang.license.util;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
class MyCorsConfig {
// 跨域请求处理
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
//允许所有域名进行跨域调用
config.addAllowedOrigin("*");
//允许所有请求头
config.addAllowedHeader("*");
//允许所有方法
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment