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