基于springmvc mybatis junit搭建分工程,分模块的web工程框架(一)

1.创建macow工程

一,new maven project --->创建Create a simple project勾选上

修改pom.xml的packaging为pom

Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix.

这个错误直接maven,update project就好了

二, 在root工程上邮件new maven module,module name为macow-dao。同样建macow-service,macow-common。

macow-web工程不要勾选Create a simple project,点next ,filter中输入web选maven-archetype-webapp,然后直接next,直到完成

三,在root工程上右键,选择maven-->Update project,所有工程都选上,force update(强制更新快照和release版本)和offline(离线)都选上

2.添加相应的maven依赖

root的pom.xml如下

<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.macow.home.first</groupId>
	<artifactId>macow-root</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	<modules>
		<module>macow-dao</module>
		<module>macow-service</module>
		<module>macow-model</module>
		<module>macow-web</module>
	</modules>

	<properties>
		<project.version>0.0.1-SNAPSHOT</project.version>
		<!-- 测试日志 -->
		<junit.version>4.12</junit.version>
		<slf4j.version>1.7.7</slf4j.version>
		<log4j.version>1.2.17</log4j.version>
		<commons-logging.version>1.1.3</commons-logging.version>

		<logback.version>1.1.3</logback.version>
		<!-- Generic properties -->
		<jedis.version>2.6.0</jedis.version>
		<java.version>1.6</java.version>
		<httpclient.version>4.3.6</httpclient.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<!-- web -->
		<servlet.version>3.0.1</servlet.version>
		<servlet-api.version>2.5</servlet-api.version>
		<jstl.version>1.2</jstl.version>
		<standard.version>1.1.2</standard.version>
		<!-- Spring -->
		<spring.version>3.2.14.RELEASE</spring.version>
		<fastjson.version>1.2.6</fastjson.version>
		<jackson2.version>2.3.0</jackson2.version>
		<jsr311.version>1.1.1</jsr311.version>
		<aspectj.version>1.7.4</aspectj.version>
		<cglib.version>2.2.2</cglib.version>
		<jackson.version>1.9.9</jackson.version>
		<!-- DAO -->
		<druid.version>1.0.15</druid.version>
		<druid-wrapper.version>0.2.9</druid-wrapper.version>
		<mybatis.version>3.2.8</mybatis.version>
		<mybatis-spring.version>1.2.2</mybatis-spring.version>
		<commons-dbcp.version>1.4</commons-dbcp.version>
		<postgresql.version>9.4-1201-jdbc4</postgresql.version>
		<pagehelper.version>3.7.6</pagehelper.version>
		<mapper.version>3.2.2</mapper.version>
		<persistence-api.version>1.0</persistence-api.version>
		<oracle.version>11.1.0.7.0</oracle.version>
		<!-- cxf -->
		<cxf.version>2.7.17</cxf.version>
		<!-- jackson_fast -->
		<jackson_fast.version>2.5.4</jackson_fast.version>
		<!-- validate -->
		<javax-validation.version>1.1.0.Final</javax-validation.version>
		<hibernate-validator.version>4.1.0.Final</hibernate-validator.version>
		<!-- apatch commons-lang -->
		<commons.lang.version>2.6</commons.lang.version>
		<commons-collections>3.1</commons-collections>
		<commons-fileupload>1.3.1</commons-fileupload>
		<commons-beanutils>1.8.0</commons-beanutils>

	</properties>
	<dependencyManagement>
		<dependencies>
			<!-- WEB -->
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>javax.servlet-api</artifactId>
				<version>${servlet.version}</version>
				<scope>provided</scope>
			</dependency>
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>jstl</artifactId>
				<version>${jstl.version}</version>
				<scope>provided</scope>
			</dependency>
			<dependency>
				<groupId>taglibs</groupId>
				<artifactId>standard</artifactId>
				<version>${standard.version}</version>
				<scope>provided</scope>
			</dependency>
			<!-- Spring -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-framework-bom</artifactId>
				<version>${spring.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
			<!-- aspectj -->
			<dependency>
				<groupId>org.aspectj</groupId>
				<artifactId>aspectjweaver</artifactId>
				<version>${aspectj.version}</version>
			</dependency>
			<dependency>
				<groupId>org.aspectj</groupId>
				<artifactId>aspectjrt</artifactId>
				<version>${aspectj.version}</version>
			</dependency>

			<!-- cglib -->
			<dependency>
				<groupId>cglib</groupId>
				<artifactId>cglib</artifactId>
				<version>${cglib.version}</version>
			</dependency>

			<!-- DAO相关 -->
			<dependency>
				<groupId>org.postgresql</groupId>
				<artifactId>postgresql</artifactId>
				<version>${postgresql.version}</version>
			</dependency>
			<dependency>
				<groupId>com.microsoft</groupId>
				<artifactId>sqljdbc4</artifactId>
				<version>${sqlserver.driver.version}</version>
			</dependency>
			<dependency>
				<groupId>commons-dbcp</groupId>
				<artifactId>commons-dbcp</artifactId>
				<version>${commons-dbcp.version}</version>
			</dependency>
			<dependency>
				<groupId>com.alibaba.druid</groupId>
				<artifactId>druid-wrapper</artifactId>
				<version>${druid-wrapper.version}</version>
			</dependency>
			<dependency>
				<groupId>com.alibaba</groupId>
				<artifactId>druid</artifactId>
				<version>${druid.version}</version>
			</dependency>

			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>${mybatis.version}</version>
			</dependency>
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis-spring</artifactId>
				<version>${mybatis-spring.version}</version>
			</dependency>

			<dependency>
				<groupId>tk.mybatis</groupId>
				<artifactId>mapper</artifactId>
				<version>${mapper.version}</version>
			</dependency>
			<dependency>
				<groupId>javax.persistence</groupId>
				<artifactId>persistence-api</artifactId>
				<version>${persistence-api.version}</version>
			</dependency>
			<!--分页插件 -->
			<dependency>
				<groupId>com.github.pagehelper</groupId>
				<artifactId>pagehelper</artifactId>
				<version>${pagehelper.version}</version>
			</dependency>

			<dependency>
				<groupId>com.oracle</groupId>
				<artifactId>jdbc6</artifactId>
				<version>${oracle.version}</version>
			</dependency>
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>${junit.version}</version>
				<scope>test</scope>
			</dependency>
			<!-- 日志 -->
			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>slf4j-api</artifactId>
				<version>${slf4j.version}</version>
			</dependency>
			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>log4j-over-slf4j</artifactId>
				<version>${slf4j.version}</version>
			</dependency>
			<dependency>
				<groupId>ch.qos.logback</groupId>
				<artifactId>logback-classic</artifactId>
				<version>${logback.version}</version>
			</dependency>
			<dependency>
				<groupId>commons-logging</groupId>
				<artifactId>commons-logging</artifactId>
				<version>${commons-logging.version}</version>
			</dependency>
			<!-- jackson -->
			<dependency>
				<groupId>org.codehaus.jackson</groupId>
				<artifactId>jackson-jaxrs</artifactId>
				<version>${jackson.version}</version>
			</dependency>
			<dependency>
				<groupId>com.fasterxml.jackson.jaxrs</groupId>
				<artifactId>jackson-jaxrs-json-provider</artifactId>
				<version>${jackson_fast.version}</version>
			</dependency>
			<!-- fastjson -->
			<dependency>
				<groupId>com.alibaba</groupId>
				<artifactId>fastjson</artifactId>
				<version>${fastjson.version}</version>
			</dependency>
			<!-- json2 -->
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-databind</artifactId>
				<version>${jackson2.version}</version>
			</dependency>
			<!-- apache 工具包 -->
			<dependency>
				<groupId>commons-lang</groupId>
				<artifactId>commons-lang</artifactId>
				<version>${commons.lang.version}</version>
			</dependency>

			<dependency>
				<groupId>commons-collections</groupId>
				<artifactId>commons-collections</artifactId>
				<version>${commons-collections}</version>
			</dependency>

			<dependency>
				<groupId>commons-fileupload</groupId>
				<artifactId>commons-fileupload</artifactId>
				<version>${commons-fileupload}</version>
			</dependency>

			<dependency>
				<groupId>commons-beanutils</groupId>
				<artifactId>commons-beanutils</artifactId>
				<version>${commons-beanutils}</version>
			</dependency>
			<dependency>
				<groupId>javax.ws.rs</groupId>
				<artifactId>javax.ws.rs-api</artifactId>
				<version>${javax.ws.rs.version}</version>
			</dependency>
			<dependency>
				<groupId>javax.ws.rs</groupId>
				<artifactId>jsr311-api</artifactId>
				<version>${jsr311-api.version}</version>
			</dependency>
			<dependency>
				<groupId>asm</groupId>
				<artifactId>asm</artifactId>
				<version>${asm.version}</version>
			</dependency>
			<!-- Apache cxf -->
			<dependency>
				<groupId>org.apache.cxf</groupId>
				<artifactId>cxf-rt-frontend-jaxrs</artifactId>
				<version>${cxf.version}</version>
			</dependency>

			<dependency>
				<groupId>org.apache.cxf</groupId>
				<artifactId>cxf-rt-transports-http-jetty</artifactId>
				<version>${cxf.version}</version>
			</dependency>
			<dependency>
				<groupId>redis.clients</groupId>
				<artifactId>jedis</artifactId>
				<version>${jedis.version}</version>
			</dependency>
			<dependency>
				<groupId>org.apache.zookeeper</groupId>
				<artifactId>zookeeper</artifactId>
				<version>3.4.6</version>
			</dependency>
			<!-- Httpclient -->
			<dependency>
				<groupId>org.apache.httpcomponents</groupId>
				<artifactId>httpclient</artifactId>
				<version>${httpclient.version}</version>
			</dependency>
			<!-- param validate -->
			<dependency>
				<groupId>javax.validation</groupId>
				<artifactId>validation-api</artifactId>
				<version>${javax-validation.version}</version>
			</dependency>

			<dependency>
				<groupId>org.hibernate</groupId>
				<artifactId>hibernate-validator-annotation-processor</artifactId>
				<version>${hibernate-validator.version}</version>
			</dependency>
			<dependency>
				<groupId>org.hibernate</groupId>
				<artifactId>hibernate-validator</artifactId>
				<version>${hibernate-validator.version}</version>
			</dependency>

		</dependencies>
	</dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>16.0.1</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
		</dependency>
		<!-- spring -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
		</dependency>
		<!-- Dao -->
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
		</dependency>
		<dependency>
			<groupId>com.alibaba.druid</groupId>
			<artifactId>druid-wrapper</artifactId>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
		</dependency>

		<dependency>
			<groupId>tk.mybatis</groupId>
			<artifactId>mapper</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.persistence</groupId>
			<artifactId>persistence-api</artifactId>
		</dependency>
		<!--分页插件 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>log4j-over-slf4j</artifactId>
		</dependency>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils</artifactId>
		</dependency>
		<!-- fastjson -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
		</dependency>
		<!-- aspectj -->
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
		</dependency>
		<!-- hibernate-validator -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator-annotation-processor</artifactId>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
		</dependency>
		<!-- jackson -->
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-jaxrs</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
		</dependency>
	</dependencies>
	<build>
		<finalName>macow-web</finalName>
		<pluginManagement>
			<plugins>
				<!-- 编译插件 -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>3.0</version>
					<configuration>
						<encoding>${project.build.sourceEncoding}</encoding>
						<source>${java.version}</source>
						<target>${java.version}</target>
						<optimise>true</optimise>
						<debug>true</debug>
					</configuration>
				</plugin>
				<!-- Java源码插件 -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-source-plugin</artifactId>
					<version>2.2.1</version>
					<configuration>
						<encoding>${project.build.sourceEncoding}</encoding>
					</configuration>
					<executions>
						<execution>
							<id>attach-source</id>
							<phase>install</phase>
							<goals>
								<goal>jar-no-fork</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</pluginManagement>

	</build>
</project>

另外所有的工程下面在src/main/java目录建一个包com.macow.home.first

3.DAO层的整合

一,macow-model下面建实体类

package com.macow.home.first.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Table(name = "T_USER")
public class User implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(generator = "UUID")
	private String id;
	@Column
	private String name;
	@Column
	private String password;
	@Column
	private Date createDate;

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setId(String id) {
		this.id = id;
	}

}

