加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – MyBatis“或”标准

发布时间:2020-12-15 00:49:44 所属栏目:Java 来源:网络整理
导读:我想用MyBatis创建一个查询,它将产生如下内容: SELECT first_field,second_filed,third_fieldWHERE first_field 1 AND (second_field 0 OR third_field 0) 我怎么能用Criteria对象构造它? 解决方法 一种方法是到 extend the generated Example classes: T
我想用MyBatis创建一个查询,它将产生如下内容:
SELECT first_field,second_filed,third_field
WHERE first_field > 1 AND (second_field > 0 OR third_field < 0)

我怎么能用Criteria对象构造它?

解决方法

一种方法是到 extend the generated Example classes:

The generated “example” class includes a nested inner class where the actual functionality of the predicates exists. This inner class is always named GeneratedCriteria.

MBG also generates an inner class named Criteria which extends GeneratedCriteria and which you may use for adding your own functions to the example classes. The Criteria class will not be deleted by the Eclipse Java code merger,so you may add to it without fear of losing your changes upon regeneration.

基本上,生成示例类,并添加自定义条件.

public Criteria multiColumnOrClause(String value1,String value2) {
        addCriterion("value1 = " + value1 + " OR value2 = " + value2);
        return this;
    }

如果您经常重复使用它,并且不想为所有映射器执行此操作,您也可以在“插件”中提取逻辑,尽管文档有点缺乏,但只有一个示例:

org.mybatis.generator.plugins.CaseInsensitiveLikePlugin

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读