controller如下:
@Controller
@RequestMapping("/publish")
class PublishController {
@RequestMapping
@ResponseBody
public String publish(@RequestBody String data) throws UnsupportedEncodingException {
System.out.println("the data is "+data);
System.out.println("the data2 is "+ new String(data.getBytes("UTF-8"), "GBK"));
return "success";
}
}
打印结果:
the data is {"classify":"???","title":"1"}
the data2 is {"classify":"软件","title":"1"}
也就是说请求的编码是UTF-8,但是spring用GBK解码成String了。
我设置了StringHttpMessageConverter
UTF-8也不好使。
这个解码在哪里设置吗?为什么默认的解码是GBK?