建表语句

CREATE TABLE public.t_user (
	id varchar(40) NOT NULL,
	"name" varchar(80) NULL,
	password varchar(80) NULL,
	create_date timestamp NULL,
	CONSTRAINT "NewTable_pkey" PRIMARY KEY (id)
)

二,macow-dao在src/main/java下新建UserMapper.xml和UserMap.xml

package com.macow.home.first.mapper;

import java.util.List;

import org.springframework.stereotype.Repository;

import tk.mybatis.mapper.common.Mapper;

import com.macow.home.first.entity.User;

@Repository("userMapper")
public interface UserMapper extends Mapper<User> {

	public List<User> selectByName(User user);
}
<?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.macow.home.first.mapper.UserMapper">

	<select id="selectByName" resultType="com.macow.home.first.entity.User" parameterType="com.macow.home.first.entity.User">
	select * from t_user where name=#{name} and create_Date=#{createDate};
	</select>
</mapper>

在src/main/resources下的spring-dao.xml

<beans	xmlns="http://www.springframework.org/schema/beans"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xmlns:context="http://www.springframework.org/schema/context"
		xmlns:tx="http://www.springframework.org/schema/tx"
		xmlns:aop="http://www.springframework.org/schema/aop"
		xmlns:util="http://www.springframework.org/schema/util"
		xmlns:p="http://www.springframework.org/schema/p"
		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
		                    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
		                    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

	<!-- 1, TOA-ASSET PostgreSQL 数据源 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
		<property name="driverClassName" value="${ds.driverClassName}"/>
		<property name="url" value="${ds.url}" />
		<property name="username" value="${ds.username}" />
		<property name="password" value="${ds.password}" />
		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="${ds.initialSize}" />
		<property name="minIdle" value="${ds.minIdle}" />
		<property name="maxActive" value="${ds.maxActive}" />

		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="${ds.maxWait}" />

		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}" />

		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}" />

		<property name="validationQuery" value="${ds.validationQuery}" />
		<property name="testWhileIdle" value="${ds.testWhileIdle}" />
		<property name="testOnBorrow" value="${ds.testOnBorrow}" />
		<property name="testOnReturn" value="${ds.testOnReturn}" />

		<property name="filters" value="${ds.filters}" />

	</bean>

	<!-- 配置mybatis的SessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="typeAliasesPackage" value="com.macow.home.first.entity" />
		<property name="plugins">
	    	<array>
		        <bean class="com.github.pagehelper.PageHelper">
		          <property name="properties">
		            <value>
		              dialect=postgresql
		              reasonable=true
		            </value>
		          </property>
		        </bean>
	      	</array>
	    </property>
	</bean>

	<!-- 自动扫描注册Mybatis mapper -->
	<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
    	<property name="basePackage" value="com.macow.home.first.mapper"/>
    	<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
	</bean>

	<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
