本来想继承MODEL的,但是因为用了自动构建baseModel所以用不了,老大给了继承的方法还没时间研究先直接发出来。希望有人能将其强大之。
用法示例:
1、new ModelX().init(new Users()).where("username","666").where("password","e10adc3949ba59abbe56e057f20f883e").findFirst()
返回record
2、new ModelX().init(new Users()).where("password","e10adc3949ba59abbe56e057f20f883e").orderBy("create_time desc").find()
返回List
3、ModelX.buildSelect(new Users())
返回String :
select * from users
4、ModelX.buildSelectWhere(new Users())
返回String :
select * from users where
4 的使用示例:someModel().find(ModelX.buildSelect(someModel()) + " column = ?",getPara("param"))
代码:
com.jfinal.plugin.activerecord.Modelcom.jfinal.plugin.activerecord.TableMappingjava.util.ArrayListjava.util.HashMapjava.util.Listjava.util.MapModelX { Model String List =ArrayList()String =List =ArrayList()String ModelX (Model model){ .= TableMapping.().getTable(model.getClass()).getName().=model} ModelX (String paraNameObject paraValue){ =..add(HashMap(){{ put()}})} ModelX (String paraNameObject paraValueString type){ =type..add(HashMap(){{ put()}})} ModelX (String orderByStr){ .=orderByStr} String (){ (.size()>){ StringBuilder temp=StringBuilder().forEach((paraMap)->{ ((Map)paraMap).forEach((kv)->{ .append(++ + k + )..add(v)})})+ temp.toString()}{ } } List (){ String sql = + + _bulidWhere() + .find(sql.toArray())} Model (){ String sql = + + _bulidWhere() + .findFirst(sql.toArray())} String (Model model){ String tableName = TableMapping.().getTable(model.getClass()).getName()+ tableName} String (Model model){ String tableName = TableMapping.().getTable(model.getClass()).getName()+ tableName + } } |