Month: July 2011

[Linux]shell程序中会用到的一些简单命令

set ignoreeof: 打开ignoreeof这个开关 set history = 50: 将history变量的值设置为50 set: 显示当前所有的shell变量 echo hello world: 显示"hello world" echo $shell: 显示"shell"变量的值 setenv TERM vt100: 把环境变量TERM设为vt100 (bash下可以用export) printenv TERM: 显示环境变量TERM的值 printenv: 显示所有的环境变量 history: 最近输入过的命令 alias uic=’echo ubuntu is cool’: 为’echo ubuntu is cool’定义别名:uic

[Linux]常用小命令

date: 显示当前时间 cal: 显示日历 ( cal 11 2011,显示Nov 2011的日历) uptime: 系统已经运行多久了 hostname:当前主机名 whoami:当前用户 man: 显示关于某个命令的帮助信息,如man ls whatis: 简单概括一个命令的作用 man -k: 搜索命令的名字,如man -k edit 可以搜出vi, vim apropos: 同man -k find ./ -name ".svn" | xargs rm -rf : 删除本目录及子孙目录下所有*.svn文件 find . -name "*.php" -print | xargs sed -i ‘s/foo/bar/g’ : 在所有*.php文件中查找"foo"并全部替换成"bar"

[Linux]Shell下的热键

^H: 删除输入的最后的字符 ^W: 删除输入的最后的单词 ^U: 删除整行 ^C: 中止当前程序 ^S: 暂停当前程序(如显示一个大文件) ^Q: 继续当前程序 ^M: 回车=Enter ^J: 换行不回车

Generate all the setter invocation statements of a javabean

private static void generateSetters(Class<?> clazz) { Method[] methods = clazz.getMethods(); for (Method m : methods) { if (m.getName().startsWith(“set”) && m.getParameterTypes().length == 1){ System.out.println(“bean.” + m.getName() + “(\”abc\”);”); } } } will print: bean.setName(“abc”); bean.setUserId(“abc”); You can put it inside eclipse as a code template: ${:import(java.lang.reflect.Method)} public static void main(String args[]) { Class<?> clazz = ${Bean}.class; …

Generate all the setter invocation statements of a javabean Read More »

[Struts2 Convention] 禁止Convention的UnknownHandler

Convention提供了一个UnknownHandler。如果系统按命名习惯或者Annotation都找不到Action,就会用这个UnknownHandler再去web下或者classpath下找出一个Action 这个Handler不应该用。正式系统里的Action是严肃的,要么按命名习惯推导出,要么用Annotation显式定义好,不能随便乱找 所以,要禁掉这个Handler. 办法分两步: 1.自己写一个空的Handler public class MyUnknownHandler implements UnknownHandler { @Override public ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException { return null; } @Override public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig actionConfig, String resultCode) throws XWorkException { return null; } @Override public Object handleUnknownActionMethod(Object action, String methodName) throws NoSuchMethodException { return null; } } …

[Struts2 Convention] 禁止Convention的UnknownHandler Read More »

[Struts2 Convention] 如果Result文件不在web下或classpath下,怎么办?

作为View的Result文件,如freemarker文件,不一定放在web目录里面,也没放在classpath下 这时候还能用Convention插件吗? 答案是:可以。解决方案分为两步:   1. 自定义 "struts.convention.resultMapBuilder" 在你自定义的resultMapBuilder中,你要根据action的路径去其对应的View目录中搜得所有View文件,然后将这些文件交给Convention Plugin处理 下面是一个参考实现: public class MyResultMapBuilder extends DefaultResultMapBuilder { @Override protected void createFromResources(Class<?> actionClass, Map<String, ResultConfig> results, String resultPath, String resultPrefix, String actionName, PackageConfig packageConfig, Map<String, ResultTypeConfig> resultsByExtension) { // 找到本action对应的View目录 // //其中getTemplateRootDir()是你的view文件的根目录 File actionTemplateDir = new File(getTemplateRootDir(), flatResultLayout ? resultPath : resultPrefix); // 列出该目录中所有的View文件 Collection<File> actionTemplates = …

[Struts2 Convention] 如果Result文件不在web下或classpath下,怎么办? Read More »

[Ehcache] timeToLive 和 timeToIdle 的意义

转自: http://www.coderanch.com/t/508779/ORM/java/Ehcache-TimeToLiveSecond-TimeToIdleSeconds timeToLiveSecond is the time in seconds from the point of creation in the cache till it expires (regardless of how frequently it is accessed in that time) timeToIdleSeconds is the time in seconds before an object in the cache expires if it is not accessed.