1.环境和工具
Idea 2019、Tomcat 8、Jdk 8
2.新建spring MVC项目
打开idea,新建项目,选择springMVC->next:填写项目名、路径->finish完成创建
3.项目属性配置
文件(file)->项目结构:检查sdk、模块设置是否正确。
4.运行调试配置
Add configration
点击“+”号,选择tomcat->local
sserver信息填写
Deploymet页选择对应模块,保存
5.引入MyBatis框架
右键项目名->添加框架支持->maven
在生成的pom.xml中添加需要的依赖设置。
此处给出我常用的依赖配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>MySpMvcSqlsrv</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 打包的机制,如pom,jar, maven-plugin, ejb, war, ear, rar, par,默认为jar -->
<packaging>jar</packaging>
<!-- 定义本项目的依赖关系 -->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- mybatis版本号 -->
<spring.version>4.0.9.RELEASE</spring.version>
<!-- mybatis版本号 -->
<mybatis.version>3.3.0</mybatis.version>
<!-- log4j日志文件管理包版本 -->
<!-- <slf4j.version>1.7.7</slf4j.version>-->
<!-- <log4j.version>1.2.16</log4j.version>-->
<cxf.version>3.3.0</cxf.version>
<springfox.version>2.8.0</springfox.version>
<jackson.version>2.10.0</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- json依赖-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- jackson-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- fileupload-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5</version>
</dependency>
<!-- 下面五个依赖为ueditor的依赖-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<dependency>
<groupId>cn.bestwu</groupId>
<artifactId>ueditor</artifactId>
<version>1.1.3.1</version>
</dependency>
</dependencies>
</project>
如需修改本地Maven仓库路径,可再项目设置里修改
点击Import change 至其依赖下载完成
还要做一个操作,就是把它同步到输出目录:项目结构->
6.数据库映射相关文件:dao、entity、service、mapper
USERSDAO.java
package com.My.dao;
import com.My.entity.USERS;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface USERSDao {
int add(USERS m);
int delete(String v);
USERS getMod(String v);
int update(USERS m);
USERS getModBySql(String sql);
List<USERS> getListBySql(String sql);
int getCountBySql(String sql);
}
USERS.java
package com.My.entity;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
public class USERS {
private String ACCOUNT;
public String getACCOUNT(){return this.ACCOUNT;}
public void setACCOUNT(String ACCOUNT){this.ACCOUNT=ACCOUNT;}
private String PASSWORD;
public String getPASSWORD(){return this.PASSWORD;}
public void setPASSWORD(String PASSWORD){this.PASSWORD=PASSWORD;}
private String NAME;
public String getNAME(){return this.NAME;}
public void setNAME(String NAME){this.NAME=NAME;}
private String TEL;
public String getTEL(){return this.TEL;}
public void setTEL(String TEL){this.TEL=TEL;}
private String QQ;
public String getQQ(){return this.QQ;}
public void setQQ(String QQ){this.QQ=QQ;}
private String EMAIL;
public String getEMAIL(){return this.EMAIL;}
public void setEMAIL(String EMAIL){this.EMAIL=EMAIL;}
private String IDCARD;
public String getIDCARD(){return this.IDCARD;}
public void setIDCARD(String IDCARD){this.IDCARD=IDCARD;}
private int STUT;
public int getSTUT(){return this.STUT;}
public void setSTUT(int STUT){this.STUT=STUT;}
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date ADDTIME;
public Date getADDTIME(){return this.ADDTIME;}
public void setADDTIME(Date ADDTIME){this.ADDTIME=ADDTIME;}
private BigDecimal MONEY;
public BigDecimal getMONEY(){return this.MONEY;}
public void setMONEY(BigDecimal MONEY){this.MONEY=MONEY;}
private String PHOTOPATH;
public String getPHOTOPATH(){return this.PHOTOPATH;}
public void setPHOTOPATH(String PHOTOPATH){this.PHOTOPATH=PHOTOPATH;}
private String ID;
public String getID(){return this.ID;}
public void setID(String ID){this.ID=ID;}
private String TIP;
public String getTIP(){return this.TIP;}
public void setTIP(String TIP){this.TIP=TIP;}
private String DEPARTID;
public String getDEPARTID(){return this.DEPARTID;}
public void setDEPARTID(String DEPARTID){this.DEPARTID=DEPARTID;}
public USERS (){}
}
BASESRV.java
package com.My.service;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:spring/spring-mybatis.xml"})
public class BaseSrv {
}
USERrV.java
package com.My.service;
import com.My.dao.USERSDao;
import com.My.entity.USERS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class USERSSrv extends BaseSrv {
@Autowired
private USERSDao usersDao;
public int add(USERS m){return usersDao.add(m);}
public int delete(String v){return usersDao.delete(v);}
public USERS getMod(String v){return usersDao.getMod(v);}
public int update(USERS m){return usersDao.update(m);}
public USERS getModBySql(String sql){return usersDao.getModBySql(sql);}
public List<USERS> getListBySql(String sql){return usersDao.getListBySql(sql);}
public int getCountBySql(String sql){return usersDao.getCountBySql(sql);}
public List<USERS> getListBySqlPage(String sql,int page,int pageSize){
List<USERS> r=usersDao.getListBySql(sql);
int pged = page*pageSize;
if(pged>r.size()){pged = r.size();}
return r.subList((page-1)*pageSize,pged);
}
}
USERSDAO.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.My.dao.USERSDao">
<insert id="add" parameterType="com.My.entity.USERS">
insert into USERS(ACCOUNT,PASSWORD,NAME,SEX,TEL,QQ,EMAIL,IDCARD,STUT,ADDTIME,MONEY,PHOTOPATH,ID,TIP,DEPARTID) values(#{ACCOUNT},#{PASSWORD},#{NAME},#{SEX},#{TEL},#{QQ},#{EMAIL},#{IDCARD},#{STUT},#{ADDTIME},#{MONEY},#{PHOTOPATH},#{ID},#{TIP},#{DEPARTID})
</insert>
<delete id="delete" parameterType="String">
delete FROM USERS WHERE ID = #{ID}
</delete>
<select id="getMod" resultType="com.My.entity.USERS" parameterType="String">
SELECT * FROM USERS WHERE ID = #{ID}
</select>
<update id="update" parameterType="com.My.entity.USERS">
update USERS set ACCOUNT=#{ACCOUNT},PASSWORD=#{PASSWORD},NAME=#{NAME},SEX=#{SEX},TEL=#{TEL},QQ=#{QQ},EMAIL=#{EMAIL},IDCARD=#{IDCARD},STUT=#{STUT},ADDTIME=#{ADDTIME},MONEY=#{MONEY},PHOTOPATH=#{PHOTOPATH},TIP=#{TIP},DEPARTID=#{DEPARTID} WHERE ID = #{ID}
</update>
<select id="getModBySql" resultType="com.My.entity.USERS" parameterType="String">
${_parameter}
</select>
<select id="getListBySql" resultType="com.My.entity.USERS" parameterType="String">
${_parameter}
</select>
<select id="getCountBySql" resultType="int" parameterType="String">
${_parameter}
</select>
</mapper>
7.框架用到的配置文件
Spring-cxf.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<!-- <jaxws:endpoint-->
<!-- id="reportEntity"-->
<!-- implementor="com.My.serviceWebService.MyWebService"-->
<!-- address="/MyServiceService"></jaxws:endpoint>-->
</beans>
Spring-mvc.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/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!--控制器路径-->
<context:component-scan base-package="com.My.Control"/>
<!--配置器处理器映射器,配置处理器适配器-->
<mvc:annotation-driven/>
<!-- 放行所有的静态资源文件-->
<mvc:default-servlet-handler/>
<!-- 静态资源文件-->
<!-- <mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/>-->
<!-- <mvc:resources mapping="/img/**" location="/img/" cache-period="31556926"/>-->
<!-- <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/>-->
<!-- <mvc:resources mapping="/photos/**" location="/photos/" cache-period="31556926"/>-->
<!-- <mvc:resources mapping="/upload/**" location="/upload/" cache-period="31556926"/>-->
<!--指定视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 视图的路径 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!-- 视图名称后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
<!--配置拦截器-->
<mvc:interceptors>
<!--登录拦截器-->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.My.aInterceptor.LoginInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
<!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 默认编码 -->
<property name="defaultEncoding" value="UTF-8" />
<!-- 文件大小最大值 -->
<property name="maxUploadSize" value="10485760000" />
<!-- 内存中的最大值 -->
<property name="maxInMemorySize" value="40960" />
</bean>
</beans>
Spring-mabatis.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 扫描包下所有使用注解的类型 -->
<context:component-scan base-package="com.My" />
<!-- 引入配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 配置连接池属性 -->
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- c3p0连接池的私有属性 -->
<property name="maxIdleTime" value="900"></property>
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!-- 关闭连接后不自动commit -->
<property name="autoCommitOnClose" value="false"/>
<!-- 获取连接超时时间 -->
<property name="checkoutTimeout" value="30000"/>
<!-- 当获取连接失败重试次数 -->
<property name="acquireRetryAttempts" value="2"/>
</bean>
<!-- 3.配置SqlSessionFactory对象 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据库连接池 -->
<property name="dataSource" ref="dataSource"/>
<!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!-- 扫描entity包 使用别名 -->
<property name="typeAliasesPackage" value="com.My.entity"/>
<!-- 扫描sql配置文件:mapper需要的xml文件 -->
<!-- <property name="mapperLocations" value="classpath:mapper/*.xml"/>-->
<!-- <property name="mapperLocations" value="classpath:mapperOrcl/*.xml" />-->
<property name="mapperLocations" value="classpath:mapper/*.xml" />
</bean>
<!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 给出需要扫描Dao接口包 -->
<property name="basePackage" value="com.My.dao"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入数据库连接池 -->
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 配置基于注解的声明式事务 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" />-->
</beans>
Jdbc.properties
#--mysql
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://49.235.49.55:3306/liu?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
#jdbc.username=root
#jdbc.password=ylkj.123
#jdbc.driverLocation=D:/IDEA_2019/Maven_storage/repository/mysql/mysql-connector-java/8.0.18/mysql-connector-java-8.0.18.jar
#--oracle
#jdbc.driver=oracle.jdbc.OracleDriver
#jdbc.url=jdbc:oracle:thin:@localhost:1521:orclx
#jdbc.username=liu
#jdbc.password=liu123
#jdbc.driverLocation=D:/IDEA_2019/Maven_storage/repository/oracle/ojdbc/14/ojdbc-14.jar
#--sqlServer
jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://localhost:1433; DatabaseName=YLAdm
jdbc.username=sa
jdbc.password=123
#jdbc.driverLocation=D:/IDEA_2019/Maven_storage/repository/com/microsoft/sqlserver/mssql-jdbc/6.4.0.jre8/mssql-jdbc-6.4.0.jre8.jar
Logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are by default assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置全局属性 -->
<settings>
<!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
<setting name="useGeneratedKeys" value="true" />
<!-- 使用列别名替换列名 默认:true -->
<setting name="useColumnLabel" value="true" />
<!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} -->
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>
8.Control类
Index.java
package com.My.Control;
import com.My.aHellper.MyBasePage;
import com.My.entity.USERS;
import com.My.service.USERSSrv;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("/")
public class Index {
@Resource
private USERSSrv usersrv;
@RequestMapping("/")
public ModelAndView index(HttpServletRequest request) {
USERS lu = new MyBasePage().getAdminfo(request,usersrv);
String sql="";
ModelAndView mav = new ModelAndView();
mav.setViewName("index");//跳转新的页面名称
mav.addObject("lu",lu);
return mav;
}
}
9.Jsp页面
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>首页</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/my.css?a=1" type="text/css">
<script src="${pageContext.request.contextPath}/js/jquery-1.11.2.min.js"></script>
<script src="${pageContext.request.contextPath}/js/my.js?a=4" type="text/javascript" language="JavaScript" charset="UTF-8"></script>
<script>
</script>
</head>
<body style="padding: 10px;">
<div style="width: 100%;text-align: center;font-size: 28px;color: #666;margin: 20px 0;">欢迎光临。</div>
<table class="myTb" frame="none" rules="none" style="width: 100%;border-spacing: 0;border-bottom: solid 2px #666;">
<tr>
<th><a href="${pageContext.request.contextPath}/loginOut">退出</a></th>
</tr>
</table>
</body>
</html>
login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登录</title>
<script src="/js/jquery-1.11.2.min.js"></script>
<script>
$(function () {
//回车事件
document.onkeydown = function(e){
var ev = document.all ? window.event : e;
if (ev.keyCode == 13) {
$("#Btn_login").click();
}
}
});
</script>
</head>
<body style="background:#aaaaff;">
<form action="${pageContext.request.contextPath}/login" method="post">
<table frame="none" rules="none"
style="border-spacing: 0;width: 300px;border: solid 1px #ddd;margin: auto;margin-top:100px;">
<tr style="height: 40px;">
<td align="right" width="100px">用户名:</td>
<td><input type="text" value="admin" autocomplete="off" name="username" style="padding: 4px;"></td>
</tr>
<tr style="height: 40px;">
<td align="right">密码:</td>
<td><input type="password" value="123456" name="password" style="padding: 4px;"></td>
</tr>
<tr style="height: 40px;">
<td align="right"></td>
<td><input id="Btn_login" type="submit" value="登录" style="padding: 4px;"> ${msg}</td>
</tr>
</table>
</form>
</body>
</html>
10.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>人在塔在</display-name>
<!-- Spring和mybatis的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/spring-mybatis.xml
classpath:spring/spring-cxf.xml
</param-value>
</context-param>
<!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- CXF servlet -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservices/*</url-pattern>
</servlet-mapping>
<!-- Spring MVC servlet -->
<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/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 静态资源格式-->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<!--欢迎页-->
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
</web-app>
11.运行调试
标签:jdbc,return,javaWeb,spring,MVC,import,org,public,String From: https://blog.csdn.net/cooluca/article/details/143707002