动软生成Java Mybatis Mapper.xml模版和Mapper.java模版代码

动软生成Java Mybatis Mapper.xml模版代码

<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
	 
	TableHost host = (TableHost)(Host);	
	string modelName="YyLampblack";
	 
	host.NameSpace="com.hbsystem.dao.mapper."+modelName+"Mapper";
	 
	string ResultType="com.hbsystem.dao.domain."+modelName;
#>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="<#= host.NameSpace #>">  
   

    <!-- 查询所有信息 -->
    <select id="getListPage" resultType="<#= ResultType #>" >
        select * from <#= host.TableName #> where 1=1 
         <if test="key != null and key != ''">
          and   (key like CONCAT('%',#{key},'%') )
      </if>
      
        order by <# for(int i=0;i< host.Keys.Count;i++){   ColumnInfo key = host.Keys[i]; #><# if (key.IsPrimaryKey || !key.IsIdentity){#><#= key.ColumnName#>  desc <# if (i< host.Keys.Count-1 ) {#>, <#}#><#}#><# }#> limit #{startIndex},#{pageSize}
    </select>
    
    <select id="getListPageCount" resultType="int" >
          select count(0) from <#= host.TableName #>  where 1=1 
         <if test="key != null and key != ''">
         and   (key like CONCAT('%',#{key},'%') )
      </if>
    </select>
    
    <insert id="add" parameterType="<#= ResultType #>" useGeneratedKeys="true" keyProperty="<# if(host.Keys.Count>0){ColumnInfo key = host.Keys[0]; #><# if (key.IsPrimaryKey || !key.IsIdentity){#><#=key.ColumnName#><#}#><# }#>"> 
    <selectKey keyProperty="<# if(host.Keys.Count>0){ColumnInfo key = host.Keys[0]; #><# if (key.IsPrimaryKey || !key.IsIdentity){#><#=key.ColumnName#><#}#><# }#>" order="AFTER" resultType="int">
      SELECT LAST_INSERT_ID()
    </selectKey>
    INSERT INTO <#= host.TableName #> (<# for(int i=1;i< host.Fieldlist.Count;i++) {   ColumnInfo c = host.Fieldlist[i]; if (!c.IsIdentity) {#><#= c.ColumnName#><# if (i< host.Fieldlist.Count-1 ) {#>,<#}#><#}}#>) VALUES (<# for(int i=1;i< host.Fieldlist.Count;i++) {   ColumnInfo c = host.Fieldlist[i]; if (!c.IsIdentity) {#> #{<#= c.ColumnName#>} <# if (i< host.Fieldlist.Count-1 ) {#>,<#}#><#}}#>);
 
    </insert>
    
    
     <update id="update" parameterType="<#= ResultType #>" >
       update <#= host.TableName #>  set <# for(int i=1;i< host.Fieldlist.Count;i++) {   ColumnInfo c = host.Fieldlist[i]; if (!c.IsIdentity) {#><#= c.ColumnName#>=#{<#= c.ColumnName#>}<# if (i< host.Fieldlist.Count-1 ) {#>,<#}#><#}}#> where <# if(host.Keys.Count>0){ColumnInfo key = host.Keys[0]; #><# if (key.IsPrimaryKey || !key.IsIdentity){#><#=key.ColumnName#>=#{<#=key.ColumnName#>}<#}#><# }#> 
    </update> 
    
    
   <delete id="del">
    delete from <#= host.TableName #>  where <# if(host.Keys.Count>0){ColumnInfo key = host.Keys[0]; #><# if (key.IsPrimaryKey || !key.IsIdentity){#><#=key.ColumnName#>=#{<#=key.ColumnName#>}<#}#><# }#> 
  </delete>
    
    <select id="getModel" resultType="<#= ResultType #>" >
        select * from <#= host.TableName #> where <# if(host.Keys.Count>0){ColumnInfo key = host.Keys[0]; #><# if (key.IsPrimaryKey || !key.IsIdentity){#><#=key.ColumnName#>=#{<#=key.ColumnName#>}<#}#><# }#>  order by <# for(int i=0;i< host.Keys.Count;i++){   ColumnInfo key = host.Keys[i]; #><# if (key.IsPrimaryKey || !key.IsIdentity){#><#= key.ColumnName#>  desc <# if (i< host.Keys.Count-1 ) {#>, <#}#><#}#><# }#> limit 0,1
    </select>
</mapper>

动软生成Java Mybatis Mapper.java模版代码

<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
	 
	TableHost host = (TableHost)(Host);	
	host.NameSpace = "com.hbsystem.dao.mapper";
	string modelSpace="com.hbsystem.dao.domain";
	string modelName="YyLampblack";
#>

package <#= host.NameSpace #>;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import <#= modelSpace #>.<#= modelName #>;

 
public interface <#= modelName #>Mapper {
	public List<<#= modelName #>> getListPage(@Param("key")String key,   @Param("startIndex")int startIndex, @Param("pageSize")int pageSize);
	public int getListPageCount(@Param("key")String key);
	public int add(<#= modelName #> model);
	public int update(<#= modelName #> model);
	public int del(<#= CodeCommon.GetInParameter(host.Keys, false) #>);
	public <#= modelName #> getModel(<#= CodeCommon.GetInParameter(host.Keys, false) #>);
}



© 2016-2024 阿尔佛 aerfo.com | 豫ICP备17044542号 | 豫公网安备 41010602000172