我有一个HTML文件,其中包含货币下拉列表。所选货币的价值应传递给控制人,控制人会根据特定货币(欧元兑换美元)检索当前汇率。
如何将下拉值传递给java控制器。
HTML code:
<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;
}
如何将所选值传递给控制器方法?任何帮助都会非常有用。
我也是这个方法,但我显示&#34;没有消息&#34;
@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;
}
答案 0 :(得分:0)
@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; }