2011-04-13 45 views
3

如果我多次敲击控制器并敲击它,偶尔我的modelCode参数会变为null。但是,URL中包含modelCode。 使用Spring框架3.0.5.RELEASESpring MVC正在删除@PathVariable

 
@RequestMapping(value="ws/getallvariants/{channelCode}/{modelCode}/{regionId}/{year}") 
    public ModelAndView getAllVariants(@PathVariable("channelCode") String channelCode, 
      @PathVariable("modelCode") String modelCode,@PathVariable("regionId") String regionId,@PathVariable("year") String year){

if (modelCode == null) { int i = 0; // this should never hit, but does. }

+0

你检查的范围为控制器(是不是默认的单身)? – nickdos 2011-04-15 23:11:26

回答

0

再次更新Spring框架的最新版本似乎已经奏效。显然,当我们更新我们的框架时,某些东西无法正常工作。

编辑:

所以这不是我们的问题在所有...我们已经建立了一个字符串微调编辑器使用不当,它是保持状态。所以当我们把这个通话加载时,它会跨越结果。

+0

一年后,问题再次出现。看起来它并没有解决。 – Dilbert789 2012-09-19 17:51:42

+0

这个问题实际上是一个没有正确实现的stringTrimmerEditor。 – Dilbert789 2012-09-20 14:50:36

+0

您是否应该将此延伸至答案/编辑您的答案? – 2012-09-29 13:57:45

1

看看Spring MVC @PathVariable getting truncated。正则表达式的方法为我工作:

@RequestMapping({ "/servers/{serverName:.+}" })

+1

在这种情况下不是问题。参数是2个或3个字母数字字符,无小数。我也看到了regionId现在变为空。 – Dilbert789 2011-04-13 16:38:15

3

是的,RegEx对我来说也是最可靠的。这样做是为了抢一个电子邮件地址作为参数:

@RequestMapping(value = "rest/userreadserv/search/{email:.+}", method = RequestMethod.GET) 
public ResponseEntity getUserAccountByEmail(@PathVariable String email) {...} 
0
//in your xml dispatcher add this property to your default annotation mapper bean as follow 
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"> 
    <property name="alwaysUseFullPath" value="true"></property> 
</bean>  
相关问题