·鱼·骨头
fish8077 · 共 14 篇文章
行转列
select customid, count(case status when 0 then status else null end) as status-0, count(case status when 1 then status else null end) as status-1, count(case status when 2 then status else null end) as status-2 from custom group by customid.
2011-07-19 13:42 · 评论(0)
ServletContextListener 介绍
在Servlet API中有一个ServletContextListener接口,它能够监听ServletContext对象的生命周期,实际上就是监听Web应用的生命周期。 当Servlet容器启动或终止Web应用时,会触发ServletContextEvent事件,该事件由 ServletContextListener 来处理。在 ServletContextListener 接口中定义了处理ServletContextEvent事件的两个方法。 contextInitialized(ServletContextEvent sce):当Servlet容器启动Web应用时调用该方法。在调用完…
2011-07-19 10:30 · java · 评论(0)
Struts控制流程
一、ActionServlet的初始化 ActionServlet作为Struts组件的前端控制器,由于web.xml的相应配置: 0 在应用一加载时即会被实例化并调用其init方法,init方法所做的主要工作有二: 加载struts配置文件,并创建用于封装配置信息的ModuleConfig对象 加载资源文件,并创建用于封装资源文件的MessageResources对象 需要注意两点:如果web.xml有多模块配置,将创建多个ModuleConfig对象和MessageResources对象分别用于封装各个模块的struts配置文件和资源文件。 针对各个模块所创建的ModuleConfig对…
2011-07-15 15:02 · 评论(0)
不用第三个变量,交换两个数
public void swap(int a, int b) { a = a + b; b = a - b; a = a - b; System.out.println("a="+a); System.out.println("b="+b); }
2011-07-15 14:57 · java · 评论(0)
递归返回N的二进制中1的个数
方法1: public static int getBinary(int num) { if (0==num) { return 0; } else { if (0==num%2) { return getBinary(num/2); } else { return getBinary(num/2)+1; } } } 方法2: public static int getBinary(int num) { if (0==num) { return 0; } else { if (0==num%2) { return getBinary(num>>1); } else { return getB…
2011-06-14 10:34 · java · 评论(0)
一些常用的JS方法
出来工作几年了, 一直没养成备份知识的习惯, 要用了直接百度. 留个备份,免得麻烦! 获取地址的参数 function search(param) { var re=new RegExp("[&,?]"+param+"=[^\\&]*","i"); var str=re.exec(document.location.search); if(str == null || str=="" || str.length==0){ return ""; } else { str = str+""; str = str.split("=")[1]; return str; } } input type=…
2011-04-07 09:58 · javascript · 评论(0)
乐观锁和悲观锁
所谓悲观锁就是基于数据库机制实现的。比如在在使用select子句的时候加上for update,那么直到改子句的事务结束为止,任何应用都无法修改select出来的记录。 所谓乐观锁是基于应用的版本机制来实现的。一般会在表里面设计一个版本字段v(我一般会把这个字段设为timestamp)。一般的update场景是这样: 1 select a, v from tb where id=1; 假设得到数据是: 2 update tb set a='yyyy', v=systimestamp where v=11111; //注意, v一般不会在业务操作的时候修改 这要求每一次update操作都变更版…
2011-03-03 15:38 · hibernate · 评论(0)
ClassPathXmlApplicationContext 和FileSystemXmlApplicationContext的区别
classpath: 前缀是不需要的, 默认就是指项目的classpath路径下面; 如果要使用绝对路径,需要加上 file: 前缀表示这是绝对路径; 对于FileSystemXmlApplicationContext: 默认表示的是两种: 1,没有盘符的是 项目工作路径, 即项目的根目录; 2,有盘符表示的是 文件绝对路径。 如果要使用classpath路径, 需要前缀 classpath: . public class Test { public static void main(String[] args) { // Resource resource = new ClassPathR…
2011-03-01 14:09 · spring · 评论(0)
10进制字符串的转换
最近面试的时候老碰到10进制字符串的转换的问题,例如:"012345"-->"012346","999999"-->"000000"。 public class Test { public static void main(String[] args) { System.out.println(convert("012345")); } // "012345"-->"012346" public static String convert(String num) { StringBuffer sb = new StringBuffer(""); char[] cs = num.toCharA…
2011-02-23 11:00 · java · 评论(0)
数组法求30的阶乘
public class Test { public static void main(String[] args) { int[] sum = new int[50]; // 用来保存值 sum[1] = 1; //个位数为1(初始值) int w = 1; // 位数 // 求30的阶乘 for (int i = 1; i <= 30; i++) { // 每一位都要乘上当前的阶乘 for (int j = 1; j <= w; j++) { sum[j]*=i; } // 进位 for (int j = 1; j <= w; j++) { // 如果是最高位,判断是否要进位 if (j…
2011-02-23 10:25 · java · 评论(0)
利用QQ去获得来访者的IP和省市
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>获取ip地址</title> <!-- 需要转码 --> <script language="javascript" src="http://fw.qq.com/ipaddress" charset="gb2312"></script> <script type="text/javascript"> function test(){ // ip地址 alert(IPData[0]); // 省份 alert(IPD…
2011-02-22 11:45 · javascript · 评论(0)
编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串
最近挺火的一道面试题。 public class Test { public static void main(String[] args) { String str = "汉字ABD不是ABC"; System.out.println(splitStr(str, 8)); } // 判断是不是汉字 public static boolean isCh(char c) { String temp = String.valueOf(c); return temp.getBytes().length>1?true:false; } // 获取字符串的字节数 public static int g…
2011-02-22 11:13 · java · 评论(0)
如何写一个不需要main方法的java应用程序?
可以使用静态代码块来实现一个可以执行但并没有main方法的Java应用程序。如下面的代码是所示: class MainMethodNot { static { System.out.println("This java program have run without the run method"); System.exit(0); } } 上面的代码可以运行是因为static代码块会在java类被加载的时候被执行,而且是在main方法被调用之前。在运行时,JVM会在执行静态代码块以后搜索main方法,如果不能找到main方法,就会抛出一个异常,为了避免这个异常,可以使用System.ex…
2011-02-22 10:40 · java · 评论(1)
如何得到Java应用程序的可用内存?
public class MemoryExp { public static void main(String[] args) { System.out.println("Total Memory"+Runtime.getRuntime().totalMemory()); System.out.println("Free Memory"+Runtime.getRuntime().freeMemory()); } }
2011-02-22 10:38 · java · 评论(0)