mybatis+spring maven下 整合 完整demo
2014-07-17 17:49
423 查看
<span style="font-family: Arial, Helvetica, sans-serif;">当前项目代码地址</span>
<pre code_snippet_id="429127" snippet_file_name="blog_20140717_1_9741099" name="code" class="csharp">http://download.csdn.net/detail/philip502/7646963
</pre><pre code_snippet_id="429127" snippet_file_name="blog_20140717_2_8966541" name="code" class="csharp">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>javamavenstudy</groupId> <artifactId>spring-mybatis-demo-01</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>spring-mybatis-demo-01</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <org.springframework.version>4.0.2.RELEASE</org.springframework.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.0.2.RELEASE</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.5</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.29</version> </dependency> </dependencies> </project>
jobdriverlog.xml
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="spring.mybatis.demo01.IJobDriverLogDao"> <resultMap type="spring.mybatis.demo01.JobDriverLog" id="logResult"> <result property="id" column="id" jdbcType="INTEGER" javaType="java.lang.Integer" /> <result property="job_code" column="job_code" /> <result property="status" column="status" /> <result property="start_time" column="start_time" /> <result property="end_time" column="end_time" /> <result property="comment" column="comment" /> <result property="create_time" column="create_time" /> <result property="data_begin_time" column="data_begin_time" /> <result property="data_end_time" column="data_end_time" /> </resultMap> <select id="fetch" parameterType="JobDriverLog" resultMap="logResult"> <![CDATA[ select * from job_driver_log where job_code = #{job_code} and data_begin_time <= #{data_begin_time} and data_end_time >= #{data_end_time} ]]> </select> <select id="insert" parameterType="JobDriverLog" resultMap="logResult"> <![CDATA[ insert into job_driver_log (job_code,status,start_time,end_time,comment,data_begin_time,data_end_time,create_time) values(#{job_code},#{status},#{start_time},#{end_time},#{comment},#{data_begin_time},#{data_end_time},#{create_time}) ]]> </select> </mapper>
beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" 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 http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <context:annotation-config /> <context:component-scan base-package="*" /> <bean id="rpbgDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://10.3.255.21:3320/tc" /> <property name="username" value="off_mynet" /> <property name="password" value="9x7c5bMox3Vq" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="rpbgDataSource" /> <property name="configLocation" value="mybatis.xml" /> </bean> </beans>
IJobDriverLogDao.java
/** * */ package spring.mybatis.demo01; /** * This class is used for ... * * @author luyifeng * @version 1.0, 2014-7-16 下午7:10:31 */ public interface IJobDriverLogDao { public abstract JobDriverLog fetch(JobDriverLog log); public abstract void insert(JobDriverLog log); }
JobDriverLog.java
/** * */ package spring.mybatis.demo01; /** * This class is used for ... * * @author luyifeng * @version 1.0, 2014-7-16 下午5:12:37 */ public class JobDriverLog { private int id; private String job_code; private int status; private int start_time; private int end_time; private String comment; private int create_time; private int data_begin_time; private int data_end_time; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getJob_code() { return job_code; } public void setJob_code(String job_code) { this.job_code = job_code; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public int getStart_time() { return start_time; } public void setStart_time(int start_time) { this.start_time = start_time; } public int getEnd_time() { return end_time; } public void setEnd_time(int end_time) { this.end_time = end_time; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public int getCreate_time() { return create_time; } public void setCreate_time(int create_time) { this.create_time = create_time; } public int getData_begin_time() { return data_begin_time; } public void setData_begin_time(int data_begin_time) { this.data_begin_time = data_begin_time; } public int getData_end_time() { return data_end_time; } public void setData_end_time(int data_end_time) { this.data_end_time = data_end_time; } }
App.java
package spring.mybatis.demo01; import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Hello world! * */ public class App { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext( "config/beans.xml"); SqlSessionFactory factory = (SqlSessionFactory) ac .getBean("sqlSessionFactory"); System.out.println(factory); System.out.println("Hello World!"); } }
最后的目录结构图:
相关文章推荐
- Eclipse+Tomcat+MAVEN+SVN项目完整环境搭建+SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- Maven+SpringMVC+Mybatis整合入门Demo
- Intellij-IDEA-maven+springMVC+mybatis整合DEMO
- 使用maven,实现ssm(spring+springmvc+mybatis)三大框架的整合DEMO
- SSM框架整合(Maven+Spring+SpringMVC+Mybatis+mysql 附demo实例)
- 909422229_spring+springMVC+Mybatis+reids+maven环境整合demo
- Spring整合MyBatis(Maven+spring+MyBatis+mysql实践附demo)
- 基于Maven的Spring+SpringMVC+MyBatis框架整合Demo
- MyBatis+Spring+Maven的简单整合Demo
- maven项目 spring-boot 整合 mybatis 实现查询功能demo
- springmvc+spring+mybatis整合demo(maven)
- Spring+mybatis+maven整合过程加载配置文件jdbc.properties
- 整合spring mvc和mybatis,spring,maven的pom脚本
- SpringMVC+Spring+Mybatis+Maven整合-需要的包
- maven项目下的Spring+SpringMVC+Mybatis整合实例
- spring+mybatis+springMvc+maven简单整合
- MAVEN_SPRING+SPRINGMVC+MYBATIS+FREEMARKER 整合
- springmvc+mybatis+maven整合实例
- velocity mybatis spring 在maven的整合开发(二)
- springMVC+MyBatis+Spring+maven 整合(1)