标签:conf drive sch snapshot schema bat 字符编码 das jdk
1.pom.xml文件中的配置
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.edu.xcu</groupId>
<artifactId>mybatis_generator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!--更改jdk默认版本,解决字符编码问题-->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- mybatis依赖 -->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.2</version>
</dependency>
<!-- 数据库驱动依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 使用maven插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
2.更新项目
3./src/main/resources文件夹下创建generatorConfig.xml
4.配置generatorConfig.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="context1" targetRuntime="MyBatis3"> <!-- 1 链接到数据库的信息 --> <jdbcConnection connectionURL="jdbc:mysql://localhost:3306/xcxy"<!--数据库名--> driverClass="com.mysql.jdbc.Driver" password="" userId="root" /> <!-- 2 配置实体类包 --> <javaModelGenerator targetPackage="cn.edu.xcxy.entity" targetProject="./src/main/java" /> <!-- 3 如果产生映射文件,放置在那里 --> <sqlMapGenerator targetPackage="cn.edu.xcxy.mapper" targetProject="./src/main/resources" /> <!-- 4 Mapper(注解)
注解版本:ANNOTATEDMAPPER
XML版本:XMLMAPPER
混合版本:MIXEDMAPPER
-->
<javaClientGenerator
targetPackage="cn.edu.xcxy.mapper"
targetProject="./src/main/java" type="ANNOTATEDMAPPER" />
<!-- 5 读取那张表 -->
<table schema="xcxy" tableName="t_type"></table>
<table schema="xcxy" tableName="t_book"></table>
</context>
</generatorConfiguration>
5.右键点击项目名——>Run As——>Run Configurations——>Maven Build——>New——>选择workspace为当前项目 Goals:mybatis-generator:generate ——>Run
标签:conf drive sch snapshot schema bat 字符编码 das jdk
原文地址:https://www.cnblogs.com/yangs-blog/p/11487162.html