How to dynamically generate SQL query based on user’s selections?

后端 未结 5 1407
误落风尘
误落风尘 2021-01-22 18:56

This is the same question as:

How to dynamically generate SQL query based on user's selections?

The only difference is, that I\'m interested in seeing soluti

5条回答
  •  渐次进展
    2021-01-22 19:23

    If you want to do this in JPA 1.X, you can use custom query builder as described here http://rrusin.blogspot.com/2010/02/jpa-query-builder.html. This enables creating queries like this:

    return new JpaQueryBuilder().buildQuery(em,
                    new Object[] {
                        "select c from Car c where c.name is not null",
                        new JQBParam("name", name, " and c.name = :name"),
                        new JQBParam("type", type, " and c.type = :type")
                    }
                )
    

提交回复
热议问题