好长时间没有写博客了,最近公司要用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. 纯CSS3打造非常炫的加载动画

    纯css3打造的一款非常炫的加载图.用在需要一定时间加载的地方非常合适.先上效果图: 点击这里在线预览 代码非常简单.没有用任何javascript代码.纯css3实现. html代码: <di ...

  2. bootstrap插件(对话框)bootbox参数和自定义弹出框宽度设置

    参考:https://hisune.com/post/view/17/bootstrap-plugin-bootbox-and-custom-width-dialog 官网:http://bootbo ...

  3. C语言 · 计算时间

    算法提高 计算时间   时间限制:1.0s   内存限制:512.0MB      问题描述 给定一个t,将t秒转化为HH:MM:SS的形式,表示HH小时MM分钟SS秒.HH,MM,SS均是两位数,如 ...

  4. Python3 串口模块移植并使用。

    想通过 Python去控制串口模块,直接上层就使用一门语言,这样虽然执行效率低一些,但是开发速度加快 通过 buildroot 先移植 Python-serial 模块 x Symbol: BR2_P ...

  5. JDK自带观察者的使用

    被观察者 package observerForJDK; import java.util.Observable; /** * 新闻派发器,当有新的新闻时派发给所有的订阅读者(观察者) */ publ ...

  6. DCGAN in Tensorflow生成动漫人物

    引自:GAN学习指南:从原理入门到制作生成Demo 生成式对抗网络(GAN)是近年来大热的深度学习模型.最近正好有空看了这方面的一些论文,跑了一个GAN的代码,于是写了这篇文章来介绍一下GAN. 本文 ...

  7. python多线程同步机制Lock

    #!/usr/bin/env python# -*- coding: utf-8 -*- import threadingimport time value = 0lock = threading.L ...

  8. Git 创建操作

    在本章中,我们将看到如何创建一个远程Git仓库,从现在开始,我们将会把它作为Git服务器.我们需要一个的Git服务器允许团队协作. 创建新用户 # add new group [root@CentOS ...

  9. Entity Framework应用:使用EF的DataBase First模式实现数据库的增删改查

    在上一篇文章中讲解了如何生成EF的DBFirst模式,接下来讲解如何使用DBFirst模式实现数据库数据的增删改查 一.新增数据 新增一个Student,代码如下: static void Add() ...

  10. 解决springmvc使用ResponseBody注解返回json中文乱码问题

    spring版本:4.2.5.RELEASE 查看“org.springframework.http.converter.StringHttpMessageConverter”源码,中有一段说明: B ...