zoukankan      html  css  js  c++  java
  • mybatis 数据库.xml中方法参考

    ① selectByPrimaryKey()

    User user = userDAO.selectByPrimaryKey(100); 相当于select * from user where id = 100

    ② selectByExample() 和 selectByExampleWithBLOGs()

    UserExample example = new UserExample();
    Criteria criteria = example.createCriteria();
    criteria.andUsernameEqualTo("joe");
    criteria.andUsernameIsNull();
    example.setOrderByClause("username asc,email desc");
    List<?>list = userDAO.selectByExample(example);
    相当于:select * from user where username = 'joe' and username is null order by username asc,email desc

    注:在iBator 生成的文件UserExample.java中包含一个static 的内部类 Criteria ,在Criteria中有很多方法,主要是定义SQL 语句where后的查询条件。

    ③ insert()

    User user = new User();
    user.setId(101);
    user.setUsername("test");
    user.setPassword("123")
    user.setEmail("joe@163.com");
    userDAO.insert(user);
    相当于:insert into user(ID,username,password,email) values(101,'test','123','joe@163.com');

     ④ updateByPrimaryKey() 和 updateByPrimaryKeySelective()

    User user =new User();
    user.setId(101);
    user.setUsername("joe");
    user.setPassword("joe");
    user.setEmail("joe@163.com");
    userDAO.updateByPrimaryKey(user);
    相当于:update user set username='joe',password='joe',email='joe@163.com' where id=101

    User user = new User();
    user.setId(101);
    user.setPassword("joe");
    userDAO.updateByPrimaryKeySelective(user);
    相当于:
    update user set password='joe' where id=101

     updateByExample() 和 updateByExampleSelective()

    UserExample example = new UserExample();
    Criteria criteria = example.createCriteria();
    criteria.andUsernameEqualTo("joe");
    User user = new User();
    user.setPassword("123");
    userDAO.updateByPrimaryKeySelective(user,example);
    相当于:update user set password='123' where username='joe'

     deleteByPrimaryKey()

    userDAO.deleteByPrimaryKey(101);  相当于:delete from user where id=101

    ⑦ deleteByExample()

    UserExample example = new UserExample();
    Criteria criteria = example.createCriteria();
    criteria.andUsernameEqualTo("joe");
    userDAO.deleteByExample(example);
    相当于:delete from user where username='joe'

    ⑧ countByExample()

    UserExample example = new UserExample();
    Criteria criteria = example.createCriteria();
    criteria.andUsernameEqualTo("joe");
    int count = userDAO.countByExample(example);
    相当于:select count(*) from user where username='joe'

  • 相关阅读:
    Trie Tree和Radix Tree
    DataNode Layout升级解决Du操作引发的性能问题
    Write-Ahead Log(WAL)的工作原理
    YARN的共享存储服务
    AWS S3存储基于Hadoop之上的一致性保证
    简单聊聊HDFS RBF第二阶段工作近期的一些进展
    基于 Confluence 6 数据中心的 SAML 单点登录设置你的身份提供者
    基于 Confluence 6 数据中心的 SAML 单点登录设置 SSL/TLS
    Confluence 6 基于 Confluence 数据中心的 SAML 单点登录
    Confluence 6 用自带的用户管理
  • 原文地址:https://www.cnblogs.com/zhenmingliu/p/2502261.html
Copyright © 2011-2022 走看看