作者 赵超

update

... ... @@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Map.Entry;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
... ... @@ -47,6 +48,9 @@ public abstract class _BaseModel<M extends _BaseModel<M>> extends Model<M> {
public List<M> searchAll() {
return find("select * from " + table());
}
public void update(String carNo) {
Db.update("update "+table()+" Set status=2 WHERE carNo in (?)",carNo);
}
private void checkTableName() {
if (StrKit.isBlank(table()))
... ... @@ -72,11 +76,17 @@ public abstract class _BaseModel<M extends _BaseModel<M>> extends Model<M> {
List<M> mList = search(maps, "");
return mList != null && mList.size() > 0 ? mList.get(0) : null;
}
public M searchFirst1(Map<String, Object> maps) {
List<M> mList = search1(maps, "");
return mList != null && mList.size() > 0 ? mList.get(0) : null;
}
public List<M> search(Map<String, Object> maps) {
return search(maps, "");
}
public List<M> search1(Map<String, Object> maps) {
return search1(maps, "");
}
public List<M> search(Map<String, Object> maps, String orderBy) {
checkTableName();
StringBuilder sb = new StringBuilder();
... ... @@ -91,7 +101,20 @@ public abstract class _BaseModel<M extends _BaseModel<M>> extends Model<M> {
sb.append(" ").append(orderBy);
return find(sb.toString(), values.toArray());
}
public List<M> search1(Map<String, Object> maps, String orderBy) {
checkTableName();
StringBuilder sb = new StringBuilder();
sb.append("select * from ").append(table()).append(" where 1=1 ");
List<Object> values = new ArrayList<Object>();
for (Entry<String, Object> entry : maps.entrySet()) {
if (entry.getValue() != null) {
sb.append(" and ").append(entry.getKey()).append("=?");
values.add(entry.getValue());
}
}
sb.append(" ").append("order by enterTime DESC");
return find(sb.toString(), values.toArray());
}
public Page<M> searchPaginate(int pageNumber, int pageSize, Map<String, Object> maps) {
return this.searchPaginate(pageNumber, pageSize, maps, "");
}
... ...