【分享】标准springMVC+mybatis项目maven搭建最精简教程

文章由来:公司有个实习同学需要做毕业设计,不会搭建环境,我就代劳了,顺便分享给刚入门的小伙伴,我是自学的JAVA,所以我懂的....

(大图直接观看显示很模糊,请在图片上点击右键然后在新窗口打开看)

先看下项目的整体层次结构及说明,本次是用的web3.0,所以需要tomcat8及以上才能运行

再看下用到了哪些jar包,jar包可以说是最精简的了,采用的maven管理

测试:请求地址时,会增加一条数据到数据库,然后读出所有数据,仅供演示,就没再分开了。

我提供了两种方式,一种是返回结果并展示到jsp页面,用到了jstl;另一种就是直接返回的json

先看返回到jsp页面的:

代码如下:

package com.xiaochangwei.web.controller;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.xiaochangwei.web.beans.User;
import com.xiaochangwei.web.service.TestService;

/**
 * @since 2017年1月5日 上午9:33:48
 * @author 肖昌伟 317409898@qq.com
 * @description
 */
@Controller
@RequestMapping("jsp")
public class TestJspController {
	private static final Logger LOGGER = LoggerFactory.getLogger(TestJspController.class);

	@Autowired
	private TestService testService;

	@RequestMapping(value = "user", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView jsp(ModelAndView mv) {
		LOGGER.info("测试增加并返回用户列表到jsp");
		User addUser = new User();
		addUser.setUsername(UUID.randomUUID().toString());
		addUser.setPassword(String.valueOf(System.currentTimeMillis()));
		mv.addObject("users", testService.testAdd(addUser));
		mv.setViewName("userList");
		return mv;
	}
}

再看直接返回json数据的:

代码如下:

package com.xiaochangwei.web.controller;

import java.util.List;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.xiaochangwei.web.beans.User;
import com.xiaochangwei.web.service.TestService;

/**
 * @since 2017年1月5日 上午9:36:53
 * @author 肖昌伟 317409898@qq.com
 * @description
 */
@RestController
@RequestMapping("json")
public class TestJsonController {

	private static final Logger LOGGER = LoggerFactory.getLogger(TestJsonController.class);

	@Autowired
	private TestService testService;

	@RequestMapping(value = "user", method = { RequestMethod.GET, RequestMethod.POST })
	public List<User> json() {
		LOGGER.info("测试增加并返回用户列表到JSON");
		User addUser = new User();
		addUser.setUsername(UUID.randomUUID().toString());
		addUser.setPassword(String.valueOf(System.currentTimeMillis()));
		return testService.testAdd(addUser);
	}
}

其实就只是RestController 和 Controller的区别,查看源码你会发现,其实RestController就是在Controller上面加了一个用于返回JSON的ResponseBody

看看web.xml 由于是采用的web 3.0 所以注意最开始的部分

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>springmvctest</display-name>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/springConfig/applicationContext-*.xml</param-value>
    </context-param>
    
    <!-- 统一编码 -->
    <filter>
        <filter-name>charsetEncoding</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>charsetEncoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- 自动装配配置信息 地址由上面的contextConfigLocation指定 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- 解决java.beans.Introspector导致的内存泄漏的问题 -->
    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
    
