zoukankan      html  css  js  c++  java
  • Mybatis中example类的使用

    要使用example类,先要在项目中导入mybatis.mapper的jar包。

    Mapper接口中包含了单表的增删改查以及分页功能。

    给出实例:

    CountryMappermapper = sqlSession.getMapper(Country.class);

    //Country.class是实体类

    //查询操作

    List<Country>cList = mapper.select(new Country());

    现在使用Example查询

    Example example =new Example(Country.class);

    example.createCriteria().andEqualTo(“id”,100);

    //这里给出查询为id=100

    cList = mapper.selectByExample(example);

    example.setOrderByClause(“字段名ASC”); 以某字段升序排序

    example.setDistinct(false)//去除重复,boolean型,true为选择不重复的记录

    selectByExample()返回的是一个集合

    mybatis中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:按主键查询。


    List<?>selectByExample(UserExample example) thorws SQLException:按条件查询


    List<?>selectByExampleWithBLOGs(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的字段

    mybatis中mapper的实例函数详解:
     selectByPrimaryKey()

    Country country = ##Mapper.selectByPrimaryKey(100);

    相当于select * from user where id = 100

    还有一些方法不在这里赘述,可以参考mybatis中的example

    转自 http://blog.csdn.net/qq_36743013/article/details/71144508

  • 相关阅读:
    第三节 单因素方差分析
    第四十一节 ORM介绍和用元类实现
    第四十节 通过type创建复杂的类,元类应用
    第二节 检验方法使用条件考察
    HDFS HA误删namenode后报错Nameservice testCluster has no SecondaryNameNode or High-Availability partner的恢复
    spark sql cache时发现的空字符串问题
    centos7环境下ELK部署之elasticsearch
    CDH升级 5.7.5 --> 5.13.3(tar包方式)
    CDH部署(以5.7.5为例)
    人生苦短,Let's Go
  • 原文地址:https://www.cnblogs.com/xingmangdieyi110/p/10329605.html
Copyright © 2011-2022 走看看