URLConnection usage example
摘要:1 public static String sendGet(String url, String param) { 2 StringBuilder result = new StringBuilder(); 3 BufferedReader br = null; 4 5 try { 6 Str...
阅读全文
二叉查找树 BinarySearchTree
摘要:package com.datastructure.tree; public class BinarySearchTree> { static class BinaryNode { T data; BinaryNode left; BinaryNode right; public BinaryNode...
阅读全文
JDK源码之AbstractCollection
摘要:public abstract class AbstractCollection implements Collection { /** * Sole constructor. (For invocation by subclass constructors, typically * implicit.) */ protected Abstract...
阅读全文
JDK源码之List
摘要:List<E> extends Collection<E> 1. Query Operation: int size(); boolean isEmpty(); boolean contains(Object o); Iterator<E> iterator(); Object[] toArray(
阅读全文
JDK源码之Collection
摘要:Collection<E> 继承 Iterable<E>, 其中有方法iterator()1. Query Operations: int size(); boolean isEmpty(); boolean contains(Object o); Iterator<E> iterator(); O
阅读全文
迭代器模式 (Iterator)
摘要:迭代器模式(Iterator), Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. (它提供一各方法访问一个
阅读全文
HIbernate工具类
摘要:HibernateUtil.java:package com.zwh.user.util;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;public class HibernateUtil { private static SessionFactory sessionFactory = null; static { sessionFactory = new Configuration().config...
阅读全文
spring mvc 返回内容乱码
摘要:需要Spring 3.1及以上,用produces来控制@RequestMapping(value={"/{name}"}, method=RequestMethod.GET, produces="application/json;charset=utf-8")
阅读全文
Jave Web接收参数乱码
摘要:encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 encodingFilter /*用于解决POST方式造成的中文乱码问题,编码只能被指定一次,即如果客户端设置了编码,则过滤器不会再设置如果是GET,需要修改 Tomcat根式目录的 conf/server.xml文件中,找,在里面加URIEncoding="utf-8"参数乱码分析: 提交表单时request与response对象encoding与con...
阅读全文
spring mvc输出Json数据
摘要:依赖的jar包:jackson-core-asl-1.8.7.jar jackson-mapper-asl-1.8.7.jar org.codehaus.jackson jackson-core-asl 1.9.13 org.codehaus.jackson jackson-mapper-lgpl 1.9.13第一种方式:(ResponseEnity)使用ResponseEnity@Controllerpublic class JSONController { @RequestMapping(value={"/{name}"}, method=Reque...
阅读全文
日期工具
摘要:1. 增加或减少天数publicDate addDay(Date date,int num) { Calendar calendar =Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_MONTH, num); return calendar.getTime();}2. String与Date相互转换 2.1. String → Date: 2.1.1.Date date =newDate(“2014-01-01”); 2.1.2.SimpleDateFormat sdf =newSimpl
阅读全文
随机产生用户名
摘要:privatestaticfinalchar[] enChar =newchar[]{ 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','
阅读全文
Java定时任务
摘要:1. 每天定时0点执行Calendar cal =Calendar.getInstance();//每天0点执行cal.set(Calendar.HOUR_OF_DAY,0);cal.set(Calendar.MINUTE,0);cal.set(Calendar.SECOND,0); newTimer().schedule(newTimerTask() {@Override publicvoid run() { // something to do ... }},cal.getTime(),24*60*60*1000);2. Timer基本用法Timer timer =newTimer();.
阅读全文