Velocity vm模板代码格式问题

vm模板是什么都输出,就是空格也输出,所以要注意这一点,所以参数要顶头写,例如

  <resultMap id="${classname}Map" type="${package}.${moduleName}.entity.${className}">
#foreach($column in $columns)
#if($column.lowerAttrName==$pk.lowerAttrName)
    <id property="${pk.lowerAttrName}" column="${pk.columnName}"/>
#else
    <result property="${column.lowerAttrName}" column="${column.columnName}"/>
#end
#end
  </resultMap>

mapper.xml模板样例格式

<?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">
  #if( "$!subModuleName" != "")
    #set($subModuleNameNew='.'+$subModuleName)
  #end
<mapper namespace="${package}.${moduleName}.mapper.${className}Mapper">

  <resultMap id="${classname}Map" type="${package}.${moduleName}.entity.${className}">
#foreach($column in $columns)
#if($column.lowerAttrName==$pk.lowerAttrName)
    <id property="${pk.lowerAttrName}" column="${pk.columnName}"/>
#else
    <result property="${column.lowerAttrName}" column="${column.columnName}"/>
#end
#end
  </resultMap>
  <sql id="Base_Column_List">
#foreach($column in $columns)
    ${column.columnName}#if($foreach.hasNext),	
#end
#end

  </sql>

  <select id="getPage" parameterType="${package}.${moduleName}.entity.${className}" resultMap="${classname}Map">
	select  
    <include refid="Base_Column_List" />
    from ${tableName}
    <where>
#foreach($column in $columns)
#if($column.lowerAttrName==$pk.lowerAttrName)
      <if test="query.${pk.lowerAttrName} !=null and query.${pk.lowerAttrName} !=''">
          and ${pk.columnName}=#{query.${pk.lowerAttrName}}
      </if>
#else
      <if test="query.${column.lowerAttrName} !=null and query.${column.lowerAttrName} !=''">
          and ${column.columnName}=#{query.${column.lowerAttrName}}
      </if>
#end
#end
    </where>
  </select>
</mapper>

输出格式

<?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="cn.emd.platform.workflow.mapper.ActRuTaskMapper">

  <resultMap id="actRuTaskMap" type="cn.emd.platform.workflow.entity.ActRuTask">
    <id property="id" column="ID_"/>
    <result property="rev" column="REV_"/>
    <result property="executionId" column="EXECUTION_ID_"/>
    <result property="procInstId" column="PROC_INST_ID_"/>
    <result property="procDefId" column="PROC_DEF_ID_"/>
    <result property="taskDefId" column="TASK_DEF_ID_"/>
    <result property="scopeId" column="SCOPE_ID_"/>
    <result property="subScopeId" column="SUB_SCOPE_ID_"/>
    <result property="scopeType" column="SCOPE_TYPE_"/>
    <result property="scopeDefinitionId" column="SCOPE_DEFINITION_ID_"/>
    <result property="propagatedStageInstId" column="PROPAGATED_STAGE_INST_ID_"/>
    <result property="name" column="NAME_"/>
    <result property="parentTaskId" column="PARENT_TASK_ID_"/>
    <result property="description" column="DESCRIPTION_"/>
    <result property="taskDefKey" column="TASK_DEF_KEY_"/>
    <result property="owner" column="OWNER_"/>
    <result property="assignee" column="ASSIGNEE_"/>
    <result property="delegation" column="DELEGATION_"/>
    <result property="priority" column="PRIORITY_"/>
    <result property="createTime" column="CREATE_TIME_"/>
    <result property="dueDate" column="DUE_DATE_"/>
    <result property="category" column="CATEGORY_"/>
    <result property="suspensionState" column="SUSPENSION_STATE_"/>
    <result property="tenantId" column="TENANT_ID_"/>
    <result property="formKey" column="FORM_KEY_"/>
    <result property="claimTime" column="CLAIM_TIME_"/>
    <result property="isCountEnabled" column="IS_COUNT_ENABLED_"/>
    <result property="varCount" column="VAR_COUNT_"/>
    <result property="idLinkCount" column="ID_LINK_COUNT_"/>
    <result property="subTaskCount" column="SUB_TASK_COUNT_"/>
  </resultMap>
  <sql id="Base_Column_List">
    ID_,	
    REV_,	
    EXECUTION_ID_,	
    PROC_INST_ID_,	
    PROC_DEF_ID_,	
    TASK_DEF_ID_,	
    SCOPE_ID_,	
    SUB_SCOPE_ID_,	
    SCOPE_TYPE_,	
    SCOPE_DEFINITION_ID_,	
    PROPAGATED_STAGE_INST_ID_,	
    NAME_,	
    PARENT_TASK_ID_,	
    DESCRIPTION_,	
    TASK_DEF_KEY_,	
    OWNER_,	
    ASSIGNEE_,	
    DELEGATION_,	
    PRIORITY_,	
    CREATE_TIME_,	
    DUE_DATE_,	
    CATEGORY_,	
    SUSPENSION_STATE_,	
    TENANT_ID_,	
    FORM_KEY_,	
    CLAIM_TIME_,	
    IS_COUNT_ENABLED_,	
    VAR_COUNT_,	
    ID_LINK_COUNT_,	
    SUB_TASK_COUNT_
  </sql>

  <select id="getPage" parameterType="cn.emd.platform.workflow.entity.ActRuTask" resultMap="actRuTaskMap">
	select  
    <include refid="Base_Column_List" />
    from ACT_RU_TASK
    <where>
      <if test="query.id !=null and query.id !=''">
          and ID_=#{query.id}
      </if>
      <if test="query.rev !=null and query.rev !=''">
          and REV_=#{query.rev}
      </if>
      <if test="query.executionId !=null and query.executionId !=''">
          and EXECUTION_ID_=#{query.executionId}
      </if>
      <if test="query.procInstId !=null and query.procInstId !=''">
          and PROC_INST_ID_=#{query.procInstId}
      </if>
      <if test="query.procDefId !=null and query.procDefId !=''">
          and PROC_DEF_ID_=#{query.procDefId}
      </if>
      <if test="query.taskDefId !=null and query.taskDefId !=''">
          and TASK_DEF_ID_=#{query.taskDefId}
      </if>
      <if test="query.scopeId !=null and query.scopeId !=''">
          and SCOPE_ID_=#{query.scopeId}
      </if>
      <if test="query.subScopeId !=null and query.subScopeId !=''">
          and SUB_SCOPE_ID_=#{query.subScopeId}
      </if>
      <if test="query.scopeType !=null and query.scopeType !=''">
          and SCOPE_TYPE_=#{query.scopeType}
      </if>
      <if test="query.scopeDefinitionId !=null and query.scopeDefinitionId !=''">
          and SCOPE_DEFINITION_ID_=#{query.scopeDefinitionId}
      </if>
      <if test="query.propagatedStageInstId !=null and query.propagatedStageInstId !=''">
          and PROPAGATED_STAGE_INST_ID_=#{query.propagatedStageInstId}
      </if>
      <if test="query.name !=null and query.name !=''">
          and NAME_=#{query.name}
      </if>
      <if test="query.parentTaskId !=null and query.parentTaskId !=''">
          and PARENT_TASK_ID_=#{query.parentTaskId}
      </if>
      <if test="query.description !=null and query.description !=''">
          and DESCRIPTION_=#{query.description}
      </if>
      <if test="query.taskDefKey !=null and query.taskDefKey !=''">
          and TASK_DEF_KEY_=#{query.taskDefKey}
      </if>
      <if test="query.owner !=null and query.owner !=''">
          and OWNER_=#{query.owner}
      </if>
      <if test="query.assignee !=null and query.assignee !=''">
          and ASSIGNEE_=#{query.assignee}
      </if>
      <if test="query.delegation !=null and query.delegation !=''">
          and DELEGATION_=#{query.delegation}
      </if>
      <if test="query.priority !=null and query.priority !=''">
          and PRIORITY_=#{query.priority}
      </if>
      <if test="query.createTime !=null and query.createTime !=''">
          and CREATE_TIME_=#{query.createTime}
      </if>
      <if test="query.dueDate !=null and query.dueDate !=''">
          and DUE_DATE_=#{query.dueDate}
      </if>
      <if test="query.category !=null and query.category !=''">
          and CATEGORY_=#{query.category}
      </if>
      <if test="query.suspensionState !=null and query.suspensionState !=''">
          and SUSPENSION_STATE_=#{query.suspensionState}
      </if>
      <if test="query.tenantId !=null and query.tenantId !=''">
          and TENANT_ID_=#{query.tenantId}
      </if>
      <if test="query.formKey !=null and query.formKey !=''">
          and FORM_KEY_=#{query.formKey}
      </if>
      <if test="query.claimTime !=null and query.claimTime !=''">
          and CLAIM_TIME_=#{query.claimTime}
      </if>
      <if test="query.isCountEnabled !=null and query.isCountEnabled !=''">
          and IS_COUNT_ENABLED_=#{query.isCountEnabled}
      </if>
      <if test="query.varCount !=null and query.varCount !=''">
          and VAR_COUNT_=#{query.varCount}
      </if>
      <if test="query.idLinkCount !=null and query.idLinkCount !=''">
          and ID_LINK_COUNT_=#{query.idLinkCount}
      </if>
      <if test="query.subTaskCount !=null and query.subTaskCount !=''">
          and SUB_TASK_COUNT_=#{query.subTaskCount}
      </if>
    </where>
  </select>
</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小生有礼了哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值