mybatis****
程序员文章站
2022-04-17 17:33:29
...
Maven方法
1.加入相应的pom的jar包
-
<dependency>
-
<groupId>org.mybatis.generator</groupId>
-
<artifactId>mybatis-generator-core</artifactId>
-
</dependency>
2.idea****插件
-
<build>
-
<finalName>noodle-mybatis</finalName>
-
<plugins>
-
<plugin>
-
<groupId>org.mybatis.generator</groupId>
-
<artifactId>mybatis-generator-maven-plugin</artifactId>
-
<version>1.3.2</version>
-
<configuration>
-
<configurationFile>src/main/resources/mybatis/mybatis-generator.xml</configurationFile>
-
<verbose>true</verbose>
-
<overwrite>true</overwrite>
-
</configuration>
-
</plugin>
-
</plugins>
-
</build>
3.属性文件
-
jdbc.driverClass=com.mysql.jdbc.Driver
-
jdbc.connectionURL=jdbc:mysql://127.0.0.1:3306/websocket?useUnicode=true&characterEncoding=utf8
-
jdbc.userId=root
-
jdbc.password=welcome
-
jdbc.driverLocation=E:\\coding\\flxlib\\mysql-connector-java-5.1.35.jar
4.配置文件
-
<?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>
-
<!--导入属性配置-->
-
<properties resource="mybatis/generator.properties"/>
-
<!--数据库驱动,最好不要有中文字符,不然会找不到-->
-
<classPathEntry location="${jdbc.driverLocation}"/>
-
-
<context id="testTables" targetRuntime="MyBatis3">
-
-
<commentGenerator>
-
<!-- 是否去除自动生成的注释 true:是 : false:否-->
-
<property name="suppressDate" value="true"/>
-
<property name="suppressAllComments" value="true"/>
-
</commentGenerator>
-
<!--数据库链接地址账号密码-->
-
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
-
<jdbcConnection driverClass="${jdbc.driverClass}"
-
connectionURL="${jdbc.connectionURL}"
-
userId="${jdbc.userId}"
-
password="${jdbc.password}">
-
</jdbcConnection>
-
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
-
NUMERIC 类型解析为java.math.BigDecimal -->
-
<javaTypeResolver>
-
<property name="forceBigDecimals" value="false"/>
-
</javaTypeResolver>
-
<!-- targetProject:生成PO类的位置 -->
-
<javaModelGenerator targetPackage="com.flx.noodle.mybatis.entity" targetProject="src/main/java">
-
<!-- enableSubPackages:是否让schema作为包的后缀 -->
-
<property name="enableSubPackages" value="false"/>
-
<!-- 从数据库返回的值被清理前后的空格 -->
-
<property name="trimStrings" value="true"/>
-
</javaModelGenerator>
-
<!-- targetProject:mapper映射文件生成的位置 -->
-
<sqlMapGenerator targetPackage="com.flx.noodle.mybatis.entity" targetProject="src/main/java">
-
<property name="enableSubPackages" value="false"/>
-
</sqlMapGenerator>
-
<!-- targetPackage:mapper接口生成的位置 -->
-
<javaClientGenerator type="XMLMAPPER" targetPackage="com.flx.noodle.mybatis.dao" targetProject="src/main/java">
-
<property name="enableSubPackages" value="true"/>
-
</javaClientGenerator>
-
<!--生成对应表及类名,需要记住的一点是****无法生成关联关系,只能生成单表操作-->
-
<table tableName="ws_user" domainObjectName="WsUser"/>
-
<table tableName="ws_room" domainObjectName="WsRoom"/>
-
-
</context>
-
</generatorConfiguration>
-
package com.flx.noodle.mybatis.generator;
-
-
import org.mybatis.generator.api.MyBatisGenerator;
-
import org.mybatis.generator.config.Configuration;
-
import org.mybatis.generator.config.xml.ConfigurationParser;
-
import org.mybatis.generator.internal.DefaultShellCallback;
-
-
import java.io.File;
-
import java.util.ArrayList;
-
import java.util.List;
-
-
/**
-
* Created by fenglixiong on 2017/10/22.
-
*/
-
public class GeneratorMain {
-
-
public static void main(String[] args) {
-
try {
-
generator();
-
System.out.println("successful!!!");
-
} catch (Exception e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
}
-
}
-
-
public static void generator() throws Exception{
-
List<String> warnings = new ArrayList<String>();
-
boolean overwrite = true;
-
//项目根路径不要有中文,我的有中文,所以使用绝对路径
-
File configFile = new File("E:\\coding\\BeefNoodle\\noodle-mybatis\\src\\main\\resources\\mybatis\\mybatis-generator.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);
-
}
-
-
}
6.tomcat配置
java工程
github地址
https://github.com/zhangwei2github/MybatisGenerator.git
下一篇: 人脸识别和关键点检测