MyBatis implementing CRUD Operations and Optimizing Code and debugging (MySQL database) (iii)

Source: Internet
Author: User

Continue (ii) to say that

1. Engineering structure

2. Create a new db.properties file (my database does not have a password set)

driver=com.mysql.jdbc.driverurl=jdbc:mysql://localhost:3306/mybatisname=rootpassword=

3.log4j.jar join the project and add the Log4j.xml file

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE log4j:configuration SYSTEM "log4j.dtd" ><log4j:configuration xmlns:log4j= "http://jakarta.apache.org/ log4j/"><appender name=" STDOUT "class=" Org.apache.log4j.ConsoleAppender "><layout class=" Org.apache.log4j.PatternLayout "><param name=" Conversionpattern "value="%-5p%d{mm-dd hh:mm:ss,sss}%m  (%F :%l) \ n "/></layout></appender><logger name=" java.sql "><level value=" Debug "/></ Logger><logger name= "Org.apache.ibatis" ><level value= "Debug"/></logger><root>< Level value= "Debug"/><appender-ref ref= "STDOUT"/></root></log4j:configuration>

4.conf.xml added alias, added db.propreties configuration

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE configuration Public "-//mybatis.org//dtd Config 3.0//en" "Http://mybatis.org/dtd/mybatis-3-config.dtd" > <configuration><properties resource= "Db.properties"/><!--Configuring an alias for an entity class--><typealiases><!- -<typealias type= "Com.atguigu.day03_mybaits.test2.User" alias= "User"/>--><package name= "Com.kpzc.bean "/></typealiases><!--Development: Development mode work: Working mode--><environments default=" development ">< Environment id= "Development" ><transactionmanager type= "JDBC"/><datasource type= "POOLED" >< Property name= "Driver" value= "${driver}"/><property name= "url" value= "${url}"/><property name= "username "Value=" ${name} "/><property name=" password "value=" ${password} "/></datasource></environment ></environments><mappers><!--Write the path to the package where the mapper is located--><mapper resource= "com/kpzc/test1/ Usermapper.xml "/> <mapper resource=" Com/kpzc/test2/usermapper.xml "/><!--<mapper class=" Com.atguigu.day03_mybaits.test3.UserMapper "/><mapper Resource= "Com/atguigu/day03_mybaits/test4/ordermapper.xml"/><mapper resource= "com/atguigu/day03_mybaits/ Test5/classmapper.xml "/><mapper resource=" Com/atguigu/day03_mybaits/test6/classmapper.xml "/><mapper Resource= "Com/atguigu/day03_mybaits/test7/usermapper.xml"/><mapper resource= "com/atguigu/day03_mybaits/ Test8/usermapper.xml "/><mapper resource=" Com/atguigu/day03_mybaits/test9/usermapper.xml "/>--></ Mappers></configuration>

5. Run the query with log output

MyBatis implementing CRUD Operations and Optimizing Code and debugging (MySQL database) (iii)

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.