程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> MyBatisÔ´ÂëdzÎö£¨Ò»£©¿ªÆª

MyBatisÔ´ÂëdzÎö£¨Ò»£©¿ªÆª

編輯:關於JAVA

MyBatisÔ´ÂëdzÎö£¨Ò»£©¿ªÆª。本站提示廣大學習愛好者:(MyBatisÔ´ÂëdzÎö£¨Ò»£©¿ªÆª)文章只能為提供參考,不一定能成為您想要的結果。以下是MyBatisÔ´ÂëdzÎö£¨Ò»£©¿ªÆª正文


Ô´ÂëѧϰµÄºÃ´¦²»Óöà˵£¬MybatisÔ´ÂëÁ¿ÉÙ¡¢Âß¼­¼òµ¥£¬½«Ð´¸öϵÁÐÎÄÕÂÀ´Ñ§Ï°¡£

SqlSession

MybatisµÄʹÓÃÈë¿ÚλÓÚorg.apache.ibatis.session°üÖеÄSqlSession£¬·¢ÏÖËüÊǸö½Ó¿Ú£¬±ØÈ»ÓиöĬÈÏʵÏÖÀàorg.apache.ibatis.session.defaults°üÖеÄDefaultSqlSession¡£ÎÒÃÇ´ÓÀ´Ã»ÓÐnew¹ýÕâ¸öÀ࣬°´ÕÕJava¹ßÀýʹÓÃSqlSessionFactoryÀïµÄ¹¤³§·½·¨¡£·¢ÏÖËüÒ²ÊǸö½Ó¿Ú£¬±ØÈ»ÓÐĬÈÏʵÏÖÀàDefaultSqlSessionFactory¡£¸ÃÀàÒÀÈ»²»ÓÃ×Ô¼º´´½¨£¬Ê¹ÓÃSqlSessionFactoryBuilderÀïµÄ¹¤³§·½·¨¡£

DefaultSqlSession

DefaultSqlSessionÀïÖ÷Òª·½·¨£º

1£©Cursor<T> selectCursor(String statement, Object parameter, RowBounds rowBounds)£¬Î¯Íиøexecutor.queryCursor(ms, wrapCollection(parameter), rowBounds)¡£

2£©List<E> selectList(String statement, Object parameter, RowBounds rowBounds)ºÍvoid select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler)£¬Î¯Íиøexecutor.query(ms, wrapCollection(parameter), rowBounds, handler)¡£

3£©int update(String statement, Object parameter)£¬Î¯Íиøexecutor.update(ms, wrapCollection(parameter))¡£
¿É¼û£¬×îÖÕ¶¼ÓÐexecutorÀ´Íê³É¡£

Executor

ExecutorλÓÚorg.apache.ibatis.executor°üÖУ¬ÊǸö½Ó¿Ú£¬ÊµÏÖÀàÊÇBaseExecutorºÍCachingExecutor¡£ÆäÖÐBaseExecutorÊdzéÏóµÄ£¬ÓÐÈý¸ö×ÓÀàSimpleExecutor¡¢ReuseExecutorºÍBatchExecutor£¬¼ûÃûÖªÒâ¡£BaseExecutorÀïÖ÷Òª·½·¨£º

1£©List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql)ºÍList<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql)£¬Î¯ÍÐΪ³éÏóµÄabstract <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)¡£

2£©Cursor<E> queryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds)£¬Î¯Íиø³éÏóµÄabstract <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql)¡£

3£©int update(MappedStatement ms, Object parameter)£¬Î¯Íиø³éÏóµÄabstract int doUpdate(MappedStatement ms, Object parameter)¡£

»ùÀà´¦Àí¹«¹²²¿·Ö£¬¾ßÌåÁô¸ø×ÓÀàʵÏÖ¡£

ÔÙ¿´ÏÂSimpleExecutorÀïµÄÖ÷Òª·½·¨£º

1£©List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)£¬Î¯Íиøhandler.<E>query(stmt, resultHandler)¡£

2£©Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql)£¬Î¯Íиøhandler.<E>queryCursor(stmt)¡£

3£©int doUpdate(MappedStatement ms, Object parameter)£¬Î¯Íиøhandler.update(stmt)¡£

¿É¼û£¬×îÖÕÓÉhandlerÀ´´¦Àí¡£

StatementHandler

StatementHandlerλÓÚorg.apache.ibatis.executor.statement°üÖУ¬ÊǸö½Ó¿Ú£¬ÊµÏÖÀàÊÇBaseStatementHandlerºÍRoutingStatementHandler¡£BaseStatementHandlerÊdzéÏóµÄ£¬ÓÐÈý¸ö×ÓÀàSimpleStatementHandler¡¢PreparedStatementHandlerºÍCallableStatementHandler¡£ÕâÈý¸öÓ¦¸Ã±È½ÏÊìϤ£¬·Ö±ð´¦Àí²»´ø²ÎÊýµÄsqlÓï¾ä¡¢²ÎÊý»¯sqlÓï¾äºÍ´æ´¢¹ý³Ì¡£ÔÙ¿´SimpleStatementHandlerÀïµÄÖ÷Òª·½·¨£º

1£©List<E> query(Statement statement, ResultHandler resultHandler)£¬Î¯Íиøstatement.execute(sql)¡£

2£©Cursor<E> queryCursor(Statement statement)£¬Î¯Íиøstatement.execute(sql)¡£

3£©int update(Statement statement)£¬Î¯Íиøstatement.execute(sql)¡£

×îÖÕÓÉstatementÖ´ÐÐsql¡£Õâ¾Í»Øµ½ÁËjava.sql°üÁË¡£

MybatisÖ÷ÒªÍê³É¶Ôsql²ÎÊýµÄ·â×°´¦Àí¡¢½á¹û¼¯µÄ»ñÈ¡²¢Éú³É¶ÔÏ󣬶ø°ÑsqlÓï¾äµÄ¹¹½¨¹ý³ÌÁô¸øÓû§¡£MybatisµÄ×÷Õß¹ÊÒâÕâÑùÉè¼ÆµÄ¡£ËäÈ»¿ò¼Ü´ÓÕûÌåÀ´¿´ÊÇ°ë×Ô¶¯µÄ£¬µ«Áé»îÐÔÈ´µÃµ½Á˼«´óÔö¼Ó¡£

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved