我有我的控制器的一個問題,它沒有處理URL時,它應該是,這裏是代碼:春天沒有檢測到我@pathvariable
@RequestMapping(value = "seeRoom/{user}/{id}")
public String getSeeMessage(@PathVariable("user") String user, @PathVariable("id") int id, Model model) {
System.out.println(id);
return "room";
}
這裏是網絡。 XML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>mif03</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myApp</servlet-name>
<url-pattern>/backoffice</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mif03</servlet-name>
<url-pattern>/users</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>myApp</servlet-name>
<url-pattern>/seeRoom/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/myApp-servlet.xml</param-value>
</context-param>
</web-app>
這裏是myApp.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="controller" />
<context:component-scan base-package="model" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
和我的日食給我這個當我嘗試訪問該頁面:
WARNING: No mapping found for HTTP request with URI [/my-webapp/seeRoom/admin/0] in DispatcherServlet with name 'myApp'
靜態處理,做工精細,但它看起來像春天沒有檢測到我@PathVariable
你爲什麼認爲它應該? –
[PathVariable in Spring Controller]可能的重複(http://stackoverflow.com/questions/9077831/pathvariable-in-spring-controller) – arseniyandru
或者,您覺得'@ PathVariable'與警告相關嗎?收到? –