</beans>

在src/test/java下的测试类

package com.macow.home.first;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.macow.home.first.entity.User;
import com.macow.home.first.mapper.UserMapper;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring-context.xml")
public class UserMapperTest {
	private Logger logger=LoggerFactory.getLogger(this.getClass());
	@Autowired
	private UserMapper userMapper;

	@Test
	public void testUserInsert() {
		User user=new User();
		user.setName("王重阳123111");
		user.setPassword("11112222");
		userMapper.insert(user);
		logger.info("--------->testUserInsert end-------------");
	}

	@Test
	public void testUserSelect() {
		List<User> select = userMapper.select(null);
		for(User user:select){
			logger.info("--------->"+user.getName()+"-------------");
		}
		logger.info("--------->testUserInsert end-------------");
	}
}

在src/test/resources下的配置文件jdbc.properties和spring-content.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:aop="http://www.springframework.org/schema/aop"
	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/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd">

	<context:property-placeholder location="classpath*:jdbc.properties" />

	<import resource="spring-dao.xml" />
</beans>
#db
ds.driverClassName=org.postgresql.Driver
ds.url=jdbc:postgresql://localhost:5432/postgres
ds.username=postgres
ds.password=11111111
#ds.url=jdbc:postgresql://10.20.130.25:7440/toaasset
#ds.username=assetopr
#ds.password=paic1234
#durid datasource
ds.initialSize=2
ds.minIdle=5
ds.maxActive=5
#ds.filters=stat,config
ds.filters=stat
ds.maxWait=60000
ds.timeBetweenEvictionRunsMillis=60000
ds.minEvictableIdleTimeMillis=300000
ds.validationQuery=SELECT 1
ds.testWhileIdle=true
ds.testOnBorrow=false
ds.testOnReturn=false