    <!-- druid自带的sql操作监控 -->
    <servlet>
        <servlet-name>DruidStatView</servlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>DruidStatView</servlet-name>
        <url-pattern>/druid/*</url-pattern>
    </servlet-mapping>
    
    <!-- 前端控制器 -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 默认加载/WEB-INF/[servlet-name]-servlet.xml,通过下面的contextConfigLocation修改 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:spring-mvc.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

再看看pom文件

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xiaochangwei.web</groupId>
    <artifactId>web-demo</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>web-demo Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
        <compiler.version>1.7</compiler.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        
        <!-- spring 4.3.5-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.5.RELEASE</version>
            <!-- 会自动加载关联的 aop、beans、context、expression、core、commons-logging 这几个jar -->
        </dependency>
        
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.5.RELEASE</version>
        </dependency>
        
        
        <!-- 返回json结果时,如使用了restController或者responseBody -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.8.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.5</version>
            <!-- 会自动加载jackson-annotations -->
        </dependency>
        
        <!-- 文件上传 -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.2</version>
            <!-- 会自动加载commons-io -->
        </dependency>
        
        <!-- 日志记录  -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.22</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.22</version>
            <!-- 会自动加载log4j -->
        </dependency>
        
        
        <!-- 通过mybatis操作mysql数据库 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.3.5.RELEASE</version>
            <!-- 自动加载spring-tx -->
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.27</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.40</version>
        </dependency>
        
        <!-- jsp页面标签 -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        
        <!-- 对象与JSON串相互转换 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.23</version>
        </dependency>
    </dependencies>
    
    <build>
        <finalName>web-demo</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${compiler.version}</source>
                    <target>${compiler.version}</target>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <warName>web-demo</warName>
                    <webResources>
                        <resource>
                            <directory>src/main/resources</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <filtering>true</filtering>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4.1</version>
                <executions>
                    <execution>
                        <id>enforce</id>
                        <configuration>
                            <rules>
                                <dependencyConvergence />
                            </rules>
                        </configuration>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

再看看重要的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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.3.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 
        http://www.springframework.org/schema/task 
        http://www.springframework.org/schema/task/spring-task-4.3.xsd">

    <!-- 扫描路径 -->
    <context:component-scan base-package="com.xiaochangwei.web">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

    <!-- 配置根视图 -->
    <mvc:view-controller path="/" view-name="index" />

    <!-- 激活基于注解的配置 -->
    <mvc:annotation-driven>
        <!-- json返回时默认的转换器,如果不需要返回json結果,可以不用配置 -->
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!-- 静态资源配置 -->
    <mvc:resources location="/assets/" mapping="/assets/**"></mvc:resources>

    <!-- 视图层配置 -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- 文件上传大小限定,如果项目中没有文件上传功能可以不用配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10485760" />
    </bean>
</beans>

如果希望返回的json数据中日期能按照某种格式显示,可以这样配置:

<mvc:annotation-driven>
        <!-- 处理responseBody 里面日期类型 -->  
        <mvc:message-converters>  
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
                <property name="objectMapper">  
                    <bean class="com.fasterxml.jackson.databind.ObjectMapper">  
                        <property name="dateFormat">  
                            <bean class="java.text.SimpleDateFormat">  
                                <constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />  
                            </bean>  
                        </property>  
                    </bean>  
                </property>  
            </bean>  
        </mvc:message-converters>  
    </mvc:annotation-driven>

 上面这样配置是全局的时间格式显示,如果想对某些Date类型的设置其他格式,可以在字段上方增加

@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    private Date lastAccessTime;

继续看数据源的配置、事物、mybatis的扫描路径配置 applicationContext-db.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:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    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">

    <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="url" value="${datasource.read.url}" />
        <property name="username" value="${datasource.read.username}" />
        <property name="password" value="${datasource.read.password}" />
        <property name="initialSize" value="${datasource.initial.size}" />
        <property name="maxActive" value="${datasource.max.size}" />
        <property name="minIdle" value="${datasource.min.idle}" />
        <property name="maxWait" value="60000" />
        <property name="poolPreparedStatements" value="false" />
        <property name="validationQuery" value="${datasource.validation.query}" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
        <property name="testWhileIdle" value="true" />
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <property name="minEvictableIdleTimeMillis" value="300000" />
        <property name="removeAbandoned" value="true" />
        <property name="removeAbandonedTimeout" value="1800" />
        <property name="logAbandoned" value="true" />
        <property name="filters" value="stat" />
        <property name="proxyFilters">
            <list>
                <bean class="com.alibaba.druid.filter.logging.Log4jFilter">
                    <property name="statementExecutableSqlLogEnable" value="true" />
                </bean>
            </list>
        </property>
    </bean>
    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis-config.xml" />
        <property name="mapperLocations">
            <list>
                <value>classpath:mybatisMapper/*.xml</value>
            </list>
        </property>
        <!-- 读写分离插件 -->        
        <!--         <property name="plugins"> -->
        <!--             <array> -->
        <!--                 <bean class="com.xiaochangwei.web.interceptor.MybatisRWSplitInterceptor" /> -->
        <!--             </array> -->
        <!--         </property> -->
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.xiaochangwei.web.dao" />
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
</beans>

资源的加载,单独列出来了,可以合并到一起

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- 加载所有的properties文件 -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:*.properties</value>
            </list>
        </property>
    </bean>
</beans>

mybatis的配置,别名这些扫描等, 不太明白的可以下载mybatis源码下来仔细看看,其实mybatis的实现真的很简单

<?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>
        <setting name="lazyLoadingEnabled" value="false" />
        <setting name="cacheEnabled" value="false" />
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>
    <typeAliases>
        <package name="com.xiaochangwei.web.beans" />
        <package name="com.xiaochangwei.web.vo" />
    </typeAliases>
</configuration>

另外就是jdbc的信息了

#configuration datasource
datasource.read.url=jdbc:mysql://xiaochangwei.com:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
datasource.read.username=root
datasource.read.password=123456

datasource.initial.size=5
datasource.max.size=10
datasource.min.idle=0
datasource.validation.query=select 1

这里需要提醒的是,url后面的编码还有最后的zeroDateTimeBehavior=convertToNull不要写漏了,某些条件下意义非常重大,曾经我负责的项目因为少写了这个出现了异常的  教训

然后就是mapper了

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.xiaochangwei.web.dao.TestDao">
    
    <select id="getAll" resultType="user">
        SELECT id,username,password FROM t_user
    </select>
    
    <insert id="testInsert" parameterType="user" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO t_user(username,password) VALUES (#{username}, #{password})
    </insert>
    
</mapper>

日志配置也顺便贴出来

log4j.rootLogger=INFO,L,stdout,M

log4j.appender.L=org.apache.log4j.DailyRollingFileAppender
log4j.appender.L.File=C:\\xiao-web-demo.log
log4j.appender.L.Append=true
log4j.appender.L.Threshold=INFO
log4j.appender.L.layout=org.apache.log4j.PatternLayout
log4j.appender.L.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ :%c:%L ] - [ %p ] %m%n

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [%c] %m%n

log4j.logger.com.ibatis=INFO
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=INFO
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=INFO
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=INFO
log4j.logger.java.sql.Connection=INFO
log4j.logger.java.sql.Statement=INFO
log4j.logger.java.sql.PreparedStatement=INFO

log4j.logger.druid.sql.Statement=debug,stdout

日志真的很重要,尤其是mybatis的sql相关的,在开发阶段起了很大作用,下面是我本地的日志输出

2017-01-05 13:31:32 INFO [com.xiaochangwei.web.controller.TestJspController] 测试增加并返回用户列表到jsp
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@71fc2ff6] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f68c1b4] will not be managed by Spring
==>  Preparing: INSERT INTO t_user(username,password) VALUES (?, ?) 
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} created. 
INSERT INTO t_user(username,password) VALUES (?, ?)
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} created. 
INSERT INTO t_user(username,password) VALUES (?, ?)
==> Parameters: 8f7ca418-6c71-4a79-9fa4-f2dabb8ec5ed(String), 1483594292079(String)
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} Parameters : [8f7ca418-6c71-4a79-9fa4-f2dabb8ec5ed, 1483594292079]
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} Parameters : [8f7ca418-6c71-4a79-9fa4-f2dabb8ec5ed, 1483594292079]
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} Types : [VARCHAR, VARCHAR]
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} Types : [VARCHAR, VARCHAR]
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} executed. 
INSERT INTO t_user (username, password)
VALUES ('8f7ca418-6c71-4a79-9fa4-f2dabb8ec5ed', '1483594292079')
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} executed. 
INSERT INTO t_user (username, password)
VALUES ('8f7ca418-6c71-4a79-9fa4-f2dabb8ec5ed', '1483594292079')
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} executed. 138.149079 millis. 
INSERT INTO t_user(username,password) VALUES (?, ?)
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} executed. 138.149079 millis. 
INSERT INTO t_user(username,password) VALUES (?, ?)
<==    Updates: 1
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} closed
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20000} closed
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@71fc2ff6]
2017-01-05 13:31:32 INFO [com.xiaochangwei.web.service.impl.TestServiceImpl] 插入用户成功,返回的id为:26
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@48acaa84] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f68c1b4] will not be managed by Spring
==>  Preparing: SELECT id,username,password FROM t_user 
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} created. 
SELECT id,username,password FROM t_user
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} created. 
SELECT id,username,password FROM t_user
==> Parameters: 
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} Parameters : []
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} Parameters : []
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} Types : []
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} Types : []
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} executed. 
SELECT id,username,password FROM t_user
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} executed. 
SELECT id,username,password FROM t_user
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} executed. 0.992148 millis. 
SELECT id,username,password FROM t_user
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} executed. 0.992148 millis. 
SELECT id,username,password FROM t_user
<==    Columns: id, username, password
<==        Row: 1, 肖昌伟, 获取源码请发送邮件到 317409898@qq.com
<==        Row: 26, 8f7ca418-6c71-4a79-9fa4-f2dabb8ec5ed, 1483594292079
<==      Total: 2
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} closed
2017-01-05 13:31:32 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20001} closed
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@48acaa84]
2017-01-05 13:32:36 INFO [com.xiaochangwei.web.controller.TestJsonController] 测试增加并返回用户列表到JSON
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2fd39614] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f68c1b4] will not be managed by Spring
==>  Preparing: INSERT INTO t_user(username,password) VALUES (?, ?) 
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} created. 
INSERT INTO t_user(username,password) VALUES (?, ?)
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} created. 
INSERT INTO t_user(username,password) VALUES (?, ?)
==> Parameters: 9c56119f-86cf-42f6-a509-419bd5ee7578(String), 1483594356817(String)
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} Parameters : [9c56119f-86cf-42f6-a509-419bd5ee7578, 1483594356817]
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} Parameters : [9c56119f-86cf-42f6-a509-419bd5ee7578, 1483594356817]
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} Types : [VARCHAR, VARCHAR]
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} Types : [VARCHAR, VARCHAR]
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} executed. 
INSERT INTO t_user (username, password)
VALUES ('9c56119f-86cf-42f6-a509-419bd5ee7578', '1483594356817')
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} executed. 
INSERT INTO t_user (username, password)
VALUES ('9c56119f-86cf-42f6-a509-419bd5ee7578', '1483594356817')
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} executed. 13.764741 millis. 
INSERT INTO t_user(username,password) VALUES (?, ?)
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} executed. 13.764741 millis. 
INSERT INTO t_user(username,password) VALUES (?, ?)
<==    Updates: 1
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} closed
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20002} closed
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2fd39614]
2017-01-05 13:32:36 INFO [com.xiaochangwei.web.service.impl.TestServiceImpl] 插入用户成功,返回的id为:27
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4a0b201e] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f68c1b4] will not be managed by Spring
==>  Preparing: SELECT id,username,password FROM t_user 
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} created. 
SELECT id,username,password FROM t_user
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} created. 
SELECT id,username,password FROM t_user
==> Parameters: 
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} Parameters : []
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} Parameters : []
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} Types : []
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} Types : []
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} executed. 
SELECT id,username,password FROM t_user
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} executed. 
SELECT id,username,password FROM t_user
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} executed. 0.92528 millis. 
SELECT id,username,password FROM t_user
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} executed. 0.92528 millis. 
SELECT id,username,password FROM t_user
<==    Columns: id, username, password
<==        Row: 1, 肖昌伟, 获取源码请发送邮件到 317409898@qq.com
<==        Row: 26, 8f7ca418-6c71-4a79-9fa4-f2dabb8ec5ed, 1483594292079
<==        Row: 27, 9c56119f-86cf-42f6-a509-419bd5ee7578, 1483594356817
<==      Total: 3
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} closed
2017-01-05 13:32:36 DEBUG [druid.sql.Statement] {conn-10005, pstmt-20003} closed
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4a0b201e]

然后就没有然后了, 所有代码我都贴出来了,如果这样你也不能运行起来,请记得呼叫我

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券