NutzCN Logo
问答 自定义sql传入对象
发布于 2288天前 作者 qq_1d84c364 1957 次浏览 复制 上一个帖子 下一个帖子
标签:

有个对象a是:
{
id : 1,
name:'abc'
}
自定义sql:
select * from table where id = @a.id
打印出来的sql是:select * from table where id = {id : 1,name:'abc'}
但是:select * from table where id = ${a.id}
打印出来的sql是:select * from table where id = 1
虽然第二种方法没问题,但是我要?传参,防止sql注入,请问这个怎么写啊?

2 回复

暂不支持 "@a.id" 形式哦

    @Test
    public void test_issue_object_param() {
        User obj = new User();
        obj.setId(123);
        Sql sql = Sqls.create("select * from table where id = @id");
        sql.params().putAll(Lang.obj2map(obj));
        System.out.println(sql.toString());
    }

嗯,看来没别的办法了

添加回复
请先登陆
回到顶部