文章由来:公司有个实习同学需要做毕业设计,不会搭建环境,我就代劳了,顺便分享给刚入门的小伙伴,我是自学的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]

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

【分享】标准springMVC+mybatis项目maven搭建最精简教程的更多相关文章

  1. IDEA中maven搭建Spring+SpringMVC+mybatis项目

    一.介绍 使用IDEA搭建maven web项目,整合框架Spring+SpringMVC+mybatis 项目结构图:

  2. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目

    一:创建maven web项目er

  3. 通过IntelliJ IDEA创建maven+springmvc+mybatis项目

    第一个springmvc+mybatis项目,通过学习极客学院视频(视频案例通过eclipse搭建,网址为http://www.jikexueyuan.com/course/1430.html),发现 ...

  4. 用 eclipse 创建一个简单的 meaven spring springMvc mybatis 项目

    下面是整体步骤: 1: 先创建一个Maven 项目: 选择跳过骨架: 因为要搭建的是 web 项目  所以这个地方选择 war 包; 点击完成 这样就完成 Maven项目的搭建: 接下俩 先把 Mav ...

  5. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 构建目录环境和依赖)

    引言:在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一   的基础上 继续进行项目搭建 该部分的主要目的是测通MyBatis 及Spring-dao ...

  6. SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一)

    1. 前言 最近在写毕设过程中,重新梳理了一遍SSM框架,特此记录一下. 附上源码:https://gitee.com/niceyoo/jeenotes-ssm 2. 概述 在写代码之前我们先了解一下 ...

  7. SpringBoot+SpringMVC+MyBatis快速整合搭建

    作为开发人员,大家都知道,SpringBoot是基于Spring4.0设计的,不仅继承了Spring框架原有的优秀特性,而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程.另外Spr ...

  8. Spring+SpringMvc+Mybatis框架集成搭建教程

    一.背景 最近有很多同学由于没有过SSM(Spring+SpringMvc+Mybatis , 以下简称SSM)框架的搭建的经历,所以在自己搭建SSM框架集成的时候,出现了这样或者那样的问题,很是苦恼 ...

  9. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试

    这一部分的主要目的是 配置spring-service.xml  也就是配置spring  并测试service层 是否配置成功 用IntelliJ IDEA 开发Spring+SpringMVC+M ...

随机推荐

  1. Restful资源文章

    理解RESTful架构 RESTful API设计指南 RESTful架构详解 NodeJs的RESTful API

  2. 2015 西雅图微软总部MVP峰会记录

    2015 西雅图微软总部MVP峰会记录 今年决定参加微软MVP全球峰会,在出发之前本人就已经写这篇博客,希望将本次会议原汁原味奉献给大家 因为这次是本人第一次写会议记录,写得不好的地方希望各位园友见谅 ...

  3. SQLSERVER走起微信公众帐号全新改版 全新首页

    SQLSERVER走起微信公众帐号全新改版 全新首页 今天,SQLSERVER走起微信公众帐号增加了首页功能 虽然还是订阅号,不过已经对版面做了比较大的修改,希望各位亲用得放心.用得安心O(∩_∩)O ...

  4. SQL Server 数据加密功能解析

    SQL Server 数据加密功能解析 转载自: 腾云阁 https://www.qcloud.com/community/article/194 数据加密是数据库被破解.物理介质被盗.备份被窃取的最 ...

  5. T-SQL字符串相加之后被截断的那点事

    本文出处:http://www.cnblogs.com/wy123/p/6217772.html 字符串自身相加, 虽然赋值给了varchar(max)类型的变量,在某些特殊情况下仍然会被“截断”,这 ...

  6. kvm 使用入门详解

    kvm 是虚拟化技术的一个典型实现,功能非常强大,使用很方便.kvm 本身主要实现对 CPU 的虚拟化,内存和IO的虚拟化使用了开源软件 qemu,qemu 是纯软件层面的虚拟化,其实就是个模拟器.k ...

  7. 【每日一linux命令1】linux命令路径

    一.路径: 执行命令前必须要考虑的一步是命令的路径,若是路径错误或是没有正确的指定,可能导致错误 的执行或是找不到该命令.要知道设置的路径,可执行以下命令: echo $PATH 显示结果: 这时我们 ...

  8. Hibernatel框架基础使用

    Hibernatel框架基础使用 1.简介 1.1.Hibernate框架由来 Struts:基于MVC模式的应用层框架技术 Hibernate:基于持久层的框架(数据访问层使用)! Spring:创 ...

  9. C#跨平台手机应用开发工具Xamarin尝试 与Eclipse简单对比

    Xamarin 支持使用C#开发基于Android.IOS.WindowsPhone应用开发,最大特点C#+跨平台,详细说明问度娘. 安装 研究 想体验研究的点击查看页面 Xamarin For Vi ...

  10. 【已解决】Https请求——基础连接已经关闭 发送时发生错误

    本人在做商用项目的推送消息功能时,借助第三方推送服务.这里避免有打广告的嫌疑,就不报名字了.由于是通过调用API接口,所以Post方法是自己写的,但是在开发环境是可以正常推送的,但是一上线就出各种问题 ...