我想在我的參數傳遞給我的web服務的格式爲:彈簧組默認PathVariable
不是
http://.../greetings?name=neil&id=1
所以我改變了我的代碼(注意,我只在代碼中包含第一個參數):
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
到:
@RequestMapping
public Greeting greeting(@PathVariable String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
它的工作原理,但我不知道如何添加默認值@PathVariable使得例如:
會工作,因爲它用查詢參數。
我該怎麼做?我想也許它會傳遞null,但它只是產生一個頁面錯誤。
我想答案可能是添加多個重載,但這聽起來有點亂。
謝謝。
謝謝。
[Spring MVC中的可能重複:如何指示的路徑變量是否需要與否?](http://stackoverflow.com/questions/17821731/spring-mvc-how-to-indicate-whether-a-path-variable-is-required-or-not) – Arpit