闲置暂时

关于SQL注入简单的有三种应对方式:
1.参数替换
List<Map<String, Object>> queryRolesList = new ArrayList<Map<String, Object>>();
		//String sql = "select iRoleId,sRoleName,sRoleDetails,iRoleMode from roletbl where sRoleName like "+"\"%"+ roleName +"%\"";
		//queryRolesList = jdbcTemplate.queryForList(sql);
		String sql = "select iRoleId,sRoleName,sRoleDetails,iRoleMode from roletbl where sRoleName like ?";
		roleName = "%"+roleName+"%";
		queryRolesList = jdbcTemplate.queryForList(sql,roleName);

2.replace之类的正则替换关键字
3.采用存储过程

关于缓存简单的由二种应对方式:
1.服务器启动时将结果放入内存,数据有变化,再跟新内存
2.采用ehcache之类的框架

service层获得request的方法:HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();


public static void main(String[] args) {
Pattern p = Pattern.compile("3-4");//3+4
String s = "3-4";//34
System.out.println(p.matcher(s).matches());
}
Pattern.class->ASCII.class

发扑克牌
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Test {
	
	private static final String FLAG = "THIS";
	
	private static final int PLAYERS = 4;
	
	private static int TOTAL = 0;
	
	private static Map<Integer,String> map = null;
	
	private static List<Integer> list = null;
	
	private static List<Map<Integer,String>> outerList = new ArrayList<Map<Integer,String>>();
	
	private static int outerCount = 0;
	
	public Test(){
		if(map==null){
			map = new HashMap<Integer,String>();
			map.put(0,"方块2");map.put(1,"梅花2");map.put(2,"红桃2");map.put(3,"黑桃2");
			map.put(4,"方块3");map.put(5,"梅花3");map.put(6,"红桃3");map.put(7,"黑桃3");
			map.put(8,"方块4");map.put(9,"梅花4");map.put(10,"红桃4");map.put(11,"黑桃4");
			map.put(12,"方块5");map.put(13,"梅花5");map.put(14,"红桃5");map.put(15,"黑桃5");
			map.put(16,"方块6");map.put(17,"梅花6");map.put(18,"红桃6");map.put(19,"黑桃6");
			map.put(20,"方块7");map.put(21,"梅花7");map.put(22,"红桃7");map.put(23,"黑桃7");
			map.put(24,"方块8");map.put(25,"梅花8");map.put(26,"红桃8");map.put(27,"黑桃8");
			map.put(28,"方块9");map.put(29,"梅花9");map.put(30,"红桃9");map.put(31,"黑桃9");
			map.put(32,"方块10");map.put(33,"梅花10");map.put(34,"梅花0");map.put(35,"方块0");
			map.put(36,"方块J");map.put(37,"梅花J");map.put(38,"红桃J");map.put(39,"黑桃J");
			map.put(40,"方块Q");map.put(41,"梅花Q");map.put(42,"红桃Q");map.put(43,"黑桃Q");
			map.put(44,"方块K");map.put(45,"梅花K");map.put(46,"红桃K");map.put(47,"黑桃K");
			map.put(48,"方块A");map.put(49,"梅花A");map.put(50,"红桃A");map.put(51,"黑桃A");
			map.put(52,"小鬼");map.put(53,"大鬼");
			TOTAL = map.size();
			list = new ArrayList<Integer>();
			for (int i = 0; i < TOTAL; i++) {
				list.add(i);
			}
		}else{
			map.clear();
		}
	}

	public static void main(String[] args) throws Exception {
		sendCard();
		theWarMachine();
	}
	
	/**人机对战阶段*/
	public static void theWarMachine(){
		System.out.println("开始人机对战。。。");
		System.out.println("一共有4堆牌,您要选择哪堆牌?(1/2/3/4)");
		String receive1 = playerInput("[1234]","请输入正确的序号!");
		//开始对牌进行排序并创建出牌流程
		System.out.println("是否对牌进行排序?(1:是;2:否)");
		String receive2 = playerInput("[12]","请输入正确的序号!");
		if(receive2.equals("1")){
			System.out.println("您的牌为:"+orderCard(outerList.get(Integer.parseInt(receive1)-1)));
		}else{
			System.out.println("您的牌为:"+outerList.get(Integer.parseInt(receive1)-1));
		}
		//TODO 人机智能处理阶段
	}
	
	/**派牌阶段*/
	public static void sendCard(){
		Test t = new Test();
		for (int i = 0; i < PLAYERS; i++) {
			t.addThread();
		}
		System.out.println("正在派牌中,请稍等。。。");
		while(true){
			if(outerCount==PLAYERS){
				/**
				//这个是cheat代码。。。
				for (int i = 0; i < outerList.size(); i++) {
					System.out.println(outerList.get(i));
				}
				*/
				System.out.println("派牌结束");
				break;
			}
		}
	}
	
	/**随机发牌*/
	public void addThread(){
		Map<Integer,String> innerMap = new HashMap<Integer,String>();
		new Thread(){
			@Override
			public void run(){
				synchronized (FLAG) {
					while(innerMap.size()<TOTAL/PLAYERS){
						int random = (int)(Math.random()*list.size());
						innerMap.put(list.get(random),map.get(list.get(random)));
						list.remove(random);
					}
					outerCount++;
				}
			}
		}.start();
		outerList.add(innerMap);
	}
	
	/**玩家输入阶段*/
	public static String playerInput(String regexRule,String errorMessage){
		@SuppressWarnings("resource")
		Scanner s = new Scanner(System.in);
		String out = "";
		while(true){
			out = s.next();
			if(out.matches(regexRule)){
				//s.close();
				return out;
			}else{
				System.out.println(errorMessage);
			}
		}
	}
	
	/**给牌排序*/
	public static Map<Integer,String> orderCard(Map<Integer,String> map){
		//TODO
		return map;
	}

}


简单生成随机密码
public class Test {
	
	//密码长度
	private static final int CODE_LENGTH = 25;
	
	//随机密码字符集
	private static final String CHARACTER_SET = "1234567890qwertyuioplkjhgfdsazxcvbnm"
									   + "QWERTYUIOPLKJHGFDSAZXCVBNM"
									   + "`-=~!@#$%^&*()_+;':\\\"[]{},./<>?\\|"; 
	
	//记录上次生成的随机数
	private static int lastRandomRecord = 0;
	
	public static void main(String[] args){
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < CODE_LENGTH; i++) {
			sb.append(CHARACTER_SET.charAt(coreCalBySelf(lastRandomRecord, getRandom())));
		}
		System.out.println(sb);
	}
	
	//得到随机数
	public static int getRandom(){
		return (int)(Math.random()*CHARACTER_SET.length());
	}
	
	//简单自定义密码生成策略算法(简单平滑化数字、字母和符号出现的概率)
	public static int coreCalBySelf(int iold,int inew){
		if(Math.abs(iold-inew)<CHARACTER_SET.length()/2){
			inew = inew+CHARACTER_SET.length()/10;
			if(inew>CHARACTER_SET.length()){
				inew = CHARACTER_SET.length()+iold-inew;
			}
		}
		lastRandomRecord = inew;
		return inew;
	}
	
}


得到相关节点:document.querySelectorAll('*[head]')
[]/*Array.prototype*/.forEach.call(document.querySelectorAll('*'), function(element) {}

你可能感兴趣的:(JavaScript)