java代码,目的是按照sql查询出一条数据。
String optionGroupCode = og.getOption_group_code();//E1
Sql sql = Sqls.create("SELECT * from apc_option where option_code NOT IN (@usedOptionCode) AND option_group = @optionGroupCode AND question_group = @questionGroupCode GROUP BY RAND() limit 1");
sql.params().set("usedOptionCode", usedOptionCode).set("questionGroupCode", questionGroupCode).set("optionGroupCode", optionGroupCode);
sql.setCallback(Sqls.callback.entities());
sql.setEntity(dao.getEntity(Option.class));
dao.execute(sql);
List<Option> sqlResultList = sql.getList(Option.class);
if(null == sqlResultList || sqlResultList.size()==0){
log.debug("questionGroupCode->"+questionGroupCode+">usedOptionCode->"+usedOptionCode+"No values");
}else{
log.debug(sqlResultList.toString());
}
以下是log日志
[DEBUG] 15:11:56.256 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * from apc_option where option_code NOT IN (?) AND option_group = ? AND question_group = ? GROUP BY RAND() limit 1
| 1 | 2 | 3 |
|------|----|---|
| NULL | E1 | 1 |
For example:> "SELECT * from apc_option where option_code NOT IN ('NULL') AND option_group = 'E1' AND question_group = '1' GROUP BY RAND() limit 1"
[DEBUG] 15:11:56.262 com.xueersi.apc.service.OptionService.getWholeOptions(OptionService.java:54) - questionGroupCode->1>usedOptionCode->nullNo values
事实上,我把
SELECT * from apc_option where option_code NOT IN ('NULL') AND option_group = 'E1' AND question_group = '1' GROUP BY RAND() limit 1
这条SQL,放入数据库执行 是有一条数据的。
最后放个pojo
@Table("apc_option")
public class Option extends BaseBean{
@Name()
@Column
private String option_code;
@Column("option_content")
private String optionContent;
@Column("option_group")
private String optionGroup;
@Column("poet")
private String poet;
@Column("question_group")
private String questionGroup;
public String getQuestionGroup() {
return questionGroup;
}
public void setQuestionGroup(String questionGroup) {
this.questionGroup = questionGroup;
}
public String getPoet() {
return poet;
}
public void setPoet(String poet) {
this.poet = poet;
}
public String getOption_code() {
return option_code;
}
public void setOption_code(String option_code) {
this.option_code = option_code;
}
public String getOptionContent() {
return optionContent;
}
public void setOptionContent(String optionContent) {
this.optionContent = optionContent;
}
public String getOptionGroup() {
return optionGroup;
}
public void setOptionGroup(String optionGroup) {
this.optionGroup = optionGroup;
}
}