【分享】標準springMVC+mybatis項目maven搭建最精簡教程

文章由來:公司有個實習同窗須要作畢業設計,不會搭建環境,我就代勞了,順便分享給剛入門的小夥伴,我是自學的JAVA,因此我懂的....前端

 

大圖直接觀看顯示很模糊,請在圖片上點擊右鍵而後在新窗口打開看java

先看下項目的總體層次結構及說明,本次是用的web3.0,因此須要tomcat8及以上才能運行mysql

 

再看下用到了哪些jar包,jar包能夠說是最精簡的了,採用的maven管理web

 

測試:請求地址時,會增長一條數據到數據庫,而後讀出全部數據,僅供演示,就沒再分開了。spring

我提供了兩種方式,一種是返回結果並展現到jsp頁面,用到了jstl;另外一種就是直接返回的jsonsql

 

先看返回到jsp頁面的:數據庫

代碼以下:express

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數據的:apache

代碼以下: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]

 

而後就沒有而後了, 全部代碼我都貼出來了,若是這樣你也不能運行起來,請記得呼叫我

相關文章
相關標籤/搜索