Step by step Mybatis-Skip tedious configuration-Mybatis configuration file generation tool (7)

Source: Internet
Author: User

We must understand and know the following information:


At last, david. mbg is the XML to be configured today. MBG generates the configuration file..

<ClassPathEntry>=> The location where the jdbc driver package is stored. You can use a relative path or an absolute path. In this example, the relative path is used.

<Context>=> Corresponding to the configuration of all tables in a database, there can be multiple context, one configuration for mysql and one configuration for oracle.

<Context>Nodes mainly include:

<CommentGenerator>=> Generate nodes by annotation. The two subnodes in this example are represented by table shards.

<JdbcConnection>=> Database connection configuration information

<JavaTypeResolver>=> Converts the decimal and numberic types in jdbc to java. math. BigDeciaml for representation.

<SqlMapGenerator >=>

<JavaClientGenerator >=> configure to generate the corresponding interface class, which corresponds to a series of CRUD method SQL statements in Mapper. xml

<Table >=> configure the corresponding database, which indicates that the domain Class Name (that is, the object class name) is to be generated. In this Example, all unnecessary Example generation information is disabled.

All the above information can be viewed on the official website or downloaded from my files. The corresponding configuration instructions and application examples are provided. Download document

  After configuring the above information, what is the last step? We just need to run this script file. There are four official instructions: first through the command line, second, all three are generated through tools such as Ant or Maven, and the last one is generated through Java code. Here we use the Java barley generation method. Add a script Generation Method to the DemoRun class as follows:

<String> warnings = ArrayList <String> overwrite = File ("./src/david/mbg/mbg_configuration.xml" = "Mybatis generated successfully! "Script Generation Method

After running the job, Refresh the project and you will find that the following magic helps you generate the main configuration, in the red box section:

Finally, let's use the automatically generated results. We can refer to the method in the first six chapters and add the corresponding CRUD test method in DemoRun as follows:

= Session. getMapper (VisitorMapper. = "hello2" "helloworld2@qq.com" count = testGenerateQuery (= session. getMapper (VisitorMapper. = 1 testGenerateDelete (= session. getMapper (VisitorMapper. count = testGenerateUpdate (= session. getMapper (VisitorMapper. = (name. contains ("update" 0, name. indexOf ("update" + "update" count =CRUD Test Method

Run the test program and the result is displayed.

Do you feel that using this improves your efficiency? You don't have to worry about complicated configuration. At least you don't have to perform repetitive unnecessary steps, let the tools do this. ^ 0 ^. Of course, in actual use, we may need to modify the corresponding class information and Interface Information name after generation, of course, these workloads are not too much. I hope this content will be helpful to the configuration personnel.

Download the source code of the Mybatis series of Use Cases

Download MybatisGenerator Use Case source code

Related Article

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.