MyBatis 使用Generator自动生成Model , Dao, mapper
最近 我新建了一 个maven 项目,使用的是spring + springmvc + mybatis框架。
听说Mybatis可以自动生成model和mapper以及dao层,我就从网上查了查资料,自己试着做一下,其中遇到一 个很麻烦的问题,
就是用dos 命令执行 java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite 时 报出 “前言中不允许有内容
这是因为 用记事本打开xml文件转化为UTF-8会有一个BOM头,所以java在读取时就会报以上错误
解决方法:用notepad++打开,在格式选择“以UTF-8无BOM格式编码”,然后保存, 就可以了。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAboAAACwCAIAAAD2eTwAAAAUuElEQVR4nO3de3BT150HcP+z+YM/9vGHl053puvQdraJM7vbbWh2C52427C7dV2yJXvJtCnY0GxC3RKSJiRbPFRqw8OQBYMTk4U0NBkXEVSCwTaGELAxlo0lbIOx/JKfsmUZ2TJgkO3yvPvHka6O7j26OrJlWT76fuZMxr4+ujpXir6cc699fykTk1PzotnLCgsLiy1DUxOTbktxuT34o9ay4lrXJNleWEi+HqotLqT6qL5NsjYw6JrzMUTTAm/oUG2x/52dspeRt558XVhYGHij6f7zsCX2W+O2FAdfdn8bqi0ua1W+dVmKC9Uv/rx5O6bx4qfM+aB5mstSXGxxT0yS4GMprrUon6jWcs1bGPLZS7aW2J9Jurkt5N0ta52YnLKXFZa1+n+kxKW9rJD8n+CysP9HKKQ+zInfEvatCby8yiTDrbze/k8iOyunEJdo87sl7GcSDW/N/HrxEZfiN3wmE7bhrZlfLz7iUvyGz2TCNrw18+vFR1yioaGhcTXEJRoaGhpXQ1yioaGhcbUUR1c3GhoaGlrEliIDAAAHxCUAABfEJQAAF8QlAAAXxCUAABfEJQAAl5ROAADggNklAAAXxCUAABfEJQAAF8QlAAAXvbg0GAxms5l8bbVas7OztX3MZrPBYKC/lSQplgMEAEgMYePS5/NlZmZ6PB7yrSRJSnTSsrOzrVar8kXEuDQYDJIk+Xy+xYsXpwSkpqYqT6SQJIkO4tlgN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K1H//zX657+q++JP21avtLRTlRP8EcfJDsKLgWZ/ijHtASMC5HR0cbuI2Ojka1c/qXi+KKWlXiUzy7/It0TC1BTcC4BACYDYhLAAAuiEsAAC6ISwAALohLAAAuYsYlSpsBQMyJGZcobQYAMSdgXKK0GQDMBgHjMu6lzfgp93wTiAB//iLAIUBcCBiXcS9txg9xySvk9hdhXjN7VOXMUMUMZkzAuIx7aTN+CRiXCXoniQivVOBPQrnLmaGKGcSAgHEZ99Jm/BCXvHRfKfvMypnhhk4wTQLGZdxLmzHvyhh6M8XgzSIjVi7TL/7FLFvGX8tMtdEYfIppVy7TKwEW8nKF3qA34jo70lJ82uXMUMUMpkvAuIx3aTPG/Ex1G/CIcclf/Ctc2TLOWmbaJ5px5TL9EmCMO6UzK4WFpXO7uumUM0MVM5gBAeMy7qXNNIXJwpXWUT8k8Kgoin+FKyzBV8uMETAzrlwWoQQYPQPX76aZB4d5LSL/gB4o1QNVzGCGBIzLuJc2I6jCZJHjMvxzsrfoJiN/LbOo45KjclmEEmD+vQavYofpFl7YMxhRlTNDFTOYOQHjMt6lzRiFyXQqkYVdjPMV/+KOS3ZdMO0TzbhyWYQSYJqXK1y30J3a2acEQuIxynJmqGIGMyVgXMa9tBmrMJnqgkrESz28xb/44zLMFRXNE820clmEEmCyJhXDdaNRw2BcKmK8FhHKmWlOTaCKGUyDgHGZcKXNxP7FFQHCRIBDgLgQMC4TrrSZ0HEpwF/ECHAIEB8CxmXClTYTNS7N878EmACHAHEkYFwCAMwGxCUAABfEJQAAF8QlAAAXxCUAABfEJQAAF8QlAAAXxCUAABfEJQAAF8QlAACXlN7EIyMuASDxpEwlGMQlACQmxCUAABfEJQAAF8QlAAAXxCUAAJf/B/eOiqKm7+NXAAAAAElFTkSuQmCC" alt="" />
从网上下载这两个jar 包,
generator.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> <classPathEntry location="D:\java\generator\mysql-connector-java-5.1.32.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/smart4j" userId="root" password="root"> </jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver> <javaModelGenerator targetPackage="com.telecom.myshiro.model" targetProject="D:\java\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <sqlMapGenerator targetPackage="com.telecom.myshiro.mapping" targetProject="D:\java\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.telecom.myshiro.dao" targetProject="D:\java\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <table tableName="userinfo" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="s_user" domainObjectName="CourseInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
然后在目录里执行dos命令就可以了。
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
MyBatis 使用Generator自动生成Model , Dao, mapper的更多相关文章
- idea使用generator自动生成model、mapper、mapper.xml(转)
原文链接:http://www.mamicode.com/info-detail-445217.html TEP 0.在Intellij IDEA创建maven项目(本过程比较简单,略) STEP 1 ...
- spring和mybatis集成,自动生成model、mapper,增加mybatis分页功能
软件简介 Spring是一个流行的控制反转(IoC)和面向切面(AOP)的容器框架,在java webapp开发中使用广泛.http://projects.spring.io/spring-frame ...
- springboot和mybatis集成,自动生成model、mapper,增加mybatis分页功能
整体思路和http://www.cnblogs.com/mahuan2/p/5859921.html相同. 主要讲maven的pom.xml和一些配置变化,详细说明. 软件简介 Spring是一个流行 ...
- 使用MyBatis Generator自动生成实体、mapper和dao层
原文链接 通过MyBatis Generator可以自动生成实体.mapper和dao层,记录一下怎么用的. 主要步骤: 关于mybatis从数据库反向生成实体.DAO.mapper: 参考文章:ht ...
- (二十二)SpringBoot之使用mybatis generator自动生成bean、mapper、mapper xml
一.下载mybatis generator插件 二.生成generatorConfig.xml new一个generatorConfig.xml 三.修改generatorConfig.xml 里面的 ...
- MyBatis使用Generator自动生成代码
MyBatis中,可以使用Generator自动生成代码,包括DAO层. MODEL层 .MAPPING SQL映射文件. 第一步: 配置好自动生成代码所需的XML配置文件,例如(generator. ...
- mybatis自定义代码生成器(Generator)——自动生成model&dao代码
花了两天的时间研究了下mybatis的generator大体了解了其生成原理以及实现过程.感觉generator做的非常不错,给开发者也留足了空间.看完之后在generator的基础上实现了自定义的生 ...
- SpringBoot整合Mybatis 使用generator自动生成实体类代码、Mapper代码、dao层代码
1.新建一个SpringBoot项目,并引入Mybatis和mybatis-generator相关的依赖. <dependency> <groupId>org.springfr ...
- mybatis generator.xml 配置 自动生成model,dao,mapping
generator.xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gener ...
随机推荐
- 电商网站垮IDC数据备份,MySql主从同步,图片及其它数据文件的同步
原文网址:http://www.bzfshop.net/article/180.html 对一个电子商务网站而言,最宝贵的资源就是数据.服务器是很廉价的东西,即使烧了好几个也问题不大,但是用户数据如果 ...
- 各种浏览器开启JavaScript脚本方法
各种浏览器开启JavaScript脚本方法 随着网站设计技术的发展,为了用户友好体验,大部分网站使用了JavaScript脚本设计,如果您的浏览器禁用或关闭的JavaScript支持,那么可能造成网站 ...
- Apache自带压力测试工具ab用法简介
ab命令原理 ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL进行访问.它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx.lighthttp ...
- SSM(Maven集成)
ssm全称:Spring+SpringMVC+Mybatis ssm简介: 1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod J ...
- VS2013使用WebDeploy发布网站到IIS服务器
VS2013用Web Deploy方式发布网站到IIS服务器发布文档 VS版本:VS2013 服务器版本:Windows Server 2012 R2 IIS版本:IIS8.0 Web Deploy版 ...
- yum网络源配置
[root@xuegod60 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak[root@x ...
- HDU 2568[前进]模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...
- [html5] 学习笔记-响应式布局
1.响应式布局介绍 响应式布局是2010年5月份提出的一个概念,简而言之,就是一个网站能够兼容多个终端——而不是每一个终端做一个特定的版本.这个概念是为了兼容移动互联网浏览而诞生的,其目的是为用户提供 ...
- (译)AngularJS1.3.0 开发者指南(四) -- 控制器
理解Controllers 在AngularJS中, Controller是一个Javascript构造函数, 常常被用来扩展 Angular Scope 对象. 控制器通过 ng-controlle ...
- PHP接入芝麻信用续。
前面,做好了,PHP查询芝麻信用. 客户又要求说,芝麻官方,发来邮件,还需要提交网站的数据给芝麻, 就是说接入芝麻SDK,还有一步,就是数据反馈. 大概芝麻分就是根据这些反馈的数据来计算的吧. 不多说 ...