You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Spring MVC构建WebService时Get请求返回空参数问题排查

Troubleshooting Empty Parameters in Your Spring MVC WebService GET Request

Hey there, let's figure out why your GET request is returning empty parameters for your Spring MVC WebService. Based on the code snippets you shared, here are the most common issues to check and fix:

1. Verify Controller Request Mapping & Parameter Binding

Your controller code is cut off, but the first thing to confirm is that your request handling method correctly maps the GET request and binds parameters properly:

  • Make sure you're using @GetMapping (or @RequestMapping(method = RequestMethod.GET)) on your controller method.
  • Use the right annotation for your parameter type:
    • For path variables (e.g., http://your-api/adtab/123/456), use @PathVariable:
      @GetMapping("/adtab/{window_ID}/{tab_ID}")
      public ResponseEntity<VO> fetchADTab(
          @PathVariable("window_ID") String windowId,
          @PathVariable("tab_ID") String tabId
      ) throws CompiereAPIApplicationException {
          VO tabData = adTabService.read(windowId, tabId);
          return ResponseEntity.ok(tabData);
      }
      
    • For query parameters (e.g., http://your-api/adtab?window_ID=123&tab_ID=456), use @RequestParam (ensure the name matches your request parameter exactly, including case):
      @GetMapping("/adtab")
      public ResponseEntity<VO> fetchADTab(
          @RequestParam(name = "window_ID") String windowId,
          @RequestParam(name = "tab_ID") String tabId
      ) throws CompiereAPIApplicationException {
          VO tabData = adTabService.read(windowId, tabId);
          return ResponseEntity.ok(tabData);
      }
      

2. Check Your BaseWs Base Class Logic

Since your ADTabWs extends BaseWs<IADTabS..., confirm the base class isn't interfering with parameter binding:

  • Ensure the base class doesn't override Spring MVC's default parameter handling (e.g., custom request interceptors or parameter parsing that drops values).
  • Verify that any shared logic in BaseWs correctly passes parameters down to your service methods.

3. Validate Parameter Flow to Your Service

Add debug logs in your controller to confirm if parameters are even reaching the controller layer:

@GetMapping("/adtab")
public ResponseEntity<VO> fetchADTab(
    @RequestParam(name = "window_ID") String windowId,
    @RequestParam(name = "tab_ID") String tabId
) throws CompiereAPIApplicationException {
    // Log to check if parameters are received
    System.out.println("Received window_ID: " + windowId + ", tab_ID: " + tabId);
    VO tabData = adTabService.read(windowId, tabId);
    return ResponseEntity.ok(tabData);
}
  • If logs show empty values here: The issue is with parameter binding (go back to point 1).
  • If logs show valid values but the response is empty: The problem is in your read service method (check if it's returning a null/empty VO).

4. Ensure Proper Serialization of Your VO Class

If your service returns a valid VO but the response is empty, Jackson (Spring's default serializer) might not be able to process the VO class:

  • Add a public no-arg constructor to your VO class (Jackson requires this to instantiate objects).
  • Add public getter methods for all fields you want to include in the response, or use @JsonProperty on private/protected fields to explicitly mark them for serialization.

5. Confirm Request Format Correctness

Double-check your GET request matches the expected format:

  • For path variables: Ensure the URL uses the exact path structure your @GetMapping defines (e.g., /adtab/10000/20000).
  • For query parameters: Ensure parameter names match exactly (HTTP query params are case-sensitive, so window_ID != window_id).

内容的提问来源于stack exchange,提问作者zebiri djallil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:45:44