4912941
V2EX  ›  Java

JPA 的 Criteria 查询,怎么使用 Mysql 的 find_in_set 函数

  •  
  •   4912941 · Feb 23, 2016 · 6917 views
    This topic created in 3925 days ago, the information mentioned may be changed or developed.
    6 replies  •  2016-02-24 10:00:06 +08:00
    hustlike
    hustlike
    Feb 23, 2016
    1
    jpa 就是数据库无关的?
    zonghua
    zonghua
    Feb 23, 2016
    2
    直接写语句,注解有参数:

    nativeQuery=true

    这样使用原生语句,就能用特定的函数啦。



    给个星吧, Spring 写的论坛

    http://spring-abc.xyz/

    https://github.com/zh-h/spring-abc
    4912941
    4912941
    OP
    Feb 23, 2016
    3
    @zonghua 有许多查询条件,用 nativeQuery 的话需要拼 sql 语句,很容易出错。希望通过 Criteria 的方式。。。是不是实现不了
    4912941
    4912941
    OP
    Feb 23, 2016
    4
    @zonghua 给星了
    zonghua
    zonghua
    Feb 23, 2016
    5
    @4912941 那就用 Mybatis 咯,可以多个 ORM 同时使用。
    fwrq41251
    fwrq41251
    Feb 24, 2016
    6
    jpa 支持的函数看这里,如果没有那就是没有了: https://en.wikibooks.org/wiki/Java_Persistence/Criteria#Functions
    你非要用 Criteria 写的话,重新设计下表吧。把你要 find_in_set 的这个 column 里的内容分开用别的表来存。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4606 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 03:44 · PVG 11:44 · LAX 19:44 · JFK 22:44
    ♥ Do have faith in what you're doing.