Commit a96c962e authored by mengmeng's avatar mengmeng

0720 解决跨域post 预检测option问题;最后完善版本

parent b241c582
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="FacetManager"> <component name="FacetManager">
<facet type="jpa" name="JPA"> <facet type="jpa" name="JPA">
<configuration> <configuration>
......
...@@ -3,6 +3,7 @@ package io.hmit.modules.competition.controller; ...@@ -3,6 +3,7 @@ package io.hmit.modules.competition.controller;
import io.hmit.common.annotation.LogOperation; import io.hmit.common.annotation.LogOperation;
import io.hmit.common.constant.Constant; import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData; import io.hmit.common.page.PageData;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.ExcelUtils; import io.hmit.common.utils.ExcelUtils;
import io.hmit.common.utils.Result; import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils; import io.hmit.common.validator.AssertUtils;
...@@ -47,9 +48,9 @@ public class WlUploadInfoController { ...@@ -47,9 +48,9 @@ public class WlUploadInfoController {
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String"),
}) })
@RequiresPermissions("competition:wluploadinfo:page") // @RequiresPermissions("competition:wluploadinfo:page")
public Result<PageData<WlUploadInfoDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){ public Result<PageData<WlUploadInfoDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<WlUploadInfoDTO> page = wlUploadInfoService.page(params); PageData<WlUploadInfoDTO> page = wlUploadInfoService.page(params);
...@@ -65,6 +66,7 @@ public class WlUploadInfoController { ...@@ -65,6 +66,7 @@ public class WlUploadInfoController {
return new Result<WlUploadInfoDTO>().ok(data); return new Result<WlUploadInfoDTO>().ok(data);
} }
/*
@GetMapping("{name}") @GetMapping("{name}")
@ApiOperation("信息") @ApiOperation("信息")
//@RequiresPermissions("competition:wluploadinfo:info") //@RequiresPermissions("competition:wluploadinfo:info")
...@@ -73,6 +75,7 @@ public class WlUploadInfoController { ...@@ -73,6 +75,7 @@ public class WlUploadInfoController {
return new Result<List<WlUploadInfoDTO>>().ok(data); return new Result<List<WlUploadInfoDTO>>().ok(data);
} }
*/
@PostMapping @PostMapping
@ApiOperation("保存") @ApiOperation("保存")
...@@ -87,7 +90,7 @@ public class WlUploadInfoController { ...@@ -87,7 +90,7 @@ public class WlUploadInfoController {
return new Result(); return new Result();
}else { }else {
return new Result().error(); return new Result().error(500,"人员信息已存在!");
} }
} }
...@@ -118,14 +121,16 @@ public class WlUploadInfoController { ...@@ -118,14 +121,16 @@ public class WlUploadInfoController {
return new Result(); return new Result();
} }
// @GetMapping("export") @GetMapping("export")
// @ApiOperation("导出") @ApiOperation("导出")
// @LogOperation("导出") @LogOperation("导出")
// @RequiresPermissions("competition:wluploadinfo:export") @RequiresPermissions("competition:wluploadinfo:export")
// public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception { public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
// List<WlUploadInfoDTO> list = wlUploadInfoService.list(params); List<WlUploadInfoDTO> list = wlUploadInfoService.list(params);
// ExcelUtils.exportExcelToTarget(response, "比赛数据", list, WlUploadInfoExcel.class); ExcelUtils.exportExcelToTarget(response, "比赛人员数据", list, WlUploadInfoExcel.class);
// } }
/*
@PostMapping("export") @PostMapping("export")
@ApiOperation("导出") @ApiOperation("导出")
@LogOperation("导出") @LogOperation("导出")
...@@ -135,7 +140,8 @@ public class WlUploadInfoController { ...@@ -135,7 +140,8 @@ public class WlUploadInfoController {
for(int i=0;i<checklist.size();i++){ for(int i=0;i<checklist.size();i++){
list.add(wlUploadInfoService.get(checklist.get(i))); list.add(wlUploadInfoService.get(checklist.get(i)));
} }
ExcelUtils.exportExcelToTarget(response, "比赛数据", list, WlUploadInfoExcel.class); ExcelUtils.exportExcelToTarget(response, "比赛人员数据", list, WlUploadInfoExcel.class);
} }
*/
} }
...@@ -58,11 +58,4 @@ public class WlUploadInfoDTO implements Serializable { ...@@ -58,11 +58,4 @@ public class WlUploadInfoDTO implements Serializable {
@ApiModelProperty(value = "就餐") @ApiModelProperty(value = "就餐")
private String dinner; private String dinner;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
} }
...@@ -28,9 +28,12 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl ...@@ -28,9 +28,12 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl
@Override @Override
public QueryWrapper<WlUploadInfoEntity> getWrapper(Map<String, Object> params){ public QueryWrapper<WlUploadInfoEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get("id"); String id = (String)params.get("id");
String name = (String)params.get("name");
QueryWrapper<WlUploadInfoEntity> wrapper = new QueryWrapper<>(); QueryWrapper<WlUploadInfoEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id); wrapper.eq(StringUtils.isNotBlank(id), "id", id);
wrapper.or();
wrapper.like(StringUtils.isNotBlank(name), "name", name);
return wrapper; return wrapper;
} }
...@@ -40,7 +43,7 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl ...@@ -40,7 +43,7 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl
public List<WlUploadInfoDTO> selectInfo(String name) { public List<WlUploadInfoDTO> selectInfo(String name) {
List<WlUploadInfoEntity> wlList =baseDao.selectByName(name); List<WlUploadInfoEntity> wlList =baseDao.selectByName(name);
List<WlUploadInfoDTO> finallist =new ArrayList<>(); List<WlUploadInfoDTO> finallist =new ArrayList<>();
// ConvertUtils.sourceToTarget(finallist,WlUploadInfoEntity.class); // ConvertUtils.sourceToTarget(wlList,WlUploadInfoEntity.class);
for(WlUploadInfoEntity wlUploadInfoEntity:wlList){ for(WlUploadInfoEntity wlUploadInfoEntity:wlList){
WlUploadInfoDTO wlInfo = new WlUploadInfoDTO(); WlUploadInfoDTO wlInfo = new WlUploadInfoDTO();
BeanUtils.copyProperties(wlUploadInfoEntity,wlInfo); BeanUtils.copyProperties(wlUploadInfoEntity,wlInfo);
...@@ -52,7 +55,7 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl ...@@ -52,7 +55,7 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl
@Override @Override
public boolean isName(String name) { public boolean isName(String name) {
int count = baseDao.isName(name); int count = baseDao.isName(name);
System.out.println(count); System.out.println(name+"信息已存在!");
if(count==0){ if(count==0){
return true; return true;
}else { }else {
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="FacetManager"> <component name="FacetManager">
<facet type="Spring" name="Spring"> <facet type="Spring" name="Spring">
<configuration /> <configuration />
......
...@@ -4,6 +4,7 @@ package io.hmit.controller; ...@@ -4,6 +4,7 @@ package io.hmit.controller;
import io.hmit.common.constant.Constant; import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData; import io.hmit.common.page.PageData;
import io.hmit.annotation.LogOperation; import io.hmit.annotation.LogOperation;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.Result; import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils; import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils; import io.hmit.common.validator.ValidatorUtils;
...@@ -21,6 +22,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -21,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import sun.net.www.content.text.plain;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
...@@ -64,24 +66,55 @@ public class WlUploadInfoController { ...@@ -64,24 +66,55 @@ public class WlUploadInfoController {
return new Result<WlUploadInfoDTO>().ok(data); return new Result<WlUploadInfoDTO>().ok(data);
} }
/*
@RequestParam 注解,默认 content-type:application/x-www-form-urlencoded;charset=UTF-8;
当Content-Type:只限于三个值application/x-www-form-urlencoded、multipart/form-data、text/plain
时,为简单请求,不会出现跨域的Option问题
*/
@PostMapping @PostMapping
@ApiOperation("保存") @ApiOperation("保存")
@LogOperation("保存") @LogOperation("保存")
//@RequiresPermissions("competition:wluploadinfo:save") //@RequiresPermissions("competition:wluploadinfo:save")
public Result save(@RequestParam Map<String, String> params){
WlUploadInfoDTO dto = new WlUploadInfoDTO().assembleWluploadInfo(params);
boolean flag = wlUploadInfoService.isName(dto.getName());
if(flag){
wlUploadInfoService.save(dto);
return new Result();
}else {
return new Result().error(500,"人员信息已存在!");
}
}
/*
最后使用版本
前端使用json格式传输数据,SpringBoot @RequestBody 注解,默认只接收前端使用json进行传输
content-type:application/json;charset=UTF-8;
解决跨域问题,配置cors,前端访问接口使用域名访问,而不是IP+端口的形式
*/
@PostMapping("/bodySave")
@ApiOperation("保存")
@LogOperation("保存")
//@RequiresPermissions("competition:wluploadinfo:save")
public Result save(@RequestBody WlUploadInfoDTO dto){ public Result save(@RequestBody WlUploadInfoDTO dto){
//校验数据 //校验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
boolean flag = wlUploadInfoService.isName(dto.getName()); boolean flag = wlUploadInfoService.isName(dto.getName());
if(flag){ if(flag){
wlUploadInfoService.save(dto); wlUploadInfoService.save(dto);
return new Result(); return new Result();
}else { }else {
return new Result().error(); return new Result().error(500,"人员信息已存在!");
} }
} }
@PutMapping @PutMapping
@ApiOperation("修改") @ApiOperation("修改")
......
package io.hmit.dto; package io.hmit.dto;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Map;
/** /**
...@@ -65,5 +67,26 @@ public class WlUploadInfoDTO implements Serializable { ...@@ -65,5 +67,26 @@ public class WlUploadInfoDTO implements Serializable {
@ApiModelProperty(value = "修改时间") @ApiModelProperty(value = "修改时间")
private Date updateTime; private Date updateTime;
public WlUploadInfoDTO assembleWluploadInfo(Map<String, String> params){
WlUploadInfoDTO wlUploadInfoDTO = new WlUploadInfoDTO();
wlUploadInfoDTO.setId(IdWorker.getId());
wlUploadInfoDTO.setName(params.get("name"));
wlUploadInfoDTO.setSex(params.get("sex"));
wlUploadInfoDTO.setEmployer(params.get("employer"));
wlUploadInfoDTO.setJob(params.get("job"));
wlUploadInfoDTO.setEmail(params.get("email"));
wlUploadInfoDTO.setMember(params.get("member"));
wlUploadInfoDTO.setWithMember(params.get("withMember"));
wlUploadInfoDTO.setWithRelationship(params.get("withRelationship"));
wlUploadInfoDTO.setPhone(params.get("phone"));
wlUploadInfoDTO.setHeight(params.get("height"));
wlUploadInfoDTO.setWeight(params.get("weight"));
wlUploadInfoDTO.setDinner(params.get("dinner"));
wlUploadInfoDTO.setCreateTime(new Date());
wlUploadInfoDTO.setUpdateTime(new Date());
return wlUploadInfoDTO;
}
} }
...@@ -20,10 +20,12 @@ public class CorsInterceptor implements HandlerInterceptor { ...@@ -20,10 +20,12 @@ public class CorsInterceptor implements HandlerInterceptor {
response.setHeader("Access-Control-Allow-Headers", "*"); response.setHeader("Access-Control-Allow-Headers", "*");
// 如果是OPTIONS则结束请求 // 如果是OPTIONS则结束请求
/*
if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) { if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) {
response.setStatus(HttpStatus.NO_CONTENT.value()); response.setStatus(HttpStatus.NO_CONTENT.value());
return false; return false;
} }
*/
return true; return true;
} }
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="FacetManager"> <component name="FacetManager">
<facet type="Spring" name="Spring"> <facet type="Spring" name="Spring">
<configuration /> <configuration />
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="FacetManager"> <component name="FacetManager">
<facet type="Spring" name="Spring"> <facet type="Spring" name="Spring">
<configuration /> <configuration />
......
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