我负责的项目都是Jfinal的了,有必要写一些学习知识,记录下来。
1、PropKit.use("config.txt", "UTF-8");
PropKit 工具类用来操作外部配置文件。
public class AppConfig extends JFinalConfig { public void configConstant(Constants me) { // 第一次使用use加载的配置将成为主配置,可以通过PropKit.get(...)直接取值 PropKit.use("a_little_config.txt"); me.setDevMode(PropKit.getBoolean("devMode")); } public void configPlugin(Plugins me) { // 非第一次使用use加载的配置,需要通过每次使用use来指定配置文件名再来取值 String redisHost = PropKit.use("redis_config.txt").get("host"); int redisPort = PropKit.use("redis_config.txt").getInt("port"); RedisPlugin rp = new RedisPlugin("myRedis", redisHost, redisPort); me.add(rp); // 非第一次使用 use加载的配置,也可以先得到一个Prop对象,再通过该对象来获取值 Prop p = PropKit.use("db_config.txt"); DruidPlugin dp = new DruidPlugin(p.get("jdbcUrl"), p.get("user")…); me.add(dp); } }
2、Tx 事务拦截器
以下为事务处理示例:
boolean succeed = Db.tx(new IAtom(){ public boolean run() throws SQLException { int count = Db.update("update account set cash = cash - ? where id = ?", 100, 123); int count2 = Db.update("update account set cash = cash + ? where id = ?", 100, 456); return count == 1 && count2 == 1; }}); }
以上两次数据库更新操作在一个事务中执行,如果执行过程中发生异常或者 invoke()方法
返回 false,则自动回滚事务。
原文:http://www.cnblogs.com/hoge/p/4961257.html