代码在项目中的应用


StringBuilder的应用

        StringBuilder sb = new StringBuilder();
	
			
	        List<CcUserItem> cis=checkitem(ccUser,ccUserItemService,ccuserjoinitemService);
	         int i = 0;
            for (CcUserItem c : cis) {
                if(StringUtil.isFine(c.getItemurl())&&!c.getItemurl().equals("#")){
                  
                    if(c.getId()==10){
                        sb.append("<li><a icon='/file/logo/x52.png' href='" + c.getItemurl()
                                + "' target='navTab' rel='s" + i + "' id='s" + i
                                + "'>" + c.getItem() + "</a></li>");
                    }
                    else if(c.getId()==17){
                        sb.append("<li><a icon='/file/logo/playlist-icon.png' href='" + c.getItemurl()
                                + "' target='navTab' rel='s" + i + "' id='s" + i
                                + "'>" + c.getItem() + "</a></li>");
                    }
                
                sb.append("<li><a icon='/file/logo/x5"+i+".png' href='" + c.getItemurl()
                        + "' target='navTab' rel='s" + i + "' id='s" + i
                        + "'>" + c.getItem() + "</a></li>");
                i++;
                }
            }


返回给页面用的代码:
ModelAndView mav = new ModelAndView();
mav.setViewName("/menu");

          mav.addObject("encryptedconnection", sb.toString());

         return mav;


随机数加日期作为:加密key、keyid

  Date date=new Date();
        SimpleDateFormat key=new SimpleDateFormat("hhmmss");
        String autokey=RandomNum.createRandomString(5)+key.format(date);


获取IP所在地:导入包: commons-geoip

 GeoEntry geoEntry = GeoipService.getInstance().lookup(pu.getIP());
            String isp=geoEntry.getIsp();
            String province=geoEntry.getProvince();

java过滤掉非法字符:

// 过滤特殊字符
	public   static   String StringFilter(String   str)   throws   PatternSyntaxException   {   
                // 只允许字母和数字		
                // String   regEx  =  "[^a-zA-Z0-9]";                   
                   // 清除掉所有特殊字符
		  String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
		  Pattern   p   =   Pattern.compile(regEx);   
		  Matcher   m   =   p.matcher(str);   
		  return   m.replaceAll("").trim();   
		  }   
	@Test	    
	public    void   testStringFilter()   throws   PatternSyntaxException   {   
		  String   str   =   "*adCVs*34_a _09_b5*[/435^*&城池()^$$&*).{}+.|.)%%*(*.中国}34{45[]12.fd'*&999下面是中文的字符¥……{}【】。,;’“‘”?";   
		  System.out.println(str);   
		  System.out.println(StringFilter(str));   
		  }  


你可能感兴趣的:(StringBuilder,应用)