我的控制器代码如下:
@GetMapping("/test")
public TestOutputDTO getSchedule(@Valid TestInputDTO dto, BindingResult bindingResult) throws JusException {
if (bindingResult.hasErrors()) {
....
}
...
}TestInputDTO定义如下:
@Getter
@Setter
public class TestInputDTO {
@NotNull
@JsonProperty("test_id")
private Long testId;
}id=1不工作,testId为null。
http://localhost:8866/test?testId=1工程
我想用test_id风格来调用这个api。
我能用这个做什么?
塞恩斯。
发布于 2018-07-27 08:27:22
您是否可以尝试如下:将@RequestBody添加到dto中:
@GetMapping("/test")
public TestOutputDTO getSchedule(@Valid @RequestBody TestInputDTO dto, BindingResult bindingResult) throws JusException {
...
}如果它仍然不起作用,通过编写单元测试来测试您的Jackson映射,并查看结果。
@Test
public void testMapping(){
TestInputDto testInput = new TestInputDto();
testInputDto.setTestId(1L);
assertEquals("{ \"test_id\" : 1}", objectMapper.writeValueAsString(testInputDto));
}https://stackoverflow.com/questions/51489304
复制相似问题