码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis----延迟加载demo

时间:2017-04-03 18:57:57      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:pen   values   deb   sequence   status   延迟加载   environ   system   debug   

一:创建数据库脚本
drop table project_info; drop table status; create table status( id number(10) primary key, name varchar2(20) not null ); create table project_info( id number(10) primary key, project_name varchar2(100) not null, start_date date not null, end_date date not null, status_id number(10) references status(id) ); drop sequence seq_status; drop sequence seq_projectinfo; create sequence seq_status; create sequence seq_projectinfo; insert into status(id,name)values(seq_status.nextval,‘已申报‘); insert into status(id,name)values(seq_status.nextval,‘审核中‘); insert into status(id,name)values(seq_status.nextval,‘已审核‘); insert into project_info(id,project_name,start_date,end_date,status_id)values(seq_projectinfo.nextval,‘北京社会科学院2017年申报‘,to_date(‘2017=04-02‘,‘yyyy-MM-dd‘),to_date(‘2017=04-03‘,‘yyyy-MM-dd‘),1); insert into project_info(id,project_name,start_date,end_date,status_id)values(seq_projectinfo.nextval,‘福建社会科学院2017年申报‘,to_date(‘2017=04-04‘,‘yyyy-MM-dd‘),to_date(‘2017=04-05‘,‘yyyy-MM-dd‘),1); insert into project_info(id,project_name,start_date,end_date,status_id)values(seq_projectinfo.nextval,‘上海社会科学院2017年申报‘,to_date(‘2017=04-06‘,‘yyyy-MM-dd‘),to_date(‘2017=04-07‘,‘yyyy-MM-dd‘),1);

  二:项目目录结构

技术分享

三:在src下创建jdbc.properties

driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
username=system
password=orcl

四:在src下创建log4j.properties

log4j.rootLogger=DEBUG, Console  
  
#Console  
log4j.appender.Console=org.apache.log4j.ConsoleAppender  
log4j.appender.Console.layout=org.apache.log4j.PatternLayout  
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n  
  
log4j.logger.java.sql.ResultSet=INFO  
log4j.logger.org.apache=INFO  
log4j.logger.java.sql.Connection=DEBUG  
log4j.logger.java.sql.Statement=DEBUG  
log4j.logger.java.sql.PreparedStatement=DEBUG   

五:在src下创建mybatis-config.xml

<?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>
  <properties resource="jdbc.properties"/>
  <settings>
  <!--  开启延时加载开关 -->
    <setting name="lazyLoadingEnabled" value="true"/>
    <!-- 设置延时加载 -->
    <setting name="aggressiveLazyLoading" value="false"/>
  </settings>
  <typeAliases>
    <typeAlias type="com.pojo.ProjectInfo" alias="ProjectInfo"/>
    <typeAlias type="com.pojo.Status" alias="Status"/>
  </typeAliases>
  <environments default="developement">
     <environment id="developement">
       <transactionManager type="JDBC"/>
       <dataSource type="POOLED">
         <property name="driver" value="${driver}"/>
         <property name="url" value="${url}"/>
         <property name="username" value="${username}"/>
         <property name="password" value="${password}"/>
       </dataSource>
     </environment>
  </environments>
  <mappers>
     <mapper resource="com/mapper/ProjectInfoMapper.xml"/>
  </mappers>
</configuration>

  

MyBatis----延迟加载demo

标签:pen   values   deb   sequence   status   延迟加载   environ   system   debug   

原文地址:http://www.cnblogs.com/ipetergo/p/6662435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!