yadianna 发表于 2017-2-28 09:27:37

IntelliJ IDEA上创建maven Spring MVC项目

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>  <beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
  xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot;
  xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.2.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc.xsd&quot;>
  <!--启用spring的一些annotation -->
  <context:annotation-config/>
  <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
  <context:component-scan base-package=&quot;com.zjut.ssm.controller&quot;>
  <context:include-filter type=&quot;annotation&quot; expression=&quot;org.springframework.stereotype.Controller&quot;/>
  </context:component-scan>
  <!--HandlerMapping 无需配置,springmvc可以默认启动-->
  <!--静态资源映射-->
  <!--本项目把静态资源放在了WEB-INF的statics目录下,资源映射如下-->
  <mvc:resources mapping=&quot;/css/**&quot; location=&quot;/WEB-INF/statics/css/&quot;/>
  <mvc:resources mapping=&quot;/js/**&quot; location=&quot;/WEB-INF/statics/js/&quot;/>
  <mvc:resources mapping=&quot;/image/**&quot; location=&quot;/WEB-INF/statics/image/&quot;/>
  <!--但是项目部署到linux下发现WEB-INF的静态资源会出现无法解析的情况,但是本地tomcat访问正常,因此建议还是直接把静态资源放在webapp的statics下,映射配置如下-->
  <!--<mvc:resources mapping=&quot;/css/**&quot; location=&quot;/statics/css/&quot;/>-->
  <!--<mvc:resources mapping=&quot;/js/**&quot; location=&quot;/statics/js/&quot;/>-->
  <!--<mvc:resources mapping=&quot;/image/**&quot; location=&quot;/statics/images/&quot;/>-->
  <!-- 配置注解驱动 可以将request参数与绑定到controller参数上 -->
  <mvc:annotation-driven/>
  <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀(如果最后一个还是表示文件夹,则最后的斜杠不要漏了) 使用JSP-->
  <!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- -->

  <bean>  <property name=&quot;viewClass&quot; value=&quot;org.springframework.web.servlet.view.JstlView&quot;/>
  <property name=&quot;prefix&quot; value=&quot;/WEB-INF/views/&quot;/><!--设置JSP文件的目录位置-->
  <property name=&quot;suffix&quot; value=&quot;.jsp&quot;/>
  </bean>
  <!-- springmvc文件上传需要配置的节点-->

  <bean>  <property name=&quot;maxUploadSize&quot; value=&quot;20971500&quot;/>
  <property name=&quot;defaultEncoding&quot; value=&quot;UTF-8&quot;/>
  <property name=&quot;resolveLazily&quot; value=&quot;true&quot;/>
  </bean>
  </beans>
页: [1]
查看完整版本: IntelliJ IDEA上创建maven Spring MVC项目