我在spring中开发了一个简单的应用程序,没有使用spring表单标签,目前我的工作是使用下面的代码来完成的,但是为了理解这个问题,我正在问这个问题。我有两个beans类,我已经绑定到一个html <form>标记,这在spring标记中是不可能的。
bean 1
public class Interim {
private int interimId;
private BigDecimal amount;
private int interimCategory;
// setter n getter
}bean 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) {
}当我在两个bean中提交spring设置interimCategory的表单时,
发布于 2017-04-12 21:05:44
如果不想使用Spring标记,可以选择使用JQuery Ajax发送表单+使用POST方法在HTTP中发送数据,该的正文将是JSON消息。
然后可以使用@RequestBody注释将json绑定到控制器上的变量。
https://stackoverflow.com/questions/43379226
复制相似问题