2018-01-30 16:19

SQL 不是你自己传进来的吗? 写sql 的时候自己不写 limit 1的吗? 如果框架自动把limit 1追加到sql里面, 外面的代码sql不易读吧。。。

2018-01-26 21:42

@昵称而已
好多个BaseModel ???
你指的是那种 get和set的 BaseXxxModel 吗?
这个简单啊, 让哪些BaseXxxModel 去继承你通用公共的BaseModel 就可以了。
比如我的:


public abstract class BaseAccount> extends BaseModel implements IBean {
setXxx
getXxx


值得注意的是 Jfinal 3.3版本 getConfig() 增加了 _getConfig() 下划线前缀的。
同时Model 生成器的模版也需要自定义一下,这样生成的就不用修改了

2018-01-25 23:20

@215115704
比较简单的 递归调用函数体:
#define showMenu(me){
...html...
#@showMenu(me.menus)
...html...
}


如果你的函数体比较复杂 , 可以建一个java , 使用下面方式去调用,

6.8 Shared Object扩展



    通过使用addSharedObject方法,将某个具体对象添加为共享对象,可以全局进行使用,以下是代码示例:

  1. public void configEngine(Engine me) {
  2.    me.addSharedObject("RESOURCE_HOST", "http://res.jfinal.com");
  3.    me.addSharedObject("sk", new com.jfinal.kit.StrKit());
  4. }

    以上代码中的第二行,添加了一个名为RESOURCE_HOST的共享对象,而第三行代码添加了一个名为sk的共享对象,以下是在模板中的使用例子:

  1. <img src="#(RESOURCE_HOST)/img/girl.jpg" />
  2. #if(sk.isBlank(title))
  3.    ...
  4. #end

    以上代码第一行中使用输出指令输出了RESOUCE_HOST这个共享变量,对于大型web应用系统,通过这种方式可以很方便地规划资源文件所在的服务器。以上第二行代码调用了名为sk这个共享变量的isBlank方法,使用方式符合开发者直觉。

    注意:由于对象被全局共享,所以需要注意线程安全问题,尽量只共享常量以及无状态对象。


2018-01-25 23:06

也许移动端传的时候就已经乱码了。。。 可以看看前面是不是有坑

2018-01-25 22:42

看 演示第二种方式,


public List 获取子菜单() {
return find("select * from 菜单 where 自联键=?", get("id"));
}

2018-01-25 22:35

5.10 表关联操作



    JFinal ActiveRecord 天然支持表关联操作,并不需要学习新的东西,此为无招胜有招。表关联操作主要有两种方式:一是直接使用sql得到关联数据;二是在Model中添加获取关联数据的方法。

    假定现有两张数据库表:user、blog,并且user到blog是一对多关系,blog表中使用user_id关联到user表。如下代码演示使用第一种方式得到user_name:

  1. public void relation() {
  2.   String sql = "select b.*, u.user_name from blog b inner join user u on b.user_id=u.id where b.id=?";
  3.   Blog blog = Blog.dao.findFirst(sql, 123);
  4.   String name = blog.getStr("user_name");
  5. }

    以下代码演示第二种方式在Blog中获取相关联的User以及在User中获取相关联的Blog:

  1. public class Blog extends Model<Blog>{
  2.     public static final Blog dao = new Blog();
  3.     
  4.     public User getUser() {
  5.        return User.dao.findById(get("user_id"));
  6.     }
  7. }
  8.  
  9. public class User extends Model<User>{
  10.     public static final User dao = new User();
  11.     
  12.     public List<Blog> getBlogs() {
  13.        return Blog.dao.find("select * from blog where user_id=?", get("id"));
  14.     }
  15. }










2018-01-24 21:03

温馨提示: 还需要注意 文件的路径,windows 不区分大小写,而在 Linux 中是区分的, 建议全部小写,用_下划线隔开单词_a_b_c_d_2_3_3_3

2018-01-24 13:40

@Irin.Chan enjoy 谁用谁enjoy

2018-01-24 09:49

@简单代码 嗯,很多工具 是根据业务走,才能体会到它的好处

2018-01-23 22:32

Db.tx() 源码搬过来,我们一起来瞅瞅


/**
* Execute transaction.
* @param config the Config object
* @param transactionLevel the transaction level
* @param atom the atom operation
* @return true if transaction executing succeed otherwise false
*/
boolean tx(Config config, int transactionLevel, IAtom atom) {
Connection conn = config.getThreadLocalConnection();
if (conn != null) { // Nested transaction support
try {
if (conn.getTransactionIsolation() < transactionLevel)
conn.setTransactionIsolation(transactionLevel);
boolean result = atom.run();
if (result)
return true;
throw new NestedTransactionHelpException("Notice the outer transaction that the nested transaction return false"); // important:can not return false
}
catch (SQLException e) {
throw new ActiveRecordException(e);
}
}

Boolean autoCommit = null;
try {
conn = config.getConnection();
autoCommit = conn.getAutoCommit();
config.setThreadLocalConnection(conn);
conn.setTransactionIsolation(transactionLevel);
conn.setAutoCommit(false);
boolean result = atom.run();
if (result)
conn.commit();
else
conn.rollback();
return result;
} catch (NestedTransactionHelpException e) {
if (conn != null) try {conn.rollback();} catch (Exception e1) {LogKit.error(e1.getMessage(), e1);}
LogKit.logNothing(e);
return false;
} catch (Throwable t) {
if (conn != null) try {conn.rollback();} catch (Exception e1) {LogKit.error(e1.getMessage(), e1);}
throw t instanceof RuntimeException ? (RuntimeException)t : new ActiveRecordException(t);
} finally {
try {
if (conn != null) {
if (autoCommit != null)
conn.setAutoCommit(autoCommit);
conn.close();
}
} catch (Throwable t) {
LogKit.error(t.getMessage(), t); // can not throw exception here, otherwise the more important exception in previous catch block can not be thrown
} finally {
config.removeThreadLocalConnection(); // prevent memory leak
}
}
}

2018-01-23 22:27

Db.tx() 感觉也挺棒的, 个人感觉比 Tx.clsss 好用。。。


boolean tx = Db.tx(new IAtom() {

@Override
public boolean run() throws SQLException {
try {
// 处理业务
return true;
} catch (Exception e) {
log.error("xxx失败", e);
return false;
}
}
});

2018-01-23 22:09

如果想在其他地方让 Tx.clsss 起作用的话, 需要使用 Duang.duang()、Enhancer.enhance() 了, 详见手册:

2018-01-23 17:34

23333, 挤着了。。 处女座的说看了难受。。
借楼:
缓存是怎么回事?