In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
When using mybatis, a large number of mapping mapping files need to be written, and manual writing is heavy and error-prone. Fortunately, Mybatis-Generator can be used to help us generate these files automatically and greatly improve the efficiency of development.
1. Preparatory work
Download mybatis-generator 's jar package from https://github.com/mybatis/generator/releases
Download the database driver package from http://www.grepcode.com.
Create the following structure directory:
2.generator.xml introduction
Before generating related files, you need to configure the configuration file with any name and suffix xml. (attribute-related explanations are available in xml. If you don't understand them, you can try to see how the effect is different.)
3. Running
There are four types of operations: command generation (the simplest), Java generation, ant generation, and maven generation. The first two are mentioned here. If you are interested, you can learn the rest on the mybatis website.
1) Open the cmd command window, cd to the working directory, and run the following command
The file path of the java-jar mybatis-generator package-the file path of configfile generator.xml-overwrite command.
This example is:
Java-jar mybatis-generator-core-1.3.2.jar-configfile generator.xml-overwrite
Output when successful: MyBatis Generator finished successfully.
2) java generation
List warnings = new ArrayList ()
Boolean overwrite = true
File configFile = new File ("generatorConfig.xml")
ConfigurationParser cp = new ConfigurationParser (warnings)
Configuration config = cp.parseConfiguration (configFile)
DefaultShellCallback callback = new DefaultShellCallback (overwrite)
MyBatisGenerator myBatisGenerator = new MyBatisGenerator (config, callback, warnings)
MyBatisGenerator.generate (null)
In fact, Java operation, subdivision can be divided into two kinds, and one can go to the official website to learn.
4. Effect.
After generating the code, according to your actual project architecture, you can make appropriate changes to the generated code, such as handing over database management to spring and so on.
5. Pay attention
1) generator.xml format: must be encoded in UTF-8 BOM-free format and converted by notepad++.
2) pay attention to the availability of the database package, invalid database package conversion will report an error.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.