Eclipse代码模板编辑

相信大家都用过Eclipse的缩写代码提示功能,如syso能补全为System.out.println();main能补全为完整的main方法,非常的方便。同时,我们也能自己编辑模板,提高自己的代码写作速度。

编辑方法 window >> Perferences >> Java >> Editor >> Templates >> New..
具体的内容各位看官可以参照里面已有的模板,自己编写适合自己的模板。
下面我写的一个DAO模板,供参考

logger.info("enter into ${enclosing_method} of ${enclosing_type} ");
if () {
logger.error(" ${enclosing_method} of ${enclosing_type}'s parameter is invalid");
throw new ParameterException();
}
logger.info("${enclosing_method} of ${enclosing_type}'s parameter is " + ${enclosing_method_arguments});
${return_type} result = null;
Session session = null;
try {
session = HibernateTemplate.getInstance().getSession();
Transaction tx = session.beginTransaction();

tx.commit();
} catch (Exception e) {
logger.error("Exception in ${enclosing_method} is ", e);
throw new DAOException();
} finally {
HibernateTemplate.close();
}
logger.info("left ${enclosing_method} of ${enclosing_type}, result is " + result);
return result;


另贴上自己总结的一些变量的含义,方便大家自定义。
"collection" = 最后一个集合类型的实参名(例:(List alist, List blist),结果显示为blist)
"date" = 月 日,年(Nov 5, 2009)
"enclosing_method" = 方法名
"enclosing_method_arguments" = 方法实参名列表(alist, bstring, cobject)
"enclosing_package" = 类路径(不含类名)
"enclosing_package" = 工程名
"enclosing_type" = 类名
"file" = 文件名(xx.java)
"primary_type_name" = 类名
"return_type" = 方法返回类型(List、String)
"time" = 时间(5:30:41 PM)
"user" = 用户名(qingzuochen)
"year" = 年(2009)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值