发表于: 2017-09-09 23:43:05

4 839


今天完成的事情:

1.完成图片上传的接口,不会写,参照的是官网萝卜多的代码

// 图片上传
@RequestMapping(value = "/a/u/img/{module}", method = RequestMethod.POST)
public String postImg(HttpServletRequest request, HttpServletResponse response, Model model,
@RequestParam MultipartFile file, @PathVariable String module ) throws Exception {
log.info("=========>get file is"+file);
log.info("=========>get module is"+module);

if (StringUtils.isBlank(module)) {
module = "common";
}
int code = 0;
log.info(file.getOriginalFilename());

Long uid = cookieUtil.getID(request, response);
try {
String type = file.getContentType();
long size = file.getSize();
log.info("  size is =" + size / 1048576);
String extend = FileUtil.getFileExtension(file
               .getOriginalFilename());

String fileName = UUID.randomUUID().toString() + "." + extend;
log.info("new name is " + fileName);
String filePath = "/data/temp/" + fileName;

File tempPic = new File(filePath);
file.transferTo(tempPic);
String url = this.imgStorageUtil.imgStorage(null, module + "/"
               + fileName, filePath);
log.info(module + " upload success ,and file name is " + fileName
               + "temp path is " + filePath + " access url is " + url);
tempPic.delete();
log.info(file.getOriginalFilename() + " delete success ");
model.addAttribute("url", url);
model.addAttribute("code", 0);
return "/common/img";
} catch (Throwable t) {
t.printStackTrace();
log.error(t.getMessage());
return "/common/success";
}


2.完成article的查看,新增,删除接口,新增还在测试

3.昨天的公司的新增接口,修改接口,用Postman测试,还是不行但是不是400bad request了,而是500的错误。这个因为数据类型的原因导致的。


明天计划的事情:

1.完成article的接口

2.部署项目


遇到的问题:
用post方法和put方法时,不知道能不能用body传数据,前端的师兄说是用key-value来传,可能我之前的数据传输方式一直有问题,还没有测试,测试完看能否成功。

我之前用body传值的时候,后台的接口使用的@RequestBody来接这个值,但是还是报错了。


总结:

之前用自己的设计的方案来写写接口的时候,设计是按简单的来写,现在按公公共接口来写,难度相当于我们之前的几口来说是加了一点。这也算是锻炼自己吧。










返回列表 返回列表
评论

    分享到