我想在春天的mvc做一个宁静的服务。这是我的控制器代码,
@Controller
@RequestMapping("/manageuser")
public class ManageUserController {
@RequestMapping(value = "/deleteuser/{user}", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
protected void deleteUser(@PathVariable String user, ModelMap model) {
System.out.println(user);
}
@RequestMapping(value = "/adduser/{user}", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
protected void addUser(@PathVariable String user, ModelMap model) {
System.out.println(user);
}
}
我的manageuser-servelt.xml
<context:component-scan base-package="com.example.web" use-default-filters="false"
>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
我的web.xml内容,
<servlet>
<servlet-name>manageuser</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:manageuser-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>manageuser</servlet-name>
<url-pattern>/manageuser</url-pattern>
</servlet-mapping>
如果我导航到localhost / manageuser / adduser / Barney,我将获得404。我在这做错了什么?这是使用spring-mvc的RESTful服务的正确方法吗?
答案 0 :(得分:0)
&#34; System.out.println(用户)&#34;显示用户?如果没有,那么您的映射会出现问题。
点击此处查看其他博客:http://www.breathejava.com/restful-web-service-tutorial-spring-xml/。