三,运行测试类的方法testUserSelect()

结果如下

16:27:32.469 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
16:27:32.469 [main] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [[email protected]] was not registered for synchronization because synchronization is not active
16:27:32.500 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
16:27:32.640 [main] INFO  c.alibaba.druid.pool.DruidDataSource - {dataSource-1} inited
16:27:32.656 [main] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [[email protected]] will not be managed by Spring
16:27:32.656 [main] DEBUG c.m.h.first.mapper.UserMapper.select - ==>  Preparing: SELECT id,name,password,create_Date AS createDate FROM T_USER
16:27:32.672 [main] DEBUG c.m.h.first.mapper.UserMapper.select - ==> Parameters:
16:27:32.704 [main] DEBUG c.m.h.first.mapper.UserMapper.select - <==      Total: 33
16:27:32.704 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [[email protected]]
16:27:32.704 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource

dao层mybatis已经集成好了,junit测试也是成功了

macow-dao的项目结构如图:

时间: 2024-12-16 10:42:38

基于springmvc mybatis junit搭建分工程,分模块的web工程框架(一)的相关文章

IntelliJ IDEA下Maven SpringMVC+Mybatis入门搭建例子

很久之前写了一篇SSH搭建例子,由于工作原因已经转到SpringMVC+Mybatis,就以之前SSH实现简单登陆的例子,总结看看SpringMVC+Mybatis怎么实现. Spring一开始是轻量级的框架,在SSH中,处于中间粘合剂的作用,核心作用是IoC(控制反转).DI(依赖注入),IoC和DI是同一个概念,只是以不同角度进行解释.简单的说,就是Spring帮助你管理Bean,只要写好了配置文件或者Spring注解,那么Spring可以自动帮你创建Bean,不需要手动new.经过后来的发

