AJAX:对ajax得到的数据进行编码

AJAX: encoding data obtained by ajax

我有一个包含 UTF-8 表格的数据库。 Spring Web 应用程序连接到位于 jdbc:mysql://localhost:3306/recr?zeroDateTimeBehavior=convertToNull&amp;characterEncoding=utf8&amp;characterSetResults=utf8 的数据库 UTF-8 格式的所有 java 和 jsp 文件。在 header jsp 文件中有一个 <%@ page contentType="text/html; charset=UTF-8" %>

页面显示正确,但是当Ajax服务器接收到数据时,显示为?????

java脚本

$(document).ready(function() {
        $("#b2").click(function(){
              $.ajax({
                  type: "GET",
                  url: "/recr/getRegion2",
                  data: 'id=3159',
                  contentType: "application/json; charset=UTF-8",
                  dataType: "json",
                  success: function (data) {
                        //var json = jQuery.parseJSON(data);
                        for(var x in data){
                            $('#region').append($('<option>').text(data[x]).attr('value', x));


                            }

                        alert("Data: " + data);
                  },
                  error: function (errormessage) {

                    alert("error" + errormessage);

                  }
              });

控制器

@RequestMapping(value = "/getRegion2", method = RequestMethod.GET)
public @ResponseBody String getRegion2(@RequestParam("id") long id) throws Exception {
    System.out.println("пришло id : " + id);
    List<Region> regions = Facade.getRegionDao(dataSource).getAllRegionsByCountry(id);
    String res = JsonTransformer.transformRegionList(regions);
    return res;

}

可能是什么问题?

我找到了解决办法。 必须在控制器映射中指定。

@RequestMapping(value = "/getRegion2", produces={"application/json; charset=UTF-8"},method = RequestMethod.GET)