好长时间没有写博客了,最近公司要用java语言,开始学习java,属于初学者,今天主要记录一下mybatis generator自动生成代码,首先在如下图的目录中新建两个文件,如下图

generatorConfig.xml and jdbc.properties都要放在resource根目录下

具体generatorConfig.xml内容如下:

  1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <!DOCTYPE generatorConfiguration
  3.  
    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4.  
    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5.  
    <generatorConfiguration>
  6.  
    <properties resource="jdbc.properties"></properties>
  7.  
    <classPathEntry location="${dbconfig.sqlServer.driverLocation}" />
  8.  
     
  9.  
    <context targetRuntime="MyBatis3">
  10.  
     
  11.  
    <!--<commentGenerator>
  12.  
    <!– 去除自动生成的注释 –>
  13.  
    <property name="suppressAllComments" value="true" />
  14.  
    </commentGenerator>-->
  15.  
    <!-- 是否生成注释 去除自动生成的注释-->
  16.  
    <commentGenerator>
  17.  
    <property name="suppressDate" value="true"/>
  18.  
     
  19.  
    <property name="suppressAllComments" value="true"/>
  20.  
    </commentGenerator>
  21.  
    <!-- 数据库连接配置 -->
  22.  
    <jdbcConnection driverClass="${dbconfig.sqlServer.driverClasss}"
  23.  
    connectionURL="${dbconfig.sqlServer.ssmDemo.read.jdbcUrl}"
  24.  
    userId="${dbconfig.sqlServer.username}"
  25.  
    password="${dbconfig.sqlServer.password}" />
  26.  
     
  27.  
    <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
  28.  
    <javaTypeResolver>
  29.  
    <property name="forceBigDecimals" value="false"/>
  30.  
    </javaTypeResolver>
  31.  
     
  32.  
    <!--配置生成的实体包
  33.  
    targetPackage:生成的实体包位置,默认存放在src目录下
  34.  
    targetProject:目标工程名
  35.  
    -->
  36.  
    <javaModelGenerator targetPackage="com.pojo"
  37.  
    targetProject="src/main/java" />
  38.  
     
  39.  
    <!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
  40.  
    <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources" />
  41.  
    <!--生成Dao类存放位置-->
  42.  
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.dao" targetProject="src/main/java">
  43.  
    <property name="enableSubPackages" value="true"/>
  44.  
    </javaClientGenerator>
  45.  
    <!--生成对应表及类名-->
  46.  
    <!-- 配置表
  47.  
    schema:不用填写
  48.  
    tableName: 表名
  49.  
    enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
  50.  
    去除自动生成的例子
  51.  
    -->
  52.  
    <table schema="" tableName="UzaiSupplierStore" domainObjectName="UzaiSupplierStore" enableCountByExample="false" enableSelectByExample="false"
  53.  
    enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
  54.  
    </table>
  55.  
    <table schema="" tableName="UzaiCountry" enableCountByExample="false" enableSelectByExample="false"
  56.  
    enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
  57.  
    </table>
  58.  
     
  59.  
    </context>
  60.  
    </generatorConfiguration>

 jdbc.properties内容如下

dbconfig.sqlServer.driverClasss=com.microsoft.sqlserver.jdbc.SQLServerDriver
dbconfig.sqlServer.ssmDemo.read.jdbcUrl=jdbc:sqlserver://127.0.0.1;DatabaseName=Travel
dbconfig.sqlServer.username=uzai_trip
dbconfig.sqlServer.password=Flzx3qC!$
#定义初始连接数
dbconfig.initialSize=0
#定义最大连接数
dbconfig.maxActive=20
#定义最大空闲
dbconfig.maxIdle=20
#定义最小空闲
dbconfig.minIdle=1
#定义最长等待时间
dbconfig.maxWait=60000
dbconfig.sqlServer.driverLocation=C:/Users/zd69155/Documents/mssql-jdbc-6.3.0.jre7-preview.jar
C:/Users/zd69155/Documents/mssql-jdbc-6.3.0.jre7-preview.jar这个地址一定是在本地下载好这个jar包的地址
可以添加下面的dependency下载SQLjdbc jar包

<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.0.jre7-preview</version>
<scope>test</scope>
</dependency>

