标签:org tps run inf jdb 技术 schema gre book
项目架构
pom文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.1.11.RELEASE</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.bjsxt</groupId> 12 <artifactId>e-book-product-provider</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <name>e-book-product-provider</name> 15 <description>e-book-product-provider</description> 16 17 <properties> 18 <java.version>1.8</java.version> 19 <spring-cloud.version>Greenwich.SR4</spring-cloud.version> 20 </properties> 21 22 <dependencies> 23 <dependency> 24 <groupId>org.springframework.boot</groupId> 25 <artifactId>spring-boot-starter-web</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>org.mybatis.spring.boot</groupId> 29 <artifactId>mybatis-spring-boot-starter</artifactId> 30 <version>2.1.1</version> 31 </dependency> 32 33 <!--数据库驱动坐标--> 34 <dependency> 35 <groupId>mysql</groupId> 36 <artifactId>mysql-connector-java</artifactId> 37 </dependency> 38 39 <dependency> 40 <groupId>org.springframework.cloud</groupId> 41 <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> 42 </dependency> 43 44 <dependency> 45 <groupId>com.bjsxt</groupId> 46 <artifactId>e-boot-product-server</artifactId> 47 <version>0.0.1-SNAPSHOT</version> 48 </dependency> 49 50 <dependency> 51 <groupId>org.springframework.boot</groupId> 52 <artifactId>spring-boot-starter-test</artifactId> 53 <scope>test</scope> 54 </dependency> 55 </dependencies> 56 57 <dependencyManagement> 58 <dependencies> 59 <dependency> 60 <groupId>org.springframework.cloud</groupId> 61 <artifactId>spring-cloud-dependencies</artifactId> 62 <version>${spring-cloud.version}</version> 63 <type>pom</type> 64 <scope>import</scope> 65 </dependency> 66 </dependencies> 67 </dependencyManagement> 68 69 <build> 70 <plugins> 71 <plugin> 72 <groupId>org.springframework.boot</groupId> 73 <artifactId>spring-boot-maven-plugin</artifactId> 74 </plugin> 75 <!--配置Generator插件--> 76 <plugin> 77 <groupId>org.mybatis.generator</groupId> 78 <artifactId>mybatis-generator-maven-plugin</artifactId> 79 <version>1.3.5</version> 80 <dependencies> 81 <dependency> 82 <groupId>mysql</groupId> 83 <artifactId>mysql-connector-java</artifactId> 84 <version>5.1.38</version> 85 </dependency> 86 </dependencies> 87 88 <!--指定配置文件的路径--> 89 <configuration> 90 <configurationFile>${project.basedir}/src/main/resources/generatorConfig.xml</configurationFile> 91 <verbose>true</verbose> 92 <overwrite>true</overwrite> 93 </configuration> 94 </plugin> 95 </plugins> 96 97 <!--配置资源拷贝插件--> 98 <resources> 99 <resource> 100 <directory>src/main/java</directory> 101 <includes> 102 <include>**/*.xml</include> 103 </includes> 104 </resource> 105 106 <resource> 107 <directory>src/main/resources</directory> 108 <includes> 109 <include>**/*.yml</include> 110 <include>**/*.properties</include> 111 </includes> 112 </resource> 113 </resources> 114 </build> 115 116 117 </project>
其中起关键作用的是<build></build>部分
放入插件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="testTables" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--数据库连接的信息:驱动类、连接地址、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/book-order" userId="root" password="root"> </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.bjsxt.pojo" targetProject=".\src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- targetProject:mapper映射文件生成的位置 --> <sqlMapGenerator targetPackage="com.bjsxt.mapper" targetProject=".\src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- targetPackage:mapper接口生成的位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.bjsxt.mapper" targetProject=".\src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 指定数据库表 --> <table schema="" tableName="orders"></table> </context> </generatorConfiguration>
需要注意的是这几个地方
根据个人需求修改数据库连接地址,以及用户名和密码
使用逆向工程生成pojo类的项目存放位置
生成mapper文件的存放位置
生成mapper接口文件的存放位置
数据库的表名,注意别写错了
标签:org tps run inf jdb 技术 schema gre book
原文地址:https://www.cnblogs.com/sakura-yxf/p/12019359.html