我有一個使用 Content-Type: application/x-www-form-urlencoded呼叫我的應用程式的 POST 請求。
表單資料負載為: [email protected]&my-token=dBq26TVjg5jy8Q4kUYyZ2DQ
我需要將這 2 個引數映射到 Java 物件中:
public class MyRequest{
private String username;
private String myToken;
//getters setters
}
我的控制器是:
@RequestMapping(value = "user/request", method = RequestMethod.POST)
public String request(@ModelAttribute(value = "myRequest") MyRequest myRequest,
Model model, RedirectAttributes redirectAttributes)
我看到用戶名正在填充,但 myToken 沒有。
我不能使用 @JsonProperty("my-token") 因為它不是 json,還有什么辦法可以獲取令牌?
uj5u.com熱心網友回復:
不是將值分配給物件,而是首先將值存盤在字串物件中,然后將其存盤到物件中。
public String request(@RequestParam("username") String username,@RequestParam("my-token") String myToken,
Model model, RedirectAttributes redirectAttributes)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/461379.html
