@RestController
@RequestMapping(value = "/xyz")
public class SysControlMachineController extends BaseController {
@Autowired
private ISysControlMachineService controlMachineService;
/**
* get server time
*/
@PostMapping(value="/ServerTime", produces="application/json;charset=utf-8")
public ControlResult getServerTime(@RequestBody SysServerTime serverTime,
@RequestHeader("Device-ID") String deviceId) {
return controlMachineService.getServerTime(serverTime, wtrDeviceId);
}
/**
* comprehensive process
*/
@PostMapping(value="/ConsumTransactions", produces="application/json;charset=GB2312")
public ControlResult consumTransactions(@RequestBody SysConSum conSum,
@RequestHeader(name = "Device-ID") String deviceId)
{
return controlMachineService.consumTransactions(conSum, deviceId);
}
我请求第一个getServiceTime Rest api,有成功响应;但是当我请求第二个consumTransactions api时,返回错误:
“没有预设 Content-Type 'null' 的 [class com.....domain.ControlResult] 转换器”。
Spring Boot 默认启用“forceEncoding”。这会导致请求字符集每次在过滤器中都被覆盖并设置为 UTF-8。
所以你应该尝试设置这个
server.servlet.encoding.force = false
您也可以单独处理请求或响应
server.servlet.encoding.request-force = false
server.servlet.encoding.response-force = false