zoukankan      html  css  js  c++  java
  • Example解析

    本文总结自:https://github.com/abel533/Mapper/wiki/6.example,旨在提供一些基本概念上的解释

    Example类用于条件查询,以代替冗长的"select from xxxxxx"

    Example可分为两类

    1、MBG生成的Example

    例如:

    CountryExample example = new CountryExample();
    example.createCriteria().andCountrynameLike("A%"); //无需设置属性名,此处为给名为CountryName的属性设值
    example.or().andIdGreaterThan(100);
    example.setDistinct(true);
    int count = mapper.deleteByExample(example);//这是一个Example方法

    备注:criteria相当于条件查询中的"where xxx"

    MBG提供的Example与model中的类的类名对应

    2、通用Mapper提供的通用Example

    通用Mapper 提供的一个类,这个类和 MBG 生成的相比,需要自己设置属性名。这个类还额外提供了更多的方法。

    例如:

    Example example = new Example(Country.class); //提供类名
    example.setForUpdate(true);
    example.createCriteria().andGreaterThan("id", 100).andLessThan("id",151);
    example.or().andLessThan("id", 41);
    List<Country> countries = mapper.selectByExample(example);

    -------------------------------------------------------------------------------------------------------------------------------

    Example方法即mapper如何使用example的方法

    方法有许多,有两种类型的定义方式:

    List<T> selectByExample(Object example);
    
    int updateByExampleSelective(@Param("record") T record, @Param("example") Object example);

    所有Example方法中的example类型都是Object类型,这是因为通用 Mapper 支持所有符合Example结构的参数。

    例如通过MBG生成的CountryExample、UserExample类。还有通用Mapper中提供的通用Example,以及支持Java8方法引用的Weekend类型。

  • 相关阅读:
    Java线程:线程的交互
    Java线程:线程的同步与锁
    重载,继承,重写和多态的区别
    Java线程:线程状态的转换
    Java线程:线程栈模型与线程的变量
    Java线程:创建与启动
    Java线程:概念与原理
    Android上dip、dp、px、sp等单位说明
    Java学习之路:不走弯路,就是捷径
    谷歌大牛 Rob Pike 的 5 个编程原则
  • 原文地址:https://www.cnblogs.com/yanze/p/10647718.html
Copyright © 2011-2022 走看看