Tag: path variables

Spring Controller中的PathVariable

我正在尝试映射url/locations/{locationId}/edit.html – 这似乎与此代码一起使用: @Controller @RequestMapping( “/locations” ) public class LocationController { @RequestMapping( value = “/{locationId}/edit.html”, method = RequestMethod.GET ) public String showEditForm( Map map, @PathVariable int locationId ) { map.put( “locationId”, locationId ); return “locationform”; } } 调用提到的url结果会出现exception: java.lang.IllegalArgumentException: Name for argument type [int] not available, and parameter name information not found in class file […]

Spring MVC中有多个@PathVariable

不幸的是找不到答案,所以希望有人可以提供帮助。 在Spring MVC 3.1.0中,这是我的方法: @RequestMapping(value = “/{app}/conf/{fnm}”, method=RequestMethod.GET) public ResponseEntity getConf(@PathVariable String app, @PathVariable String fnm) { log.debug(“AppName:” + app); log.debug(“fName:” + fnm); … return … } 我在网上看到了一些例子,看起来在理论上有多个@PathVariables是没有问题的。 但是,当我这样做时,“app”和“fnm”都包含相同的值(这是分配给“app”的任何值)。 真的很感激有人可能对我出错的地方有任何见解? 谢谢!

如果找不到,@ PathVariable可以返回null吗?

如果路径变量不在url中,是否可以使@PathVariable返回null? 否则我需要做两个处理程序。 一个用于/simple ,另一个用于/simple/{game} ,但两者都做同样的事情,如果没有定义游戏我从列表中选择第一个然而如果有游戏参数定义然后我使用它。 @RequestMapping(value = {“/simple”, “/simple/{game}”}, method = RequestMethod.GET) public ModelAndView gameHandler(@PathVariable(“example”) String example, HttpServletRequest request) { 这是我在尝试打开页面/simple : 引起:java.lang.IllegalStateException:在@RequestMapping中找不到@PathVariable [example]

SpringBoot中的@PathVariable,带有URL中的斜杠

我必须在SpringBoot应用程序中使用@PathValiable从URL获取params。 这些参数常常有斜线 。 我无法控制用户在URL中输入的内容,因此我希望获得他输入的内容然后我可以处理它。 我已经在这里查看了材料和答案,我不认为对我来说好的解决方案是要求用户以某种方式编码输入参数。 SpringBoot代码很简单: @RequestMapping(“/modules/{moduleName}”) @ResponseBody public String moduleStrings (@PathVariable(“moduleName”) String moduleName) throws Exception { … } 所以URL例如如下: http://localhost:3000/modules/… 问题是param moduleName经常有斜杠。 例如, metadata-api\cb-metadata-services OR app-customization-service-impl\\modules\\expand-link-schemes\\common\\app-customization-service-api 因此用户可以定义输入: http://localhost:3000/modules/metadata-api\cb-metadata-services 这可以在/ modules /之后获取用户在URL中输入的所有内容吗? 如果有人告诉我处理此类问题的好方法是什么。

在Spring中将路径变量绑定到自定义模型对象

我有一个模拟我的请求的类,比如 class Venue { private String city; private string place; // Respective getters and setters. } 我想支持一个RESTful URL来获取有关场地的信息。 所以我有这样的控制器方法。 @RequestMapping(value = “/venue/{city}/{place}”, method = “GET”) public String getVenueDetails(@PathVariable(“city”) String city, @PathVariable(“place”) String place, Model model) { // code } 有没有办法,我可以说在spring将我的路径变量绑定到模型对象(在本例中为Venue)而不是获取每个单独的参数?