我正在将印地语存储在数据库中。
在我的 fetch 方法中,我使用 objectMapper
它将印地语字体转换为特殊字符。没有objectmapper
它工作正常。
@CrossOrigin
@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> fetchDepartmentInfo() {
try {
List<Map<String, Object>> departmentList = departmentServices.fetchDepartments();
if (departmentList == null || departmentList.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
else
return new ResponseEntity<String>(new ObjectMapper().writeValueAsString(departmentList), HttpStatus.OK);
} catch (Exception e) {
System.out.println(e);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
o/p:
[
{
"department": "?? ?? ?????",
"departmentId": 1
}
]
但应该是:
[
{
"department": "जल कल विभाग",
"departmentId": 1
}
]
最佳答案
刚刚将 mediaType 更改为 APPLICATION_JSON_UTF8_VALUE
@CrossOrigin
@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<?> fetchDepartmentInfo() {
try {
List<Map<String, Object>> departmentList = departmentServices.fetchDepartments();
if (departmentList == null || departmentList.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
else
return new ResponseEntity<String>(new ObjectMapper().writeValueAsString(departmentList), HttpStatus.OK);
} catch (Exception e) {
System.out.println(e);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
它解决了我的问题。
关于java - objectMapper 将印地语文本转换为特殊字符 "???",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45397929/