接上一篇:CRM-首页功能实现
自动生成User、UserDao和映射文件
1. 新建Module
- 打开上一篇的mycrm项目,在当前项目File–>New–>Module
- 不勾选Create from archetype
- 路径和mycrm项目一致
2. 配置
2.1 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>crm-mybatis-generator</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.2 generator.properties
jdbc.driverLocation是你的本地仓库下面mysql的jar包
jdbc.driverLocation=C:/MySoftware/maven/repository_shine/mysql/mysql-connector-java/5.1.43/mysql-connector-java-5.1.43.jar
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql://localhost:3308/myssm?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
2.3 generatorConfig.xml
- 引入数据库的配置文件
2. context标签
3. 配置数据库连接的<jdbcConnection> 4. 配置实体类存放路径
- 配置XML存放路径
- dao存放路径和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>
<properties resource="generator.properties"/>
<classPathEntry location="${jdbc.driverLocation}"/>
<context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection
driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.connectionURL}"
userId="${jdbc.username}"
password="${jdbc.password}">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<javaModelGenerator targetPackage="com.lyx.settings.domain"
targetProject="C:/MyLearningFiles/JavaWeb-Learning/mycrm/src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="constructorBased" value="false"/>
<property name="trimStrings" value="true"/>
<property name="immutable" value="false"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.lyx.settings.mapper"
targetProject="C:/MyLearningFiles/JavaWeb-Learning/mycrm/src/main/java">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator
targetPackage="com.lyx.settings.mapper"
targetProject="C:/MyLearningFiles/JavaWeb-Learning/mycrm/src/main/java"
type="XMLMAPPER">
</javaClientGenerator>
<table tableName="tbl_user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
3. 自动生成User、UserDao和映射文件
- 双击Plugins下的mybatis-generator
2. 查看
|