67,515
社区成员
发帖
与我相关
我的任务
分享
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value="/add")
@ResponseBody
public String addUser(HttpServletRequest request,User user) {
userService.addUser(user);
request.setAttribute("user",user);
return "hello";
}
}
<!-- 注解探测器 -->
<context:component-scan base-package="com.springapp.mvc" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 使用JSP页面进行输出 -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- 这个配置是配置JSP页面的位置 -->
<property name="prefix" value="/WEB-INF/"/>
<!-- 指定了表示层的后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="conversionService"
class="com.springapp.mvc.common.springmvc.IdentityToEntityConversionServiceFactoryBean" />
<!--配置spirngMVC-web的静态资源,不配会当成控制器-->
<mvc:resources mapping="/assets/**" location="assets/"/>
<mvc:resources mapping="/codefans.net/**" location="codefans.net/"/>
<mvc:resources mapping="/Css/**" location="Css/"/>
<mvc:resources mapping="/font/**" location="codefans.net/"/>
<mvc:resources mapping="/Images/**" location="Images/"/>
<mvc:resources mapping="/Js/**" location="Js/"/>
<mvc:resources mapping="/Menu/**" location="Menu/"/>
<mvc:resources mapping="/Node/**" location="Node/"/>
<mvc:resources mapping="/pages/**" location="pages/"/>
<mvc:resources mapping="/Public/**" location="Public/"/>
<mvc:resources mapping="/Role/**" location="Role/"/>
<mvc:resources mapping="/User/**" location="User/"/>
<!-- 处理文件上传处理 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="UTF-8"/>
</beans>
<!--配置spirngMVC-web的静态资源,不配会当成控制器-->
<mvc:resources mapping="/assets/**" location="assets/"/>
<mvc:resources mapping="/codefans.net/**" location="codefans.net/"/>
<mvc:resources mapping="/Css/**" location="Css/"/>
<mvc:resources mapping="/font/**" location="codefans.net/"/>
<mvc:resources mapping="/Images/**" location="Images/"/>
<mvc:resources mapping="/Js/**" location="Js/"/>
<mvc:resources mapping="/Menu/**" location="Menu/"/>
<mvc:resources mapping="/Node/**" location="Node/"/>
<mvc:resources mapping="/pages/**" location="pages/"/>
<mvc:resources mapping="/Public/**" location="Public/"/>
<mvc:resources mapping="/Role/**" location="Role/"/>
<mvc:resources mapping="/User/**" location="User/"/>
注释掉这一部分就可以了。。。但不知道原因
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<display-name>Spring MVC Application</display-name>
<!-- 设置Spring容器加载配置文件路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-context.xml</param-value>
</context-param>
<!-- 配置Spring核心控制器 -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:mvc-*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>aaa.jsp</welcome-file>
</welcome-file-list>
</web-app>