IDEA+spring boot+Mybatis 连接数据库反向生成实体类
2018-08-31 12:19
519 查看
原文地址:https://www.jianshu.com/p/0e1a362ceff3
1.添加mybatis generator插件,在pom.xml文件中 plugins 节点下添加以下内容
[code]<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.7</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> </plugin>
2.在src/main/resources目录下新建generatorConfig.xml文件,与上一点中 configurationFile 节点中的路径一致。xml内容如下:
[code]<?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> <!--sql 连接数据库jar 注意路径--> <classPathEntry location="C:\\Users\\FYY\\.m2\\repository\\com\\microsoft\\sqlserver\\mssql-jdbc\\6.2.2.jre8\\mssql-jdbc-6.2.2.jre8.jar" /> <context id="testTables" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!- 4000 -数据库连接的信息:驱动类、连接地址、用户名、密码 --> <jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://localhost:1433;DatabaseName=KSBQC17" userId="sa" password="testline"> </jdbcConnection> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型(PO)的包名和位置 --> <javaModelGenerator targetPackage="com.cosber.vehicleprint.entity" targetProject="src/main/java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="main.resources.mapping" targetProject="src"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.cosber.vehicleprint.dao" targetProject="src/main/java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> <table tableName="HSPASS" domainObjectName="TablePrint" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
3.菜单 View - Tool Window - Maven Projects,调出 Maven Projects窗口
4.创建运行项目(这里直接双击运行也可以)
5.运行上一步创建的运行项(完成)
阅读更多
相关文章推荐
- 用idea搭建spring boot+mybatis及反向生成框架
- Intellij IDEA springboot maven 配置mybatis-generator,自动从数据库中生成代码
- SpringBoot建立数据库连接JdbcTemplate和Mybatis两种方式
- idea中怎样连接数据库同时生成实体类
- SpringBoot + Mybatis实体类属性与数据库表列名对应规则
- spring-boot集成mybatis问题1:IntellijIdea中j解决自动生成代码xml配置文件中出现“uri is not registered”问题
- Spring Boot MyBatis 连接数据库
- springboot + mybatis 多数据源配置 数据库与实体类映射(驼峰命名法)
- SpringBoot - MyBatis 连接数据库
- 在Idea中连接数据库并生成实体类
- SpringBoot实践之---Mybatis连接数据库(mybatis-generator-plugin)
- Spring Boot通过Mybatis,使用mapper接口和xml配置sql,连接数据库
- 在IDEA中连接数据库并生成实体类
- Shiro学习(二) 基于SpringBoot连接数据库与配置MyBatis
- Spring boot通过JPA和Mybatis同时连接2个关系数据库的例子
- Mac下intellij idea 连接数据库并利用hibernate反向生成实体类
- 关于idea SpringBoot项目中出现与数据库连接加载不到驱动类异常
- Spring Boot MyBatis 连接数据库
- SpringBoot学习日志之DAY_03数据库连接之MYBATIS
- SpringBoot实践之---JPA连接数据库+idea全新创建该工程