@JsonProperty(“ test_id”)在springboot @GetMapping中不起作用

时间:2018-07-24 01:46:26

标签: spring-boot jackson

我的控制器代码如下:

6 / (0 + 2)

TestInputDTO定义如下:

Option Explicit

Public Sub SaveAsXLS()
Dim wb As Workbook
Dim sh As Worksheet
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
Dim nameWB As String

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual

'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)

With FldrPicker
  .Title = "Select A Target Folder"
  .AllowMultiSelect = False
    If .Show <> -1 Then GoTo NextCode
    myPath = .SelectedItems(1) & "\"
End With

NextCode:
myPath = myPath
If myPath = "" Then Exit Sub

'Target File Extension (must include wildcard "*")
myExtension = "*.xlsb*"

myFile = Dir(myPath & myExtension)

'Loop through each Excel file in folder
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
Call DetermineNonBuiltinCommandBars
nameWB = Replace(myFile, ".xlsb", "")
ActiveWorkbook.SaveAs Filename:=nameWB, FileFormat:=xls <---- ERROR
ActiveWorkbook.Close savechanges:=False

myFile = Dir
Loop
End Sub

http://localhost:8866/test?test_id=1无效,testId为null。

http://localhost:8866/test?testId=1作品

我想通过 test_id 样式调用此api。

我该怎么办?

Thakns。

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:将@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));
}