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

.NET Core从SQL Server取数:手动路由跳转首页问题求助

Troubleshooting Your Request Info Controller Issues

Hey there! Let's work through your problem step by step to get your request info query functionality up and running properly.

First: Fixing the Redirect Issue for Manual Route Access

When accessing /api/requestinfo/details/7507373 gets redirected to the homepage, there are a few common culprits to check:

  • Mismatched Route Parameter Names
    Double-check your controller method's route annotation and parameter binding. For example, if you're using Spring Boot, make sure the @PathVariable name matches exactly what's in your route:

    // Correct: Path variable name matches the route placeholder
    @GetMapping("/api/requestinfo/details/{requestId}")
    public ResponseEntity<RequestInfo> getRequestDetails(@PathVariable("requestId") Long requestId) {
        // Fetch data from your DAO and return it
        return ResponseEntity.ok(yourDao.getRequestById(requestId));
    }
    

    If the names don't match, the framework might fail to resolve the method and fall back to a default route (like your homepage).

  • Permission/Interception Rules
    If you're using a security framework (like Spring Security), verify that your /api/requestinfo/details/** path isn't being intercepted and redirected. Check your security configuration to ensure this endpoint is allowed for unauthenticated users (or whatever your access rules require).

  • Global Exception Handling
    If your DAO throws an exception (e.g., request ID not found), check if a global exception handler (@ControllerAdvice) is catching it and redirecting to the homepage. Modify the handler to return an appropriate error response instead of a redirect.

  • Accidental Redirect in Controller
    Double-check your controller method's return value. Make sure you're not accidentally returning return "redirect:/"; instead of returning the fetched data or a proper view.

  • Debug with Browser Dev Tools
    Open your browser's Network tab when making the request. Look at the response status code (it'll be a 3xx for redirects) and check the Location header to confirm where it's sending you. This can clue you into whether it's a security redirect, a route fallback, or something else.

Second: Implementing Form-Based Request ID Lookup

Once the manual route works, adding a form for your support team is straightforward. Here are two approaches:

Option 1: GET Request with Query Parameter

Create a simple HTML form that submits a GET request with the request ID as a query parameter:

<form action="/api/requestinfo/details" method="GET">
  <label for="requestId">请求编号:</label>
  <input type="text" id="requestId" name="requestId" required>
  <button type="submit">查询</button>
</form>

Then update your controller to accept a query parameter:

@GetMapping("/api/requestinfo/details")
public ResponseEntity<RequestInfo> getRequestDetailsByQuery(@RequestParam("requestId") Long requestId) {
    return ResponseEntity.ok(yourDao.getRequestById(requestId));
}

Option 2: Path Variable with JavaScript Handling

If you want to keep the /api/requestinfo/details/{requestId} route structure, use JavaScript to handle form submission and navigate to the correct path:

<form id="requestQueryForm">
  <label for="requestId">请求编号:</label>
  <input type="text" id="requestId" required>
  <button type="submit">查询</button>
</form>

<script>
document.getElementById('requestQueryForm').addEventListener('submit', function(e) {
  e.preventDefault(); // Prevent default form submission
  const requestId = document.getElementById('requestId').value.trim();
  if (requestId) {
    window.location.href = `/api/requestinfo/details/${requestId}`;
  }
});
</script>

This way, the form submission will redirect to the exact route you already tested (once the redirect issue is fixed).

Final Tips

  • Check your backend logs for any error messages related to the request—they'll often tell you exactly why the redirect is happening (e.g., parameter binding errors, security denied exceptions).
  • Test the DAO layer directly first to confirm it returns the correct data for the request ID 7507373—this ensures the issue isn't with data retrieval itself.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:18:10