比如这样的 Sql sql = Sqls.create("DELETE FROM $table WHERE name=@name");
可以先创建sqlStr 然后
sql.vars().set("table","t_abc");
sql.params().set("name","Peter");
但是我这个是这样写的
StringBuilder sqlStr = new StringBuilder();
String id = params.getString("id");
String name = params.getString("name");
int pageNumber = params.getInt("pageNumber");
int pageSize = params.getInt("pageSize");
if(Strings.isBlank(id)){
sqlStr.append("SELECT * FROM sys_department WHERE 1 = 1");
if(!Strings.isBlank(name)){
sqlStr.append(" AND name LIKE %"+name+"%");
}
sqlStr.append(" ORDER BY orderNum ASC");
}else{
sqlStr.append("SELECT *,LEVEL AS _level FROM sys_department WHRE 1 = 1");
if(!Strings.isBlank(name)){
sqlStr.append(" AND name LIKE %"+name+"%");
}
sqlStr.append(" START WITH id='").append(id).append("' CONNECT BY PRIOR id=parentId");
sqlStr.append(" ORDER BY _level ASC,orderNum ASC");
}
Sql sql = Sqls.create(sqlStr.toString());
这个怎么避免like中的硬编码呢?