我正在開發一個簡單的應用程序在春天mvc沒有使用春天形式標籤,目前我的工作是通過使用下面的代碼,但爲了理解目的我問這個問題。 我有兩個支持豆類,我已經綁定到一個html <form>
標籤,這在spring form標籤中是不可能的。提交表單與彈出窗體標籤
豆1
public class Interim {
private int interimId;
private BigDecimal amount;
private int interimCategory;
// setter n getter
}
豆2
public class Bcr {
private int bcrId;
private BigDecimal cashAmount;
private int interimCategory;
}
HTML表單
<form action="/interim" method="get">
<input type="text" name="amount" />
<input type="text" name="cashAmount" />
<input type="text" name="interimCategory" />
<button type="submit" name="Month" > month </button>
</from>
春天控制器
@Controller
public TestController {
@RequestMapping(value = "/interim", method = RequestMethod.GET)
public String interimInit(ModelMap map) {
map.addAttribute("interim",new Interim());
map.addAttribute("bcr",new Bcr());
return "interim";
}
/// on form submit
@RequestMapping(value = "/interim", method = RequestMethod.GET, params = "Month")
public String getMonthlyInterim(@ModelAttribute("bcr") Bcr b,ModelMap
modelMap,@ModelAttribute("interim") Interim in) {
}
當我提交表單的Spring MVC兩種豆類設置interimCategory,
- 如何分辨春天不要設置的Bcr豆interimCategory?
- 這是在春季創建html表單的好方法嗎?
您在窗體上使用POST方法,但是,您的控制器上只有GET方法 –
ops編輯,謝謝;-) –
您對窗體的操作是「/ test」,但您沒有方法與RequestMethod的「/測試」 –