Commit 933cfc22 by tyfanchz

接口请求方式修改

1 parent 20bcfd35
package cn.com.glsx.smart.common.filter;
import com.glsx.plat.common.utils.StringUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
/**
* <p>Description: 跨域配置
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-18
*/
//@Component
public class ChejiaCorsFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
StringBuffer headersSb = new StringBuffer();
Enumeration<String> headerNames = httpRequest.getHeaderNames();
while (headerNames.hasMoreElements()) {
headersSb.append(headerNames.nextElement()).append(", ");
}
if (!StringUtils.containsIgnoreCase(headersSb, HttpHeaders.CONTENT_TYPE)) {
headersSb.append(HttpHeaders.CONTENT_TYPE).append(", ");
}
if (!StringUtils.containsIgnoreCase(headersSb, HttpHeaders.AUTHORIZATION)) {
headersSb.append(HttpHeaders.AUTHORIZATION).append(", ");
}
httpResponse.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS,
headersSb.toString().replaceAll(", +$", ""));
httpResponse.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
httpResponse.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,
httpRequest.getHeader(HttpHeaders.ORIGIN));
httpResponse.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,
httpRequest.getMethod());
httpResponse.addHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "*");
httpResponse.addHeader(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "18000L");
// 放行预检请求(preflight requests)
if (httpRequest.getMethod().equalsIgnoreCase(HttpMethod.OPTIONS.toString())) {
httpResponse.setStatus(HttpServletResponse.SC_OK);
httpResponse.getWriter().println("OK");
return;
}
chain.doFilter(request, response);
}
}
...@@ -66,7 +66,7 @@ public class ProductController { ...@@ -66,7 +66,7 @@ public class ProductController {
* @param req 请求体 * @param req 请求体
* @return 结果 * @return 结果
*/ */
@GetMapping("/getListByCondition") @PostMapping("/getListByCondition")
public R getListByCondition(@RequestBody ProductReq req) { public R getListByCondition(@RequestBody ProductReq req) {
log.info("/product/getListByCondition param: {}", JSON.toJSONString(req)); log.info("/product/getListByCondition param: {}", JSON.toJSONString(req));
List<SmartProduct> productList = productService.getListByCondition(req); List<SmartProduct> productList = productService.getListByCondition(req);
......
...@@ -91,7 +91,7 @@ public class ProductTypeController { ...@@ -91,7 +91,7 @@ public class ProductTypeController {
* *
* @return 结果 * @return 结果
*/ */
@GetMapping("/getListAndContent") @PostMapping("/getListAndContent")
public R getListAndContent(@RequestBody List<Long> list) { public R getListAndContent(@RequestBody List<Long> list) {
List<SmartProductType> contentList = productTypeService.getListAndContent(list); List<SmartProductType> contentList = productTypeService.getListAndContent(list);
List<ProductTypeResponse> responseList = new ArrayList<>(); List<ProductTypeResponse> responseList = new ArrayList<>();
...@@ -104,7 +104,7 @@ public class ProductTypeController { ...@@ -104,7 +104,7 @@ public class ProductTypeController {
* *
* @return 结果 * @return 结果
*/ */
@GetMapping("/getListAndCondition") @PostMapping("/getListAndCondition")
public R getListAndCondition(@RequestBody List<Long> list) { public R getListAndCondition(@RequestBody List<Long> list) {
List<SmartProductType> conditionList = productTypeService.getListAndCondition(list); List<SmartProductType> conditionList = productTypeService.getListAndCondition(list);
List<ProductTypeResponse> responseList = new ArrayList<>(); List<ProductTypeResponse> responseList = new ArrayList<>();
......
...@@ -23,11 +23,11 @@ import org.apache.commons.collections.CollectionUtils; ...@@ -23,11 +23,11 @@ import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
...@@ -57,8 +57,7 @@ public class RemoteProductController { ...@@ -57,8 +57,7 @@ public class RemoteProductController {
* *
* @return 结果 * @return 结果
*/ */
@ResponseBody @PostMapping(value = "/getList")
@RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
public R getList(@RequestBody UserRelationRequest relationRequest) { public R getList(@RequestBody UserRelationRequest relationRequest) {
log.info("用户参数:{}", JSON.toJSONString(relationRequest)); log.info("用户参数:{}", JSON.toJSONString(relationRequest));
SmartUserRelation request = new SmartUserRelation(); SmartUserRelation request = new SmartUserRelation();
...@@ -120,8 +119,7 @@ public class RemoteProductController { ...@@ -120,8 +119,7 @@ public class RemoteProductController {
* *
* @return 结果 * @return 结果
*/ */
@ResponseBody @GetMapping(value = "/findRemotes")
@RequestMapping(value = "/findRemotes", method = {RequestMethod.GET})
@ApiOperation(value = "查询红外设备下的遥控器") @ApiOperation(value = "查询红外设备下的遥控器")
public String findRemotes(@RequestParam String infrared_id) { public String findRemotes(@RequestParam String infrared_id) {
return productTypeService.findRemotesById(infrared_id); return productTypeService.findRemotesById(infrared_id);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!