我正在开发Spring MVC webApp项目,我有点坚持这一步。我有一个JSP页面,当用户点击需要存储的按钮进行购买时,按钮的价值为$ 1.00 .25等。我在控制器中有一个方法,但不确定输入的参数传递什么。请指出正确的方向。谢谢。
<div class="form-group" >
<input class="form-control" style="text-align: center" id="display-money" placeholder="Enter Money" required/> <!--to diplay total -->
</div>
<div class="col-md-6">
<button method="POST"
action="addOne-btn"
value="addOne"
modelAttribute="add-one"
type="button"
name="one"
id="addOne"
class="btn btn-default ">
Add Dollar
</button>
</div>
<div class="col-md-6">
<div class="form-group">
<button method="POST"
value="addQrtr"
action="addQrtr-btn"
type="button"
name="qrtr"
id="addQRTR"
class="btn btn-default">
Add Quarter
</div>
</div>
</div>
-------------------------------------------------------------------
//controller
@RequestMapping(value = "/money", method = RequestMethod.GET)
public String money(HttpServletRequest request, Model model){
BigDecimal moneyIn = new BigDecimal(0);
String input = request.getParameter();//pass in onlcick from jsp.
if(input.equals("addOne")){
moneyIn.add(new BigDecimal(1.00));
}
if(input.equals("")){
moneyIn.add(new BigDecimal(.25));
}
}
答案 0 :(得分:1)
在提交控制器中使用@ModelAttribute。
@RequestMapping(value = "/money", method = RequestMethod.GET)
public String money(HttpServletRequest request, @ModelAttribute Bean bean){
BigDecimal moneyIn = new BigDecimal(0);
String input = bean.get***();//pass in onlcick from jsp.
if(input.equals("addOne")){
moneyIn.add(new BigDecimal(1.00));
}
if(input.equals("")){
moneyIn.add(new BigDecimal(.25));
}
}