2017-08-09 34 views
-3

在Spring項目中,無論控制器上的requestparam是否錯誤,我都會得到400錯誤。在spring項目中,我得到了400錯誤

這是我的代碼。

@RequestMapping("theater_delTheater.do") 
public String theater_updateTheater(@RequestParam int idx){ 
    theaterService.delTheater(Integer.parseInt(idx)); 
    return "/insang/test"; 
} 

IDX在requestparam是數值型,是在電影院電影唯一代碼。

+3

那麼,你想要什麼?你有什麼問題? – Teo

+1

顯示請求代碼(來自前端),或向我們顯示您使用的url。 – Optio

回答

0

你的問題沒有多大意義......

status code definitions 400錯誤代碼據指

請求不能被服務器因爲語法錯誤的理解。客戶端不應該在沒有修改的情況下重複請求。

而這正是你的問題

說什麼,我得到400錯誤的requestparam是否是錯誤的控制器上。

這意味着當您的requestparam錯誤時,您的方法無法解析請求。

所以解決方法非常簡單:避免用錯誤的requestparam發出請求(您可以通過在控制器發出請求之前驗證requestparam來完成)。

0

使用@ResponseMapping添加@ResponseBody註釋。

@RequestMapping("theater_delTheater.do") 
@ResponseBody 
public String theater_updateTheater(@RequestParam int idx) { 
    theaterService.delTheater(Integer.parseInt(idx)); 
    return "/insang/test"; 
} 
+1

不,@ResponseBody - 允許身體響應,例如與JSON,但有問題有返回視圖(頁面的名稱) – Optio

相關問題