mybatis基础理解

1、主要的类

创新互联是一家集网站建设,阳高企业网站建设,阳高品牌网站建设,网站定制,阳高网站建设报价,网络营销,网络优化,阳高网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

1.1 SqlSessionFactoryBuilder

     用于创建SqlSessionFactory,要通过配置文件也可以是代码。

   主要的方法

SqlSessionFactory build(InputStream inputStream)
SqlSessionFactory build(InputStream inputStream, String environment)
SqlSessionFactory build(InputStream inputStream, Properties properties)
SqlSessionFactory build(InputStream inputStream, String env, Properties props)
SqlSessionFactory build(Configuration config)

    创建的示例

String resource = "org/mybatis/builder/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory factory = builder.build(inputStream);
DataSource dataSource = BaseDataTest.createBlogDataSource();
TransactionFactory transactionFactory = new JdbcTransactionFactory();

Environment environment = new Environment("development", transactionFactory, dataSource);

Configuration configuration = new Configuration(environment);
configuration.setLazyLoadingEnabled(true);
configuration.setEnhancementEnabled(true);
configuration.getTypeAliasRegistry().registerAlias(Blog.class);
configuration.getTypeAliasRegistry().registerAlias(Post.class);
configuration.getTypeAliasRegistry().registerAlias(Author.class);
configuration.addMapper(BoundBlogMapper.class);
configuration.addMapper(BoundAuthorMapper.class);

SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory factory = builder.build(configuration);

1.2 SqlSessionFactory

    用于创建SqlSession

    主要方法

SqlSession openSession()
SqlSession openSession(boolean autoCommit)
SqlSession openSession(Connection connection)
SqlSession openSession(TransactionIsolationLevel level)
SqlSession openSession(ExecutorType execType,TransactionIsolationLevel level)
SqlSession openSession(ExecutorType execType)
SqlSession openSession(ExecutorType execType, boolean autoCommit)
SqlSession openSession(ExecutorType execType, Connection connection)
Configuration getConfiguration();

1.3 SqlSession

   持久层操作会话

   常用方法

 T selectOne(String statement)
 List selectList(String statement)
 Map selectMap(String statement, String mapKey)
int insert(String statement)
int update(String statement)
int delete(String statement)

   事务操作方法

void commit()
void commit(boolean force)
void rollback()
void rollback(boolean force)

2、配置文件


  
  

  
  
  
  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

  

  
    
      
    
    
      
      
      
      
    
  

  
          
  

  
  
  

  

注:

配置文件元素与JAVA操作方法是可以相互对应的; 配置文件中元素是可以独立,如属性文件和注解。

详细参考官网地址:http://www.mybatis.org/mybatis-3/zh/configuration.html#environments


网站名称:mybatis基础理解
路径分享:http://csruizhi.cn/article/pjgcec.html

其他资讯

Copyright © 2007-2024 成都优众联杰科技有限公司 All Rights Reserved 蜀ICP备2024116266号
友情链接: 高端网站设计 企业网站建设 成都网站建设 成都网站制作 网站设计 成都做网站建设公司 LED网站设计方案 企业网站建设公司 成都网站设计 营销网站建设 网站建设公司 定制网站建设多少钱 成都网站建设 成都网站设计 网站制作 成都网站设计 成都网站设计公司 温江网站设计 商城网站建设 成都网站建设公司 专业网站建设 手机网站制作