2016-05-05 11 views
2

を返すことができません: "?????"春@RestControllerは、私はUnicode文字列を返す簡単なRestController持っユニコード

@RestController 
@RequestMapping(path = "/") 
public class FooController { 
    @RequestMapping(method = RequestMethod.GET) 
    public String test() throws Exception { 
     return "ỗ ẵ ẫ ậ ự"; 
    } 
} 

をしかし、実行すると、それだけでを表示します

<filter> 
     <filter-name>characterEncodingFilter</filter-name> 
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
     <init-param> 
      <param-name>encoding</param-name> 
      <param-value>UTF-8</param-value> 
     </init-param> 
     <init-param> 
      <param-name>forceEncoding</param-name> 
      <param-value>true</param-value> 
     </init-param> 
    </filter> 
    <filter-mapping> 
     <filter-name>characterEncodingFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

をそして、私は簡単なのHttpServletをテストするとき、それは、Unicode文字列の上に返すことができます:は、私はこの問題を解決するにはどうすればよい、私はすでにweb.xmlにこの設定を持っていました。ケースの他に

+1

レスポンスヘッダ? – Blank

+0

@Reno私は設定していません。 – yelliver

答えて

0

が同じに遭遇...
を追加文字セットと注釈を生成= UTF-8
は次にようにレスポンスオブジェクトを使用する:の `のContent-type`がある何

@RestController 
@RequestMapping(path = "/") 
@Produces(MediaType.TEXT_PLAIN + ";charset=utf-8") 
public class FooController { 
    @RequestMapping(method = RequestMethod.GET) 
    public Response test() throws Exception { 
      return Response.status(HttpStatus.OK).entity("ỗ ẵ ẫ ậ ự").build(); 
    } 
} 
関連する問題