Mybatis3 generator sqlserver 配置详解及应用工具 下载

php中文网
发布: 2016-06-07 15:41:18
原创
2212人浏览过

这是mybatis3 generator 配置文件,包括了主要的配置参数,具体的配置说明请在文章结尾处下载 完整的配置应用。 应用是基于myeclipse的java应用。 文章中的MBG指的就是MybatisGenerator这个工具。 ?xml version=1.0 encoding=UTF-8 ? !DOCTYPE generatorConf

这是mybatis3 generator 配置文件,包括了主要的配置参数,具体的配置说明请在文章结尾处下载 完整的配置应用。

应用是基于myeclipse的java应用。

文章中的MBG指的就是MybatisGenerator这个工具。

 











 


 
   
 

 
 
        connectionURL="${connectionURL}"
    userId="${userId}" password="${password}" />
   
   
   
     
   

   
   
   
   
   
   
   
   
      
   


   

 

 

因为需要 eclipse3.6以上 才能运行mybatis插件,所以使用cmd方式运行,采用了.bat方式 直接双击运行即可。

强烈建议将属性文件中各个路径些为绝对路径,但不包括包。

如果需要使用,请修改properties处的属性文件的具体路径。

 

------------------------------------------------------------------------------------------------------------------------------------------------------------

上面的方式使用cmd命令来运行mybatis generator,其实apache 提供了更方便的方法。即支持java文件的main入口来读取Generator配置文件。

下面是它的代码: 

package util;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

public class MyBatisGeneratorTool {
	public static void main(String[] args) {
		List<String> warnings = new ArrayList<String>();
		boolean overwrite = true;//是否覆盖原来的文件
		String genCfg = "/generatorConfig.xml";//配置文件的名称
		File configFile = new File(MyBatisGeneratorTool.class.getResource(genCfg).getFile());//用当前类MyBatisGeneratorTool的加载器来加载 注意路径是java项目名/bin/作为根路径
		System.out.println(configFile.getAbsolutePath());
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = null;
		try {
			config = cp.parseConfiguration(configFile);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XMLParserException e) {
			e.printStackTrace();
		}
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = null;
		try {
			myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
		} catch (InvalidConfigurationException e) {
			e.printStackTrace();
		}
		try {
			myBatisGenerator.generate(null);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
登录后复制


 这样更加简单和方便。

Med-PaLM
Med-PaLM

来自 Google Research 的大型语言模型,专为医学领域设计。

Med-PaLM 221
查看详情 Med-PaLM

发现的问题: 如果对一个表多次生成,表mapper.xml不会覆盖,而是以追加的方式。所以记住每次生成前线删除掉对应的表mapper.xml文件,其他生成的文件没有该问题.

 ---------------------------------------------------------------------------------------------------------------------------------------------

mybatis generator 自动生成分页:

项目里已经集成了分页插件,是在工具生成的时候,添加分页内容到各自的mapper.xml文件中,并为mapper.java追加了 selectByPage方法。

实际上比较原来的生成的结果,仅仅是在 mapper.xml文件中追加了:

<resultMap id="selectPageResult" extends="BaseResultMap" type="com.cnofe.base.vo.BaseUser" >
    <!--
<association property="" column="" javaType="">
   <id column="" property="" jdbcType="" />
   <result column="" property="" jdbcType="" />
 </association>
-->
  </resultMap>
  <sql id="select_by_page_outter_where_sql" >
      <if test="oredCriteria.size>0">     <if test="_parameter != null" > <include refid="Example_Where_Clause"/> </if>    and   </if>  <if test="oredCriteria.size==0">     where   </if> 
  </sql>
  <sql id="select_by_page_inner_where_and_orderby_sql" >
      <if test="oredCriteria.size>0">     <if test="_parameter != null" > <include refid="Example_Where_Clause"/> </if>  </if>   <if test="orderByClause != null">    order by ${orderByClause}   </if> 
  </sql>
  <sql id="select_by_page_outter_orderby_sql" >
       <if test="orderByClause != null">    order by ${orderByClause}   </if> 
  </sql>
  <select id="selectPage" resultMap="selectPageResult" parameterType="com.cnofe.base.vo.BaseUserExample" >
    select a.* from base_user a where a.user_id in 
 (select top ${pageSize} user_id from base_user 
<include refid="select_by_page_outter_where_sql"/> 
user_id not in (select top ${skipRecordCount} user_id from base_user  
<include refid="select_by_page_inner_where_and_orderby_sql"/> 
 ) 
<include refid="select_by_page_outter_orderby_sql"/> 
 )
  </select>
登录后复制


 Mybatis3 generator sqlserver 配置详解及应用工具 下载

 

 

mybatis生成工具 是myeclipse里的Java应用:

 http://115.com/file/be93a63d 测试通过!!!。

 

Mybatis3 generator 官方文档

http://www.mybatis.org/generator/index.html

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号