用form表單提交數據給后台時返回415,主要是瀏覽器的原生表單,如果不設置 enctype 屬性,那么最終就會以 application/x-www-form-urlencoded 方式提交數據。
而Java后台默認的post請求方式的控制器默認
后台控制器: @RequestMapping(value="/addUser", method=RequestMethod.POST, consumes="application/json") public String addUser() { return "success"; }
要改為@RequestMapping(value="/addUser", method=RequestMethod.POST, consumes="application/x-www-form-urlencoded") public String addUser() { return "success"; }