Rumah  >  Artikel  >  pangkalan data  >  Mybatis3 generator sqlserver 配置详解及应用工具 下载

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

WBOY
WBOYasal
2016-06-07 15:41:181822semak imbas

这是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();
		}
	}
}</string></string>


 这样更加简单和方便。

发现的问题: 如果对一个表多次生成,表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"></include> </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"></include> </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"></include> 
user_id not in (select top ${skipRecordCount} user_id from base_user  
<include refid="select_by_page_inner_where_and_orderby_sql"></include> 
 ) 
<include refid="select_by_page_outter_orderby_sql"></include> 
 )
  </select>


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

 

 

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

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

 

Mybatis3 generator 官方文档

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

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn