[WARN ] 2018-04-03 09:09:40 DefaultHandlerExceptionResolver@(DefaultHandlerExceptionResolver.java:38

function initPage(){
	var location = window.location.href;
	var fromIndex = location.indexOf("/Shopping/");
	var serviceUrl = location.substring(0, fromIndex);
	var params={
			
	};
	$.ajax({
		url : serviceUrl + "/Shopping/userinfo/getuserlist",
		type : 'post',
		data:params,
		contentType : 'application/json;charset=utf-8',
		success : function(data) {
			console.log(data);
		},
		error : function(error) {
			console.log('接口不通' + error);
		}
	});
	
}

上面是利用ajax请求后台的restful接口

接口代码如下:

	/**
	 * 获取所有满足的条件的用户
	 * @param params
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/getuserlist",produces = "application/json; charset=utf-8")
	public @ResponseBody String getUserList(@RequestBody String params,@Context HttpServletResponse response) throws IOException{
	    log.info("-----------------开始调用getuserlist------------------------------------");
        JSONArray json_arr=userService.getUserListInfo();
        log.info("------------------结束调用getuserlist------------------------------------");
        JSONObject json=new JSONObject();
        json.put("userlist", json_arr);
        return BuildJsonOfObject.buildJsonOfJsonObject(json);
	}
就这样看着还挺完美的,但是却十分的不尽人意,总是出现这样的错误
[WARN ] 2018-04-03 09:09:40 DefaultHandlerExceptionResolver@(DefaultHandlerExceptionResolver.java:384):Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.lang.String com.wdg.controller.UserController.getUserList(java.lang.String) throws java.io.IOException

我把这样的错误放到网上看了一大堆说什么异常处理啊之类的,但是我可不是想要这样的结果,我们知道的是应该怎样来解决这样的的问题

原因是后台接口有接收参数的@RequestBody  没有向后台传递参数,或者是参数为空

解决办法:

1.后台的接口参数去掉

2.前台ajax里面添加 data:params   其中params是不能为空的


希望对你有所帮助








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
runtime-core.esm-bundler.js:41 [Vue warn]: Unhandled error during execution of beforeMount hook at <App> warn @ runtime-core.esm-bundler.js:41 logError @ runtime-core.esm-bundler.js:216 handleError @ runtime-core.esm-bundler.js:208 callWithErrorHandling @ runtime-core.esm-bundler.js:160 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:166 hook.__weh.hook.__weh @ runtime-core.esm-bundler.js:2655 invokeArrayFns @ shared.esm-bundler.js:77 componentUpdateFn @ runtime-core.esm-bundler.js:5657 run @ reactivity.esm-bundler.js:178 instance.update @ runtime-core.esm-bundler.js:5814 setupRenderEffect @ runtime-core.esm-bundler.js:5822 mountComponent @ runtime-core.esm-bundler.js:5612 processComponent @ runtime-core.esm-bundler.js:5565 patch @ runtime-core.esm-bundler.js:5040 render @ runtime-core.esm-bundler.js:6332 mount @ runtime-core.esm-bundler.js:3824 app.mount @ runtime-dom.esm-bundler.js:1431 eval @ main.js:7 ./src/main.js @ app.js:85 __webpack_require__ @ app.js:359 (匿名) @ app.js:1539 __webpack_require__.O @ app.js:405 (匿名) @ app.js:1540 (匿名) @ app.js:1542 app.js:362 Uncaught TypeError: (0 , _test__WEBPACK_IMPORTED_MODULE_1__.holleTest) is not a function at eval (App.vue:77:1) at eval (runtime-core.esm-bundler.js:2675:1) at callWithErrorHandling (runtime-core.esm-bundler.js:158:1) at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:166:1) at hook.__weh.hook.__weh (runtime-core.esm-bundler.js:2655:1) at invokeArrayFns (shared.esm-bundler.js:77:1) at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5657:1) at ReactiveEffect.run (reactivity.esm-bundler.js:178:1) at instance.update (runtime-core.esm-bundler.js:5814:1) at setupRenderEffect (runtime-core.esm-bundler.js:5822:1)
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值