zoukankan      html  css  js  c++  java
  • [mybatis]Record与Example的用法

    一、Record

    一个Record是一个Dao对象(继承Mapper接口),tkmybatis会将record自动映射成sql语句,record中所有非null的属性都作为sql语句,如:

    映射的sql文如下:

    SELECT eigyousyo_id,goods_id,goods_kind_id,goods_management_id,goods_management_name,reserve1,reserve2,reserve3,reserve4,sort_no,update_author,update_time,version
    FROM mst_GoodsInPad
    WHERE eigyousyo_id = ?

    Mapper接口中的方法:

     

    Mapper接口中部分方法的解析:

    方法功能说明
    int countByExample(UserExample example) thorws SQLException 按条件计数
    int deleteByPrimaryKey(Integer id) thorws SQLException 按主键删除
    int deleteByExample(UserExample example) thorws SQLException 按条件查询
    String/Integer insert(User record) thorws SQLException 插入数据(返回值为ID)
    User selectByPrimaryKey(Integer id) thorws SQLException 按主键查询
    ListselectByExample(UserExample example) thorws SQLException 按条件查询
    ListselectByExampleWithBLOGs(UserExample example) thorws SQLException 按条件查询(包括BLOB字段)。只有当数据表中的字段类型有为二进制的才会产生。
    int updateByPrimaryKey(User record) thorws SQLException 按主键更新
    int updateByPrimaryKeySelective(User record) thorws SQLException 按主键更新值不为null的字段
    int updateByExample(User record, UserExample example) thorws SQLException 按条件更新
    int updateByExampleSelective(User record, UserExample example) thorws SQLException 按条件更新值不为null的字段

    二、Example

    Example对象允许在sql操作时手动指定where 条件:

    映射的sql文会自动生成where 条件:

    WHERE ( goods_code = goodsFromTable.getGoodsCode() )

    Example的实例函数如下:

    方法说明
    example.setOrderByClause(“字段名 ASC”); 添加升序排列条件,DESC为降序
    example.setDistinct(false) 去除重复,boolean型,true为选择不重复的记录。
    criteria.andIsNull 添加字段为null的条件
    criteria.andIsNotNull 添加字段不为null的条件
    criteria.andEqualTo(value) 添加字段等于value条件
    criteria.andNotEqualTo(value) 添加字段不等于value条件
    criteria.andGreaterThan(value) 添加字段大于value条件
    criteria.andGreaterThanOrEqualTo(value) 添加字段大于等于value条件
    criteria.andLessThan(value) 添加字段小于value条件
    criteria.andLessThanOrEqualTo(value) 添加字段小于等于value条件
    criteria.andIn(List<?>) 添加字段值在List<?>条件
    criteria.andNotIn(List<?>) 添加字段值不在List<?>条件
    criteria.andLike(“%”+value+”%”) 添加字段值为value的模糊查询条件
    criteria.andNotLike(“%”+value+”%”) 添加字段值不为value的模糊查询条件
    criteria.andBetween(value1,value2) 添加字段值在value1和value2之间条件
    criteria.andNotBetween(value1,value2) 添加字段值不在value1和value2之间条件
  • 相关阅读:
    循环移位算法
    关于Java中2.0-1.1!=0.9的问题
    Java基础语法(三)
    Java基础语法(二)
    Java基础语法(一)
    关于Java运行机制
    Java从零开始(前篇)
    关于.ssh目录下的known_hosts文件的补充
    解决 bash cd too many arguments 报错
    Markdown学习笔记(一)
  • 原文地址:https://www.cnblogs.com/vickylinj/p/9486098.html
Copyright © 2011-2022 走看看