我的控制器类是
@RequestMapping(method = RequestMethod.POST, value = "/auditregistry/collectionentry/cid/{cid}/collid/{collid}/colldt/{collectiondate}/amount/{amt}")
public ModelAndView saveManualCollection(@PathVariable("cid") Integer custId, @PathVariable("collid") Integer collRtId, @PathVariable("collectiondate") String dt, **@PathVariable("amt") String amount**) throws Exception
{
debug("amount recieving=="+amount);
我传递给网址的值是
/ auditregistry / collectionentry / CID / 9991 / COLLID / 10 / colldt / 20120726 /量/的 $ 14.55
当我尝试将其打印量打印为“14美元”而不是“14.55美元”时,我该如何打印实际值“$ 14.55”
任何帮助都非常感谢
答案 0 :(得分:6)
将您的RequestMapping更改为
以下@RequestMapping(method = RequestMethod.POST, value = "/auditregistry/collectionentry/cid/{cid}/collid/{collid}/colldt/{collectiondate}/amount/{amt:.*}")
此处的更改已替换为 {amt:。*} ,而非RequestMapping中的 {amt}
答案 1 :(得分:5)
这是因为默认情况下,Spring MVC会在.
之后删除所有内容,并将其视为文件扩展名(例如/file.txt
)。这很容易修复。使用Spring MVC 3.1和Java配置:
@Configuration
class Cfg extends WebMvcConfigurationSupport {
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
final RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
mapping.setUseSuffixPatternMatch(false);
return mapping;
}
}
请注意:RequestMappingHandlerMapping.setUseSuffixPatternMatch()
。