2020暑假项目-车辆派遣管理系统开发记录#1
2020暑假项目-车辆派遣管理系统开发记录#1
- 1、今日搭建SSM框架,
- 使用maven进行项目资源管理 - 2、核心源码
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>user/toLogin</welcome-file>
</welcome-file-list>
<!-- log4j -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!--编码过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class> </listener> -->
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/view/404.jsp</location>
</error-page>
</web-app>
spring-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- 配置springmvc -->
<!-- 1、开启springMvc注解模式 -->
<mvc:default-servlet-handler />
<mvc:annotation-driven />
<context:component-scan base-package="com.vdm.action" />
<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 资源文件过滤 -->
<mvc:resources location="/" mapping="/**/*.js" />
<mvc:resources location="/" mapping="/**/*.css" />
<mvc:resources location="/layui/" mapping="/layui/**" />
<!-- 自定义拦截器 -->
<mvc:interceptors>
<!-- 用户登录拦截器 -->
<mvc:interceptor>
<!-- 拦截所有的请求,这个必须写在前面,也就是写在【不拦截】的上面 -->
<mvc:mapping path="/**" />
<!-- 但是排除下面这些,也就是不拦截请求 -->
<mvc:exclude-mapping path="/user/*" />
<mvc:exclude-mapping path="/verifycode/*" />
<mvc:exclude-mapping path="/**/*.css" />
<mvc:exclude-mapping path="/**/*.js" />
<mvc:exclude-mapping path="/**/*.png" />
<mvc:exclude-mapping path="/**/*.img" />
<mvc:exclude-mapping path="/**/*.gif" />
<mvc:exclude-mapping path="/layui/**" />
</mvc:interceptor>
</mvc:interceptors>
<!-- 上传文件 -->
<bean name="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
<!-- JSON 处理 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<!-- <value>application/json;charset=UTF-8</value> -->
<!-- <value>text/html;charset=UTF-8</value> -->
<value>text/json;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" />
<bean
class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean
class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
<bean
class="org.springframework.http.converter.ResourceHttpMessageConverter"></bean>
<bean
class="org.springframework.http.converter.ByteArrayHttpMessageConverter"></bean>
<bean
class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"></bean>
<bean
class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"></bean>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
<!-- JSON转换器 -->
</list>
</property>
</bean>
</beans>
-
3、遇到的问题
- 3.1、配置spring.xml时头文件出现 cvc-elt.1: Cannot find the declaration of element 'beans'. 报错信息,
eg : http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd - 3.2、利用mybatis-generator自动生成代码,发生:Plugin execution not covered by lifecycle configuration 报错
- 3.1、配置spring.xml时头文件出现 cvc-elt.1: Cannot find the declaration of element 'beans'. 报错信息,
-
4、解决问题
- 4.1、解决配置文件报错,在pom中找到自己对应配置的spring相关包版本信息,在spring.xml的头文件中,把对应的地址改为和版本号一致的内容
eg : http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.14.xsd - 4.2、解决方案,在plugins标签的上级添加 pluginManagement标签
- 4.1、解决配置文件报错,在pom中找到自己对应配置的spring相关包版本信息,在spring.xml的头文件中,把对应的地址改为和版本号一致的内容