NutzCN Logo
问答 andInBySql 变量赋值 问题 我去掉 %号
发布于 2043天前 作者 Hamming 1911 次浏览 复制 上一个帖子 下一个帖子
标签:

查询部门下面的用户 及子部门下面用户
cnd条件为

cnd.where().andInBySql("dept_id","SELECT dept_id FROM sys_dept  WHERE FIND_IN_SET ('%%%s%%',ancestors)", deptId).or("dept_id","=", deptId);

输出SQL为

 For example:> "SELECT * FROM sys_user  WHERE dept_id IN (SELECT dept_id FROM sys_dept  WHERE FIND_IN_SET ('%100%',ancestors)) OR dept_id='100' LIMIT 0, 10 "
4 回复

改成酱紫 报错

cnd.where().andInBySql("dept_id","SELECT dept_id FROM sys_dept  WHERE FIND_IN_SET ('%%s%',ancestors)", deptId).or("dept_id","=", deptId);
 org.nutz.service.EntityService.<init>(EntityService.java:41) - Get TypeParams for self : io.nutz.nutzsite.module.sys.models.User
[WARN ] 11:50:29.113 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/sys/user/list :
java.util.UnknownFormatConversionException: Conversion = '''
	at java.util.Formatter.checkText(Formatter.java:2579)
	at java.util.Formatter.parse(Formatter.java:2565)
	at java.util.Formatter.format(Formatter.java:2501)
	at java.util.Formatter.format(Formatter.java:2455)
	at java.lang.String.format(String.java:2940)
	at org.nutz.dao.util.cri.SqlRange.<init>(SqlRange.java:14)
	at org.nutz.dao.util.cri.Exps.inSql(Exps.java:74)
	at org.nutz.dao.util.cri.SqlExpressionGroup.andInBySql(SqlExpressionGroup.java:122)
	at io.nutz.nutzsite.module.sys.controllers.UserController.list(UserController.java:58)

想要 sql输出 为

SELECT dept_id FROM sys_dept  WHERE FIND_IN_SET ('100',ancestors)

那是String.format,

\% 转义一下

完美解决

cnd.where().andInBySql("dept_id","SELECT id FROM sys_dept  WHERE FIND_IN_SET ('%s',ancestors)", deptId).or("dept_id","=", deptId);
添加回复
请先登陆
回到顶部