我需要在現有的基於Spring的Web服務中添加Restful URL。Spring servlet URL映射
每個URL映射良好但點擊URL寧靜如 http://localhost:9090/Mercury/rest/invoice, 畢竟上下文根路徑被改變http://localhost:9090/Mercury/rest
的一點是,我要使用REST風格(/ REST)和*。做網址模式
如何在沒有/休息的情況下設置contextroot路徑?
的web.xml
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
控制器
@Controller
@RequestMapping("/rest")
public class InvoiceController {
@RequestMapping(value="/{name}", method=RequestMethod.GET)
public String getInvoice(@PathVariable String name, Model model) {
model.addAttribute("name", name);
return "rest.body";
}