2018-11-08

第一篇记录一下很以前也遇到过没有解决的一个问题,关于筛选的时候怎么处理有些条件为空的时候,把它作为一个默认全选的sql问题。
项目是springboot jpa操作数据库,就这么贴上来了,主要是那个if的判断

 @Query(value = "SELECT * FROM date where gyear_month_day like ?1% and if(?2 !='',season=?2,1=1) and if(?3 !='',solar_terms=?3,1=1) and if(?4 !='',special_solar_terms_class=?4,1=1) and if(?5 !='',special_solar_terms=?5,1=1)",nativeQuery = true)
    public List<Date> ChooseDate(String year,String season,String solarTerms,String specialSolarTermsClass,String specialSolarTerms);
  

坐久了,肩膀疼~

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容