post表单json接口
Posted Heng-
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了post表单json接口相关的知识,希望对你有一定的参考价值。
package com.lv.qggz.man.dhht.api.typesetting;
import com.lv.qggz.man.dhht.api.typesetting.vo.UVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* @Author: sh
* @Description: TypeSettingController
* @Date: 22:00 2019/12/31
*/
@Controller
@RequestMapping("/api/typesetting")
public class TypeSettingController {
/**
* POST json提交
* @param json
* @param request
* @return
*/
@RequestMapping(value = "/hello", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public String hello(@RequestBody String json, HttpServletRequest request) {
String head = request.getHeader("token");
System.out.println("head:" + head);
return json;
}
/**
* POST form表单,多附件提交
* @param uvo
* @param request
* @return
*/
@RequestMapping(value = "/word",method = RequestMethod.POST,produces = "application/json;charset=UTF-8",consumes = "multipart/form-data")
public String word(UVO uvo,HttpServletRequest request){
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
List<MultipartFile> files = multipartHttpServletRequest.getFiles("file");
System.out.println(uvo);
return null;
}
}
以上是关于post表单json接口的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot 一个接口同时支持 form 表单、form-data、json 优雅写法