maven+springMVC+mybatis+junit详细搭建过程 【转】

springMVC+mybatis框架搭建 首先我们先要弄清搭建项目的一般流程,需要注意哪些方面,想要什么样的效果,自己的功能有哪些? (假设效果:项目目录结构清晰,能够查询到本地数据库中的内容..) 1.  工程目录结构整理清楚 在src/main/java文件夹中,新建包cn.springmvc.model(存放javabean), cn.springmvc.dao(存放spring与mybatis连接接口), cn.springmvc.service(service接口), cn.spri

maven+springMVC+mybatis+junit详细搭建过程

springMVC+mybatis框架搭建 首先我们先要弄清搭建项目的一般流程,需要注意哪些方面,想要什么样的效果,自己的功能有哪些? (假设效果:项目目录结构清晰,能够查询到本地数据库中的内容..) 1.  工程目录结构整理清楚 在src/main/java文件夹中,新建包cn.springmvc.model(存放javabean), cn.springmvc.dao(存放spring与mybatis连接接口), cn.springmvc.service(service接口), cn.spri

原:maven+springMVC+mybatis+junit详细搭建过程

阅读目录 1.  工程目录结构整理清楚 2.  引入依赖包 3. 配置数据库连接属性 4.  配置spring配置文件 5.  java代码编写(model,dao,service层代码) 6.  mybatis配置 7.  junit测试插入功能 8.  springMVC模块搭建 9.  log4j日志记录搭建 10.  测试运行 整体包下载地址: springMVC+mybatis框架搭建 首先我们先要弄清搭建项目的一般流程,需要注意哪些方面,想要什么样的效果,自己的功能有哪些? (假设效

基于maven+ssm的增删改查之spring+springmvc+mybatis环境搭建

接上一节. 1.首先建立如下目录 说明: com.gong.curd.bean:用于存放普通javabean. com.gong.curd.dao:用于存放mapper接口 com.gong.curd.controller:用于存放控制器 com.gong.curd.service:用于存放业务层接口 com.gong.curd.serviceImpl:用于存放service接口的实现类 com.gong.curd.utils:用于存放通用的工具类 com.gong.curd.test:用于测试

SSM框架——Spring+SpringMVC+Mybatis的搭建教程

一:概述 SSM框架在项目开发中经常使用到,相比于SSH框架,它在仅几年的开发中运用的更加广泛. Spring作为一个轻量级的框架,有很多的拓展功能,最主要的我们一般项目使用的就是IOC和AOP. SpringMVC是Spring实现的一个Web层,相当于Struts的框架,但是比Struts更加灵活和强大! Mybatis是 一个持久层的框架,在使用上相比Hibernate更加灵活,可以控制sql的编写,使用 XML或注解进行相关的配置! 根据上面的描述,学习SSM框架就非常的重要了! 二:搭

玩转 SSH(六):SpringMVC + MyBatis 架构搭建(注解版)

一.创建 SSMVCAnnoDemo 项目 点击菜单,选择“File -> New Project” 创建新项目.选择使用 archetype 中的 maven-webapp 模版创建. 输入对应的项目坐标GroupId 和 ArtifactId 之后在项目名称中填入项目名称,这里我填的 ProjectName 和上文的 ArtifactId 相同,都是 SSMVCAnnoDemo. 点击确定后,等待 Maven 帮我们构建好项目的目录结构.当控制台显示 BUILD SUCCESS 就表示初始化

基于springMVC+mybatis的实践记录

目前在做一个项目用到springMVC+mybatis,由于之前没学过,上手有点难,因此写下随笔记录下: 写了四个接口 第一个接口:GET请求,查询返回列表 查找 专户报告列表 -----GEThttp://localhost:8080/fee/investWeeklyReport/getByAccoutId 通过postman 模拟各种参数 { "code": 0, "message": "成功", "data": { &q

springmvc+mybatis环境搭建

1.spring+mybatis 环境搭建: A.配置jdbc和dbcp数据源:注意版本com.mysql.cj.jdbc.Driver B.配置sessionfactory,绑定dbcp及配置mapper文件命名规范, C.配置mapper文件所在包 *注意调整mysql数据库时区,否则将报错,可参考如下: MySQL之--Ignoring query to other database问题 https://blog.csdn.net/l1028386804/article/details/5