我有一个HTML文件,其中有货币下拉列表。所选货币的值应传递给控制器,控制器检索当前对特定货币的汇率,例如:欧元兑美元。
如何将下拉值传递给 java 控制器。
网页代码:
<form action="/currencyRate?currencyVal=currency" id="currency">
<input type="submit" value="Submit">
</form>
<select name="currencyVal" form="currency">
<option value="USD">USD</option>
<option value="INR">INR</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="AED">AED</option>
</select>
其余控制器方法
@RequestMapping(value="/currencyRate", method=RequestMethod.GET)
public ModelAndView getCurrencyRate(@ModelAttribute String currency) {
ModelAndView modelAndView = new ModelAndView();
double currencyRate = 0;
// does the exchange rate retrieval task.
currencyRate = getCurrencyRateDetail(currency);
modelAndView.addObject("currencyRate", currencyRate);
modelAndView.setViewName("result");
return modelAndView;
}
如何将所选值传递给控制器方法?任何帮助都会非常有帮助。
我也是这个方法,但我它显示"没有消息">
@RequestMapping(value="/currencyRate/{currency}", method=RequestMethod.GET)
public ModelAndView getCurrencyRate(@PathVariable String currency) {
ModelAndView modelAndView = new ModelAndView();
double currencyRate = 0;
currencyRate = getCurrencyRateDetail(currency);
modelAndView.addObject("currencyRate", currencyRate);
modelAndView.setViewName("result");
return modelAndView;
}
@RequestMapping(value="/currencyRate/{currency}", method=RequestMethod.GET) public ModelAndView getCurrencyRate(@PathVariable String currency) { ModelAndView modelAndView = new ModelAndView(); double currencyRate = 0; currencyRate = getCurrencyRateDetail(currency); modelAndView.addObject("currencyRate", currencyRate); modelAndView.setViewName("result"); return modelAndView; }