importcom.jeat.clinic.controller.OVmodel.BookType;importorg.springframework.util.MultiValueMap;import org.springframework.web.bind.annotation.*;importjavax.servlet.http.HttpServletRequest;importjava.util.List;importjava.util.Map;/***@author* @class JsonTest
* @Abstract
* @date 2019/02/19*/@RestControllerpublic classJsonTest {/*** 以实体类接收
*@parambookType
*@paramrequest
*@return* {"id":12,"typeName":"类型1"}*/@RequestMapping(value="acceptJsonByEntity",method =RequestMethod.POST)publicBookType acceptJsonByEntity(@RequestBody BookType bookType, HttpServletRequest request){
System.out.println("当前http请求方式为:"+request.getMethod());
System.out.println(bookType);returnbookType;
}/*** 以map方式接收
*@paramparamsMap
*@paramrequest
*@return
*/@RequestMapping(value="acceptJsonByMap")public Map acceptJsonByMap(@RequestBody MapparamsMap, HttpServletRequest request){
System.out.println("当前http请求方式为:"+request.getMethod());
System.out.println(paramsMap);returnparamsMap;
}/*** 以list方式接收(以json数组形式传递)
*@parambookTypeList
*@paramrequest
*@return
*/@RequestMapping(value="acceptJsonByList")public List acceptJsonByList(@RequestBody ListbookTypeList, HttpServletRequest request){
System.out.println("当前http请求方式为:"+request.getMethod());
System.out.println(bookTypeList);returnbookTypeList;
}/*** 以单独属性形式接收
*@paramid
*@paramname
*@return
*/@RequestMapping("acceptJsonBySingleParam")publicMultiValueMap acceptJsonByRequestParam(@RequestBody MultiValueMap params/*@RequestBody int userId,
@RequestBody String userName*/) {
System.out.println(params.get("userId")+","+params.get("userName"));returnparams;
}
}