Jing Xuan little brother of mybatis summary

MyBatis framework is a semi-automatic mapping. "Semi-Automatic" is relative to the full Hibernate mapping table in terms of, MyBatis need to manually match the offer POJO, SQL and mapping relationships, Hibernate and POJO simply provide a mapping relationship can be.

Compared with Hibernate, although MyBatis manually write workload than using Hibernate SQL, but MyBatis can be configured to optimize the dynamic SQL and SQL, SQL mapping rules can be determined by the configuration, it also supports stored procedures. For some complex and the need to optimize the performance of the project, it is clear that using MyBatis more appropriate.

 public class MybatisUtils {

          private static SqlSessionFactory sqlSessionFactory = null;

          static {

              try {

    Reader reader = Resources.getResourceAsReader("mybatis-config.xml");

    sqlSessionFactory =  new SqlSessionFactoryBuilder().build(reader);

              } catch (Exception e) {

    e.printStackTrace ();

              }

          }

          public static SqlSession getSession() {

               return sqlSessionFactory.openSession();

          }

    }

<properties resource="db.properties" />

<dataSource type="POOLED">

    <-! Database-driven ->

    <property name="driver" value="${jdbc.driver}" />

    <-! Connection to the database url ->

    <property name="url" value="${jdbc.url}" />

    <! - username connection to the database ->

    <property name="username" value="${jdbc.username}" />

    <! - password to connect to the database ->

    <property name="password" value="${jdbc.password}" />

</dataSource>

 <environments default="development">

          <environment id="development">

      <transactionManager type="JDBC" />

            <dataSource type="POOLED">

                   <property name="driver" value="${jdbc.driver}" />

                   <property name="url" value="${jdbc.url}" />

                   <property name="username" value="${jdbc.username}" />

                   <property name="password" value="${jdbc.password}" />

         </dataSource>

          </environment>

            ...

     </environments>

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/jxxgg/p/11600818.html