Commit a96c962e authored by mengmeng's avatar mengmeng

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

parent b241c582
<?xml version="1.0" encoding="UTF-8"?>
<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">
<facet type="jpa" name="JPA">
<configuration>
......
......@@ -3,6 +3,7 @@ package io.hmit.modules.competition.controller;
import io.hmit.common.annotation.LogOperation;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.ExcelUtils;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
......@@ -47,9 +48,9 @@ public class WlUploadInfoController {
@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.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){
PageData<WlUploadInfoDTO> page = wlUploadInfoService.page(params);
......@@ -65,6 +66,7 @@ public class WlUploadInfoController {
return new Result<WlUploadInfoDTO>().ok(data);
}
/*
@GetMapping("{name}")
@ApiOperation("信息")
//@RequiresPermissions("competition:wluploadinfo:info")
......@@ -73,6 +75,7 @@ public class WlUploadInfoController {
return new Result<List<WlUploadInfoDTO>>().ok(data);
}
*/
@PostMapping
@ApiOperation("保存")
......@@ -87,7 +90,7 @@ public class WlUploadInfoController {
return new Result();
}else {
return new Result().error();
return new Result().error(500,"人员信息已存在!");
}
}
......@@ -118,14 +121,16 @@ public class WlUploadInfoController {
return new Result();
}
// @GetMapping("export")
// @ApiOperation("导出")
// @LogOperation("导出")
// @RequiresPermissions("competition:wluploadinfo:export")
// public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
// List<WlUploadInfoDTO> list = wlUploadInfoService.list(params);
// ExcelUtils.exportExcelToTarget(response, "比赛数据", list, WlUploadInfoExcel.class);
// }
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("competition:wluploadinfo:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<WlUploadInfoDTO> list = wlUploadInfoService.list(params);
ExcelUtils.exportExcelToTarget(response, "比赛人员数据", list, WlUploadInfoExcel.class);
}
/*
@PostMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
......@@ -135,7 +140,8 @@ public class WlUploadInfoController {
for(int i=0;i<checklist.size();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 {
@ApiModelProperty(value = "就餐")
private String dinner;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
}
......@@ -28,9 +28,12 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl
@Override
public QueryWrapper<WlUploadInfoEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
String name = (String)params.get("name");
QueryWrapper<WlUploadInfoEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
wrapper.or();
wrapper.like(StringUtils.isNotBlank(name), "name", name);
return wrapper;
}
......@@ -40,7 +43,7 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl
public List<WlUploadInfoDTO> selectInfo(String name) {
List<WlUploadInfoEntity> wlList =baseDao.selectByName(name);
List<WlUploadInfoDTO> finallist =new ArrayList<>();
// ConvertUtils.sourceToTarget(finallist,WlUploadInfoEntity.class);
// ConvertUtils.sourceToTarget(wlList,WlUploadInfoEntity.class);
for(WlUploadInfoEntity wlUploadInfoEntity:wlList){
WlUploadInfoDTO wlInfo = new WlUploadInfoDTO();
BeanUtils.copyProperties(wlUploadInfoEntity,wlInfo);
......@@ -52,7 +55,7 @@ public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, Wl
@Override
public boolean isName(String name) {
int count = baseDao.isName(name);
System.out.println(count);
System.out.println(name+"信息已存在!");
if(count==0){
return true;
}else {
......
<?xml version="1.0" encoding="UTF-8"?>
<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">
<facet type="Spring" name="Spring">
<configuration />
......
......@@ -4,6 +4,7 @@ package io.hmit.controller;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.annotation.LogOperation;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils;
......@@ -21,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import sun.net.www.content.text.plain;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
......@@ -64,24 +66,55 @@ public class WlUploadInfoController {
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
@ApiOperation("保存")
@LogOperation("保存")
//@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){
//校验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
boolean flag = wlUploadInfoService.isName(dto.getName());
if(flag){
wlUploadInfoService.save(dto);
return new Result();
}else {
return new Result().error();
return new Result().error(500,"人员信息已存在!");
}
}
@PutMapping
@ApiOperation("修改")
......
package io.hmit.dto;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;
/**
......@@ -65,5 +67,26 @@ public class WlUploadInfoDTO implements Serializable {
@ApiModelProperty(value = "修改时间")
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 {
response.setHeader("Access-Control-Allow-Headers", "*");
// 如果是OPTIONS则结束请求
/*
if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) {
response.setStatus(HttpStatus.NO_CONTENT.value());
return false;
}
*/
return true;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<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">
<facet type="Spring" name="Spring">
<configuration />
......
<?xml version="1.0" encoding="UTF-8"?>
<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">
<facet type="Spring" name="Spring">
<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