springmvc的controller方法中接受到的引數值為NULL
阿新 • • 發佈:2019-02-02
最近遇到一個問題controller方法中接收到的引數為Null,使用的是spring-webmvc-4.3.1,tomcat使用的是tomcat6,前後臺程式碼大概如下:
function test7(){ var user={"username":"zhangsan","password":"0000fe87eeb84a009e68859573a81069"}; $.ajax({ type:'POST', url:"http://localhost:8080/springmvc/test7.json", data:user, success:function(data){ console.log(data); }, error:function(data){ console.log(data); } }); }
@RequestMapping(value="/test7")
public String test7(String username,HttpServletRequest request){
System.out.println("引數:"+username);//這裡接收到的username總是為null
..........................
return "demo1";
}
在後臺test7方法中接收到的username值始終為null,但是直接從request中取是可以取到值的,後來發本地服務換成tomcat7後就可以正常接收了。這裡不去糾結為什麼了,肯定是4.3程式碼裡需要至少tomcat7及以上的執行環境,查下