NutzCN Logo
问答 自定义sql传参为null?
发布于 2801天前 作者 老司机 1907 次浏览 复制 上一个帖子 下一个帖子
标签:

sql代码

/* achievement.list.by.student.id */
SELECT
  a.achievementScore,
  b.student_name,
  c.curriculum_name
FROM t_achievement a LEFT JOIN t_student b ON a.student_id = b.student_id
  LEFT JOIN t_curriculum c ON a.curriculum_id = c.curriculum_id
WHERE a.student_id = @studentId

java代码

 Sql sql = dao.sqls().create("achievement.list.by.student.id");
        sql.setVar("studentId", 1);
        sql.setCallback(Sqls.callback.records());
        dao.execute(sql);

日志

2017-4-22 15:37:40.216 DEBUG [RMI TCP Connection(3)-127.0.0.1] SELECT
a.achievementScore,
b.student_name,
c.curriculum_name
FROM t_achievement a LEFT JOIN t_student b ON a.student_id = b.student_id
LEFT JOIN t_curriculum c ON a.curriculum_id = c.curriculum_id
WHERE a.student_id = ?
    |    1 |
    |------|
    | NULL |
  For example:> "SELECT
a.achievementScore,
b.student_name,
c.curriculum_name
FROM t_achievement a LEFT JOIN t_student b ON a.student_id = b.student_id
LEFT JOIN t_curriculum c ON a.curriculum_id = c.curriculum_id
WHERE a.student_id = 'NULL'"

我想传1,但是是null?为什么?

3 回复

@wendal 可不可以传数组或者集合

Sql sql = dao.sqls().create("achievement.list.by.student.id");
        sql.setParam("studentIds", new int[]{1, 2});
        sql.setCallback(Sqls.callback.records());
        dao.execute(sql);

现在是报错的

2017-4-22 17:29:11.34 DEBUG [RMI TCP Connection(3)-127.0.0.1] SELECT
now(),
a.achievementScore,
b.student_name,
c.curriculum_name
FROM t_achievement a LEFT JOIN t_student b ON a.student_id = b.student_id
LEFT JOIN t_curriculum c ON a.curriculum_id = c.curriculum_id
WHERE a.student_id IN ?,?;
    | 1 | 2 |
    |---|---|
    | 1 | 2 |
  For example:> "SELECT
now(),
a.achievementScore,
b.student_name,
c.curriculum_name
FROM t_achievement a LEFT JOIN t_student b ON a.student_id = b.student_id
LEFT JOIN t_curriculum c ON a.curriculum_id = c.curriculum_id
WHERE a.student_id IN 1,2;"
添加回复
请先登陆
回到顶部