当前位置:网站首页>MBG combat zero basis
MBG combat zero basis
2022-07-04 10:53:00 【Eric%258436】
** If there is a mistake , Thank you for correcting **
If there is a mistake , Thank you for correcting , Please send a private message to the blogger , There is a red envelope for hard work , Worship “ one-word teacher ”.
Please find the paragraphs you need according to the table of contents
Introduction : This blog is organized for individuals Java Learning notes , If there is a mistake , Thank you for correcting . System learning , Welcome to continue to pay attention , Follow up updates
Java communication qq Group 383245788
This article aims to learn and communicate , personal crud The learning
This paper makes a lot of references MBG Official website :http://mybatis.org/generator/
MBG Doing it ssm Small demo Can be used when , convenient ,MP You can also do , And do better ,MBG It is suggested to just understand .
MBG brief introduction
MyBatis Generator (MBG) yes MyBatis Code generator for . It will be for all versions of MyBatis The generated code . It will introspect a database table ( Or more tables ) And generate artifacts that can be used to access tables . This reduces the initial hassle of setting up objects and configuration files to interact with database tables .MBG Try to be simple about a lot CRUD( establish 、 retrieval 、 to update 、 Delete ) Has a significant impact on database operations . You still need to write... For connection queries or stored procedures SQL And object code .
MBG Generate code in different styles and languages , It depends on how it is configured . for example ,MBG Can generate Java or Kotlin Code .MBG Can generate and MyBatis3 Compatible XML - Although it is now considered MBG Legacy uses . Newer styles of generated code do not need XML.
xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="DB2Tables" targetRuntime="Mybatis3">
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/ssm_mdsp"
userId="root"
password="root">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- Appoint javaBean The location of the generation -->
<javaModelGenerator targetPackage="top.atluofu.pojo"
targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- Appoint sql Map where the file is generated -->
<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- Appoint dao Where the interface is generated ,mapper Interface -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="top.atluofu.mapper" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- table Specify the generation strategy for each table -->
<table tableName="order" domainObjectName="Order">
</table>
<table tableName="role" domainObjectName="Role">
</table>
<table tableName="trade" domainObjectName="Trade">
</table>
<table tableName="user" domainObjectName="User">
</table>
</context>
</generatorConfiguration>
xml Reference configuration
- classPathEntry: Specify drive
Such as <classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />- commentGenerator: Commenter , Generate annotations , As noted in the table , Column comment , Time stamps, etc
Start class
Use xml Configure from Java The program runs MBG
public class MBG {
@Test
public static void main(String[] args) throws XMLParserException, IOException, InvalidConfigurationException, SQLException, InterruptedException {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("src/main/resources/mbg.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);
}
}
边栏推荐
- Design and common methods of test case documents
- [Galaxy Kirin V10] [desktop] printer
- VI text editor and user rights management, group management and time management
- Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
- Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
- Write a program to judge whether the two arrays are equal, and then write a similar program to compare the two vectors.
- Dichotomy search (C language)
- Write a program to judge whether the elements contained in a vector < int> container are 9.20: exactly the same as those in a list < int> container.
- Canoe test: two ways to create CAPL test module
- From programmers to large-scale distributed architects, where are you (2)
猜你喜欢

Article publishing experiment

TS type gymnastics: illustrating a complex advanced type

Canoe - the second simulation project -xvihicle1 bus database design (operation)
![[Galaxy Kirin V10] [server] NUMA Technology](/img/9b/65466c6fc6336e27e842f50c26b9c3.jpg)
[Galaxy Kirin V10] [server] NUMA Technology
![[Galaxy Kirin V10] [desktop] can't be started or the screen is black](/img/68/735d80c648f4a8635513894c473860.jpg)
[Galaxy Kirin V10] [desktop] can't be started or the screen is black

Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
![[Galaxy Kirin V10] [server] KVM create Bridge](/img/a4/a35a276d13e194cefc547607c59f00.jpg)
[Galaxy Kirin V10] [server] KVM create Bridge

How to use diff and patch to update the source code
![[Galaxy Kirin V10] [server] system partition expansion](/img/49/5d3e28eab45d300bd5695e47b35e6b.jpg)
[Galaxy Kirin V10] [server] system partition expansion

Four characteristics and isolation levels of database transactions
随机推荐
RHCE day 3
Performance test process
Regular expression
For and while loops
Seven examples to understand the storage rules of shaped data on each bit
Canoe: the difference between environment variables and system variables
Jemeter plug-in technology
Write a program to judge whether the elements contained in a vector < int> container are 9.20: exactly the same as those in a list < int> container.
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing
Appscan installation steps
Canoe - description of common database attributes
Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
Application and Optimization Practice of redis in vivo push platform
Canoe - the second simulation project -xvihicle1 bus database design (operation)
Recursive method to achieve full permutation (C language)
[Galaxy Kirin V10] [desktop] login system flash back
First article
[Galaxy Kirin V10] [desktop] printer
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology