欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

freemarker自定义宏和Function

程序员文章站 2024-03-22 09:53:40
...

隐位操作

<#-- 姓名的隐位操作-->
<#macro implicit_name name>
    <#if name !=''>
        <#--${name}-->
       <#-- ${name?replace(name?substring(name?length-1),"*")}-->
        <#if name?length gt 3>
            <#--${"**"+name?substring(1,name?length-1)}-->
            ${name?substring(0,2)+(name?substring(2))?replace("[\\u4e00-\\u9fa5-^\\w+$]",'*','r')}
        <#else>
            ${name?substring(0,1)+(name?substring(1))?replace("[\\u4e00-\\u9fa5-^\\w+$]",'*','r')}
        </#if>
    <#else>
        ${name}
    </#if>
</#macro>
<#-- 身份证的隐位操作 -->
<#macro implicit_ids ids>
    <#if ids !=''>
        <#--${ids?replace(ids?substring(ids?length-4),"****","r")}-->
        ${ids?substring(0,3)+"************"+ids?substring(ids?length-3)}
    <#else>
        ${ids}
    </#if>
</#macro>
<#-- 手机号的隐位操作 -->
<#macro implicit_phone phone>
    <#if phone!=''>
        <#--${phone?replace(phone?substring(phone?length-4),"****","r")}-->
        ${phone?substring(0,3)+"******"+phone?substring(9)}
    <#else>
        ${phone}
    </#if>
</#macro>
<#-- 邮箱的隐位操作 -->
<#macro implicit_email email>
    <#if email!=''>
        <#if email?index_of('@')==-1>
            ${email}
        <#else>
            ${email?substring(0,2)+"***"+email?substring(email?index_of('@')-1)}
        </#if>
    <#--${phone?replace(phone?substring(phone?length-4),"****","r")}-->
    <#else>
        ${email}
    </#if>
</#macro>
<#-- 输入框使用的方法 -->
<#function implicit value index>
    <#-- 如果传入的是空字符 -->
    <#if value==''>
       <#return ''>
    </#if>
    <#if index == 1>
        <#-- 姓名 -->
        <#if value?length gt 3>
            <#return value?substring(0,2)+(value?substring(2))?replace("[\\u4e00-\\u9fa5-^\\w+$]",'*','r')>
        <#else>
            <#return value?substring(0,1)+(value?substring(1))?replace("[\\u4e00-\\u9fa5-^\\w+$]",'*','r')>
        </#if>
    <#elseif index==2>
        <#-- 身份证 -->
        <#return value?substring(0,3)+"*************"+value?substring(value?length-3)>
        <#--<#return value?substring(0,value?length-4)+"****">-->
    <#elseif index==3>
        <#-- 手机号 -->
        <#return value?substring(0,3)+"******"+value?substring(9)>
    <#elseif index==4>
        <#-- 支付宝、易付宝账号 -->
        <#return "****"+value?substring(value?length-4)>
    <#elseif index==5>
        <#-- 银行卡号 -->
        <#return value?substring(0,6)+"****"+value?substring(value?length-4)>
    <#elseif index==6>
        <#-- 地址隐位 -->
        <#if value?length gt 5>
            <#return "****"+value?substring(value?length-6)>
        <#else>
            <#return "****"+value>
        </#if>
    <#else>
        <#return value>
    </#if>
</#function>
<#import "common/implicit_bit.ftl" as implicit_bit>

姓名:<@implicit_bit.implicit_name name="${(customerManagerList.name)!''}" />                            
	${implicit_bit.implicit((loanCustomer.name)!'',1) } 
	if(name !== null || name !== undefined || name !== ''){
		$("#name").val("");
	}else{
		$("#name").val(name.replace(name.substring(name.length-1),"*"));	
	}
	
手机号:<@implicit_bit.implicit_phone phone="${(customerManagerList.custMobile)!''}" />
       ${implicit_bit.implicit((loanCustomer.mobile)!'',3)}
	   mobile.substring(0,3)+"******"+mobile.substring(mobile.length-2)
	   
	   
身份证:<@implicit_bit.implicit_ids ids="${(customerManagerList.ids)!''}" />                    
		${implicit_bit.implicit((loanCustomer.ids)!'',2)}
		
支付宝账号  
	${implicit_bit.implicit((loanCustomer.zhifubaoNo)!'',4)}
银行卡号
	${implicit_bit.implicit((loanCustomer.zhifubaoNo)!'',5)}
地址:
	${implicit_bit.implicit((customerWorkInfo.workAddressDetail)!'',6)}

把括号里面的值替换就可以使用

相关标签: freemarker 前端