程序助手

1 国际化

  1. native2ascii -encoding UTF-8 messages_zh_CN.txt messages_zh_CN.properties  
  2. native2ascii -encoding UTF-8 messages_en_US.txt messages_en_US.properties

2 转码

  1. java java.net.URLEncoder.encode(s, "utf-8")
  2. js URLencoder
  3. .net string Name = "中文参数"; Response.Redirect("B.aspx?Name="+Server.UrlEncode(Name));

3 树状菜单

function getChildGroup(obj){
    if($("#ul"+obj)[0]==undefined){
        $.ajax({
                  url: "category.jhtml",
                  data: {"event":"child","uuid":obj},
                  dataType: "json",
                  type: "post",
                  success: function (datas) {
                      var ulEle =  "<ul id='ul"+obj+"'>";
                          $.each(datas, function(i, data){
                                  ulEle += "<li id='"+data.uuid+"' οnclick='getChildGroup(this.id)'>"+data.name+"</li>";
                            })
                      ulEle +="</ul>";
                          $("#"+obj).after(ulEle);
                  }    
              });
        }else if($("#ul"+obj)[0].style.display == 'none'){
            $.ajax({
                  url: "category.jhtml",
                  data: {"event":"child","uuid":obj},
                  dataType: "json",
                  type: "post",
                  success: function (datas) {
                      var ulEle =  "<ul id='ul"+obj+"'>";
                          $.each(datas, function(i, data){
                                  ulEle += "<li id='"+data.uuid+"' οnclick='getChildGroup(this.id)'>"+data.name+"</li>";
                            })
                      ulEle +="</ul>";
                          $("#"+obj).next().replaceWith(ulEle);
                  }    
              });
            $("#ul"+obj).show()
        }else{
            $("#ul"+obj).hide()
        }
    $("#indexRight").html($.ajax({url:"category.jhtml?event=search&uuid="+obj,async:false}).responseText);
    
    var arr = $("tr td:nth-child(1)")
    arr.each(function(i,data){
        if(i>0){            
            data.innerHTML = $("#"+obj).text();
        }
    });
    }

4 分页代码

<input type="submit" name="prePage" value="上一页">
        <#if totalPage &lt; 3>
            <#list 1..totalPage as t>
                <#if t == pageIndex>
                    ${t}<input type="hidden" id="pageIndex" name="pageIndex" value="${t}">
                <#else>
                    <a href="javascript:Asubmit('${t}')">${t}</a>
                </#if>
            </#list>
        <#elseif pageIndex &lt; 3>
            <#list 1..3 as t>
                <#if t == pageIndex>
                    ${t}<input type="hidden" id="pageIndex" name="pageIndex" value="${t}">
                <#else>
                    <a href="javascript:Asubmit('${t}')">${t}</a>
                </#if>
            </#list>
        <#else>
            <#if pageIndex+2 &lt; totalPage>
                <#list 2..1 as t>
                <a href="javascript:Asubmit('${pageIndex-t}')">${pageIndex-t}</a>
                </#list>
                ${pageIndex}<input type="hidden" id="pageIndex" name="pageIndex" value="${pageIndex}">
                <#list 1..2 as t>
                <a href="javascript:Asubmit('${pageIndex+t}')">${pageIndex+t}</a>
                </#list>
            <#else>
                <#list 2..1 as t>
                <a href="javascript:Asubmit('${pageIndex-t}')">${pageIndex-t}</a>
                </#list>
                <#if totalPage = pageIndex>
                    ${pageIndex}<input type="hidden" id="pageIndex" name="pageIndex" value="${pageIndex}">
                <#else>
                    ${pageIndex}<input type="hidden" id="pageIndex" name="pageIndex" value="${pageIndex}">
                    <#list 1..totalPage-pageIndex as t>
                    <a href="javascript:Asubmit('${pageIndex+t}')">${pageIndex+t}</a>
                    </#list>
                </#if>
            </#if>
        </#if>
        共:${totalPage}页
        <input type="submit" name="nextPage" value="下一页"><input type="text" name="goToPage"><input type="submit" name="goTo" value="转向">

5.ibaits like '$name$' 传入时参数前后可拼接%

6.md5 方法

	public static String getPassword(){
		String model = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		StringBuilder sbf = new StringBuilder();
		for(int i = 0;i<6;i++){
			sbf.append(model.charAt((int)(Math.random()*62)));
		}
		return sbf.toString();
	}
	
	public static String md5(String s) {
		char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				'a', 'b', 'c', 'd', 'e', 'f' };
		try {
			byte[] strTemp = s.getBytes();
			MessageDigest mdTemp = MessageDigest.getInstance("MD5");
			mdTemp.update(strTemp);
			byte[] md = mdTemp.digest();
			int j = md.length;
			char str[] = new char[j * 2];
			int k = 0;
			for (int i = 0; i < j; i++) {
				byte byte0 = md[i];
				str[k++] = hexDigits[byte0 >>> 4 & 0xf];
				str[k++] = hexDigits[byte0 & 0xf];
			}
			return new String(str);
		} catch (Exception e) {
			return null;
		}
	}

7.java操作POI所需jar(针对2007以上版本)

xmlbeans2.3.0 dom4j1.6.1

8. java操作图片

        BufferedImage image = ImageIO.read(item.getInputStream());

直接从inputstream获取图片

9.Ant打包

<?xml version="1.0" encoding="UTF-8"?>
<project name="bbb" basedir="." default="source.jar"> 

    <property name="src" location="${basedir}/bbb_source"/>  
    <property name="source" location="${src}/source"></property>
    <property name="cvsroot" value=":pserver:zhangsongwei@192.168.1.107:/aaa"/>  
	<target name="init">
		<delete dir="${src}"/>
		<delete dir="${source}"/>

		<mkdir dir="${src}"/>
		<mkdir dir="${source}"/>

	</target>
	
    <target name="bbb-checkout" depends="init">  
    	<cvspass cvsroot="${cvsroot}" password="zhangsongwei"/>
        <cvs cvsRoot="${cvsroot}" package="bbb/code" dest="${src}"/>  
    </target>  

<!--	<target name="copy" depends="bbb-checkout">-->
	<target name="copy" depends="bbb-checkout">
        <copy todir="${source}">
        	<fileset dir="${src}/bbb/code/common"></fileset>
        </copy>
        <copy todir="${source}">
       		<fileset dir="${src}/bbb/code/platform"></fileset>
        </copy>
        <copy todir="${source}">
        	<fileset dir="${src}/bbb/code/target"></fileset>
        </copy>
        
	</target>
    
    <target name="source.jar" depends="copy">
    	<jar destfile="${source}/bbb.jar" basedir="${source}">
		</jar>
    </target>
</project>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值