jdbc.properties的参数是对应generatorConfig.xml里面的,如下图

 

然后就是需要配置pom.xml

以上配置完成以后,点run弹出如下界面

mybatis-generator:generate -e

如果碰到这样的错误 “The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed. ClientConnectionId:972101e7-9ee5-4004-9abc-e0e932b921bd"

可以尝试

mybatis-generator:generate -Djdk.tls.client.protocols=TLSv1.2

以上都配置以后点击运行就可以生成了

目前发的生成的dao文件名字是Mapper,还有就是生成的数据库类没有中文注释,大多数解决方案是mysql数据库。关于sqlserver还在进一步了解中

idea中mybatis generator自动生成代码配置 数据库是sqlserver的更多相关文章

  1. SpringBoot 添加mybatis generator 自动生成代码插件

    自动生成数据层代码,提高开发效率 1.pom添加插件,并指定配置文件路径 <!-- mybatis generator 自动生成代码插件 --> <plugin> <gr ...

  2. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

  3. IDEA Maven Mybatis generator 自动生成代码

    IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...

  4. IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)

    IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...

  5. 使用Mybatis Generator自动生成代码

    MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为所有版本的MyBatis以及版本2.2.0之后的iBATIS版本生成代码.它将内省数据库 ...

  6. IDEA使用mybatis generator自动生成代码

    主要就三步: 1.pom 文件中引入jar包并配置 build 属性 <dependencies> <!-- 自动生产mapper Begin! --> <depende ...

  7. MyBatis Generator自动生成的配置及使用

    注意:文件名不能有中文字符,不然不能自动生成 找到MyBatis Generator.rar\MyBatis Generator\eclipse里的features和plugins文件,把这两个文件复 ...

  8. 在IDEA中使用MyBatis Generator自动生成代码

    转载自 https://blog.csdn.net/hua_faded/article/details/78900780 一.配置Maven pom.xml 文件 在pom.xml增加以下插件:   ...

  9. Mybatis generator 自动生成代码(2)

    最近准备开始做一个项目,需要开始手动创建sql,于是将Mybatis generator 工具功能强化了下. 首先,这里引入到版本一点的包 <dependency> <groupId ...

随机推荐

  1. [转]详解Oracle高级分组函数(ROLLUP, CUBE, GROUPING SETS)

    原文地址:http://blog.csdn.net/u014558001/article/details/42387929 本文主要讲解 ROLLUP, CUBE, GROUPING SETS的主要用 ...

  2. Parquet

     Parquet是列式存储格式的一种文件类型,列式存储有以下的核心优势: 可以跳过不符合条件的数据,只读取需要的数据,降低IO数据量压缩编码可以降低磁盘存储空间,由于同一列的数据类型是一样的,可以使用 ...

  3. ORA-12705 解决方法

    问题:创建Oracle数据库出现ORA-12705:Cannot access NLS data files or invalid environment specified. 环境:重置系统,无Or ...

  4. logback的日志文件中出现大量的ESC符号

    如下图: 这个日志文件是用less命令打开的,然后看到就惊呆了,日志文件乱成这样的. 开始我以为是我把logback的配置文件弄错了,还看了半天pattern. 然后百度了一下,找了这篇博客: htt ...

  5. Android——黑名单管理

    DBHelper.java package com.example.chenshuai.test; import android.content.Context; import android.dat ...

  6. idea mac快捷键

    mac快捷键 alt+f7查找变量方法使用的地方 F3添加书签 Ctrl + O快捷覆写方法 Alt + F3 添加书签标识 command + F3 显示书签 command + Shift + A ...

  7. 【C】——C语言字符串比较函数

    c语言字符串函数详解 void *memset(void *dest, int c, size_t count); 将dest前面count个字符置为字符c. 返回dest的值. void *memm ...

  8. SpringBoot 中 @RequestBody的正确使用方法

    SpringBoot 中 @RequestBody的正确使用方法 最近在接收一个要离职同事的工作,接手的项目是用SpringBoot搭建的,其中看到了这样的写法: @RequestMapping(&q ...

  9. Urllib3 库详解

    文档:http://urllib3.readthedocs.io/en/latest/

  10. R语言合并data.frame

    Merging Data Adding Columns To merge two data frames (datasets) horizontally,  use the merge functio ...