- spring.xml文件
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- <span style="white-space:pre;"> </span>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
- <span style="white-space:pre;"> </span>xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
- <span style="white-space:pre;"> </span>xsi:schemaLocation="
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/beans
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/beans/spring-beans.xsd
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/context
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/context/spring-context.xsd
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/tx
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/tx/spring-tx.xsd
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/aop
- <span style="white-space:pre;"> </span>http://www.springframework.org/schema/aop/spring-aop.xsd
- <span style="white-space:pre;"> </span>">
- <span style="white-space:pre;"> </span>
- <span style="white-space:pre;"> </span><bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
- <span style="white-space:pre;"> </span><property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
- <span style="white-space:pre;"> </span><property name="url" value="jdbc:mysql://127.0.0.1:3306/springboot"></property>
- <span style="white-space:pre;"> </span><property name="username" value="root"></property>
- <span style="white-space:pre;"> </span><property name="password" value="root"></property>
- <span style="white-space:pre;"> </span></bean>
- <span style="white-space:pre;"> </span><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <span style="white-space:pre;"> </span><property name="dataSource" ref="dataSource" />
- <span style="white-space:pre;"> </span><property name="mapperLocations" value="classpath:com/xinxin/mapper/*.xml"></property>
- <span style="white-space:pre;"> </span></bean>
- <span style="white-space:pre;"> </span><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <span style="white-space:pre;"> </span><property name="basePackage" value="com.xinxin.mapper" />
- <span style="white-space:pre;"> </span><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
- <span style="white-space:pre;"> </span></bean>
- </beans>
- springMVC.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
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc.xsd
- ">
- <context:component-scan base-package="com.xinxin"></context:component-scan>
- <mvc:annotation-driven />
- </beans>
- application.properties
- spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8
- spring.datasource.username=root
- spring.datasource.password=root
- spring.mvc.view.prefix=/jsp/
- spring.mvc.view.suffix=.jsp
- logging.level.com.bw.dao=debug
- mybatis.mapper-locations=classpath:com/xinxin/mapper/*.xml
- 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>com.xinxin</groupId>
- <artifactId>xinxin</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>shengchengqi</name>
- <description>Demo project for Spring Boot</description>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.1.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>1.3.2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper-spring-boot-starter</artifactId>
- <version>1.2.3</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
- 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_2_5.xsd" id="WebApp_ID" version="2.5">
- <display-name>springmvc-01</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:spring-redis.xml,classpath:spring-mongo.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>
- <!-- 默認找 /WEB-INF/[servlet的名稱]-servlet.xml -->
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:springmvc.xml</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>springmvc</servlet-name>
- <!--
- 1. /* 攔截所有 jsp js png .css 真的全攔截 建議不使用
- 2. *.action *.do 攔截以do action 結尾的請求 肯定能使用 ERP
- 3. / 攔截所有 (不包括jsp) (包含.js .png.css) 強烈建議使用 前臺 面向消費者 www.jd.com/search /對靜態資源放行
- -->
- <url-pattern>*.action</url-pattern>
- </servlet-mapping>
- <!-- 過濾器 -->
- <filter>
- <filter-name>myfilter</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>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>myfilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
- mapper.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.xinxin.mapper.ITableMapper">
- </mapper>