MyBatis optimized operation

Source: Internet
Author: User

MyBatis optimized operation

When linking the database, you can write the operation of the configuration link database file in a file, and then introduce the file in the Conf.xml file, which is similar to the JSTL tag value when the value is taken.

<properties resource= "Db.properties"/>

Through the above two sections of the code, you can see that the entity class is too long to write this is more troublesome, there is no alias to replace it, MyBatis does provide a way to define the alias

Write down the code in the Conf.xml

< typealiases >         <  type= "bean. User "  alias=" _user "/></typealiases>

The use of aliases can be implemented. As we all know, hibernate can be printed in SQL statements, MyBatis can also be implemented, but need to configure themselves, need to introduce log4j package in the project

src to add the log4j configuration file, print the log information.

1: Add Rack Pack Log4j-1.2.16.jar

2: Configure Log4j.xml

<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "Log4j.dtd"><log4j:configurationxmlns:log4j= "http://jakarta.apache.org/log4j/">    <Appendername= "STDOUT"class= "Org.apache.log4j.ConsoleAppender">//Output to console<Layoutclass= "Org.apache.log4j.PatternLayout">            <paramname= "Conversionpattern"value= "%-5p%d{mm-dd hh:mm:ss,sss}%m (%f:%l) \ n" />        </Layout>    </Appender>    <Loggername= "java.sql">//Output SQL statement< Levelvalue= "Debug" />    </Logger>    <Loggername= "Org.apache.ibatis">        < Levelvalue= "Debug" />    </Logger>    <Root>        < Levelvalue= "Debug" />        <Appender-refref= "STDOUT" />    </Root>

MyBatis optimized operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.