PostMan上传文件到Java后台
Posted java李杨勇
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PostMan上传文件到Java后台相关的知识,希望对你有一定的参考价值。
post参数文件设置
Java后台接受并处理请求
/**
* 上传表格数据
* @param model
* @param request
* @param response
* @return
*/
@RequestMapping(value = "shangchuan")
public synchronized R fileUpload(Model model,HttpServletRequest request,HttpServletResponse response)
try
String[] fields = "lineName", "majorName", "procedureName", "totalQuantity";
List<ConstructionProcedureConfig> map = ExcelImportUtil.getImportData(fields, ConstructionProcedureConfig.class, request);
List<ConstructionProcedureConfig> configs=new ArrayList<>();
for(int i=0;i<map.size();i++)
ConstructionProcedureConfig config = map.get(i);
//查询线路
EntityWrapper<DqLinename> entityWrapper = new EntityWrapper<DqLinename>();
Wrapper<DqLinename> wrapper = entityWrapper.eq("linename", config.getLineName());
DqLinename dqLinename = dqLinenameService.selectOne(wrapper);
if(dqLinename == null)
return R.error("线路数据不存在");
if(!BaseMajorEnum.DQ_QYBDZ.getName().equals(config.getMajorName()))
return R.error("专业数据不存在");
BaseConstructionProcedure baseConstruct = baseConstructionProcedureService.getByName(majorId, config.getProcedureName());
if(baseConstruct == null)
return R.error("工序数据不存在");
//通过线路名称和专业分类名称以及工序名称获取唯一施工配置
EntityWrapper<ConstructionProcedureConfig> coEntityWrapper = new EntityWrapper<ConstructionProcedureConfig>();
Wrapper<ConstructionProcedureConfig> configwrapper = coEntityWrapper.eq("lineid", dqLinename.getId())
.eq("major_name", config.getMajorName())
.eq("procedure_name", config.getProcedureName());
ConstructionProcedureConfig constructionprocedureconfig = constructionProcedureConfigService.selectOne(configwrapper);
if(constructionprocedureconfig == null)
constructionprocedureconfig = new ConstructionProcedureConfig();
constructionprocedureconfig.setLineid(dqLinename.getId());
constructionprocedureconfig.setLineName(dqLinename.getLinename());
constructionprocedureconfig.setMajorId(majorId);
constructionprocedureconfig.setMajorName(config.getMajorName());
constructionprocedureconfig.setProcedureCode(baseConstruct.getCode());
constructionprocedureconfig.setProcedureId(baseConstruct.getId());
constructionprocedureconfig.setProcedureName(baseConstruct.getName());
constructionprocedureconfig.setUnit(baseConstruct.getUnit());
constructionprocedureconfig.setSort(baseConstruct.getSort());
constructionprocedureconfig.setTotalQuantity(config.getTotalQuantity());
else
constructionprocedureconfig.setTotalQuantity(config.getTotalQuantity());
configs.add(constructionprocedureconfig);
constructionProcedureConfigService.insertOrUpdateBatch(configs);
return R.ok();
catch (Exception e)
logger.error("excel上传异常:", e);
return R.error("上传失败");
以上是关于PostMan上传文件到Java后台的主要内容,如果未能解决你的问题,请参考以下文章