前面使用vue+ElementUI写了一个登录页面,那么现在使用SSM框架写一个登录接口,用于接收前端的用户名和密码并且进行校验。
1、创建一个maven工程
2、在pom.xml文件中把该项目打成war包
3、创建web.xml文件
4、配置tomcat
5、搭建spring+springmvc环境
(1)在pom.xml文件中加入spring整合springmvc的依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
</dependencies>
(2)创建aplicationContext.xml的spring配置文件,配置包扫描
<!-- spring配置文件中只扫描controller-->
<context:component-scan base-package="com.sxt.ytwl" use-default-filters="true">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
(3)创建springmvc的配置文件spring-servlet.xml,配置包扫描,开启注解,配置静态资源过滤等
<!-- springmvc文件中扫描除了controller之外的所有东西-->
<context:component-scan base-package="com.sxt.ytwl" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<mvc:annotation-driven/>
<mvc:resources mapping="/**" location="/"/>
(4)在web.xml中配置spring和springmvc的配置文件以及监听器过滤器等
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-n