android Retrofit框架使用@body上传数据,服务端接收数据为空的解决办法

时间:2022-08-29 00:15:30
有时候当上传的数据参数很多的时候,会用model打包上传,但是如果服务端的解析方式不当,无论你怎么上传,服务端解析到的数据包里面数据都是null
服务端请用ResponseBody
客户端:
@POST("FenceSetting/add")    Observable<MyHttpResponse<FenceBean>> addFence(@Body RequestBody fenceSetting);
 

服务端:

 @InitBinder("fenceSetting")	public void initBinderUser(WebDataBinder binder) {		binder.setFieldDefaultPrefix("fenceSetting.");	}        @RequestMapping(value="/add", method = RequestMethod.POST)    public @ResponseBody JSONResponse<FenceSetting> add(@RequestBody FenceSetting fenceSetting) throws Exception{    	    	mapper.insert(fenceSetting);    	return new JSONResponse<FenceSetting>(fenceSetting, MsgConstant.success_cd,MsgConstant.success, true);    }