当前位置: 首页 > news >正文

免费页面设计模板海外网站优化

免费页面设计模板,海外网站优化,厦门建设局叶文语简历,搭建网页视频教程MyBatis-Flex 的增删改功能 - MyBatis-Flex 官方网站https://mybatis-flex.com/zh/base/add-delete-update.html 代码https://gitee.com/hntianshu/mybatis-flex-test 一 新增数据 不忽略 null 值。 就是允许有null 忽略null 就是不允许有null BaseMapper 的接口提供了 inser…MyBatis-Flex 的增删改功能 - MyBatis-Flex 官方网站https://mybatis-flex.com/zh/base/add-delete-update.html 代码https://gitee.com/hntianshu/mybatis-flex-test 一 新增数据 不忽略 null 值。 就是允许有null 忽略null  就是不允许有null BaseMapper 的接口提供了 insert 和 insertBatch 方法用于新增数据 insert(entity)插入实体类数据不忽略 null 值。insertSelective(entity)插入实体类数据但是忽略 null 的数据只对有值的内容进行插入。这样的好处是数据库已经配置了一些默认值这些默认值才会生效。insert(entity, ignoreNulls)插入实体类数据。insertWithPk(entity)插入带有主键的实体类不忽略 null 值。insertSelectiveWithPk(entity)插入带有主键的实体类忽略 null 值。insertWithPk(entity, ignoreNulls)带有主键的插入此时实体类不会经过主键生成器生成主键。insertBatch(entities)批量插入实体类数据只会根据第一条数据来构建插入的字段内容。insertBatch(entities, size)批量插入实体类数据按 size 切分。insertOrUpdate(entity)插入或者更新若主键有值则更新若没有主键值则插入插入或者更新都不会忽略 null 值。insertOrUpdateSelective(entity)插入或者更新若主键有值则更新若没有主键值则插入插入或者更新都会忽略 null 值。insertOrUpdate(entity, ignoreNulls)插入或者更新若主键有值则更新若没有主键值则插入。 1. insert(entity)插入实体类数据不忽略 null 值。 Autowiredprivate AccountMapper accountMapper; Testvoid insert() {Account account new Account(16, 哈皮, null, LocalDateTime.now()); //还是自增//INSERT INTO tb_account(user_name, age, birthday) VALUES (?, ?, ?)//Parameters: 哈皮(String), null, 2024-01-02T09:42:14.063491400(LocalDateTime)int row accountMapper.insert(account);System.err.println(新增数量: row 条);} 2.insertSelective(entity)插入实体类数据但是忽略 null 的数据只对有值的内容进行插入。这样的好处是数据库已经配置了一些默认值这些默认值才会生效。 /*** insertSelective(entity)插入实体类数据但是忽略 null 的数据只对有值的内容进行插入。这样的好处是数据库已经配置了一些默认值这些默认值才会生效。*/Testvoid insertSelective() {Account account new Account(null, 赵华, null, LocalDateTime.now());//Preparing: INSERT INTO tb_account(user_name, birthday) VALUES (?, ?)//Parameters: 赵华(String), 2024-01-02T09:44:54.492425100(LocalDateTime)int row accountMapper.insertSelective(account);System.err.println(新增数量: row 条);} 3. insert(entity, ignoreNulls)插入实体类数据。  ignoreNulls: false相当于 insert(entity)ignoreNulls: true相当于 insertSelective(entity) /*** insert(entity, ignoreNulls)插入实体类数据。* ignoreNulls: false相当于 insert(entity)* ignoreNulls: true相当于 insertSelective(entity)*/Testvoid insert2() {Account account new Account(null, 赵华, null, LocalDateTime.now());int row accountMapper.insert(account, true);System.err.println(新增数量: row 条);} 4.insertWithPk(entity)插入带有主键的实体类不忽略 null 值。 /*** insertWithPk(entity)插入带有主键的实体类不忽略 null 值。*/Testvoid insertWithPk() {Account account new Account(null, 赵华, null, LocalDateTime.now());int row accountMapper.insertWithPk(account);System.err.println(新增数量: row 条);} 5. insertSelectiveWithPk(entity)插入带有主键的实体类忽略 null 值。 相当于insertWithPk(entity, true) /*** insertSelectiveWithPk(entity)插入带有主键的实体类忽略 null 值。* 相当于insertWithPk(entity, true)*/Testvoid insertSelectiveWithPk() {Account account new Account(5, 赵华, null, LocalDateTime.now());int row accountMapper.insertSelectiveWithPk(account);System.err.println(新增数量: row 条);} 6.insertWithPk(entity, ignoreNulls)带有主键的插入此时实体类不会经过主键生成器生成主键。 insertWithPk insertWithPk(entity, false) insertSelectiveWithPk insertWithPk(entity, true) /*** insertWithPk(entity, ignoreNulls)带有主键的插入此时实体类不会经过主键生成器生成主键。* insertWithPk insertWithPk(entity, false)* insertSelectiveWithPk insertWithPk(entity, true)*/Testvoid insertWithPk2() {Account account new Account(5, 赵华, null, LocalDateTime.now());int row accountMapper.insertWithPk(account, true);System.err.println(新增数量: row 条);} 7.insertBatch(entities)批量插入实体类数据只会根据第一条数据来构建插入的字段内容。 只会根据字段数量最多的数据来构建插入的字段内容 不忽略null /*** insertBatch(entities)批量插入实体类数据只会根据第一条数据来构建插入的字段内容。* 只会根据字段数量最多的数据来构建插入的字段内容* 不忽略null*/Testvoid insertBatch() {ArrayListAccount list new ArrayList();list.add(new Account(null, 林一, 25, LocalDateTime.now()));list.add(new Account(null, null, null, null));list.add(new Account(王五, 23, LocalDateTime.now()));int row accountMapper.insertBatch(list);System.err.println(新增数量: row 条);} 8. insertBatch(entities, size)批量插入实体类数据按 size 切分。分开插入 n条做切分 /*** insertBatch(entities, size)批量插入实体类数据按 size 切分。* 分开插入 n条做切分*/Testvoid insertBatch2() {ArrayListAccount list new ArrayList();list.add(new Account(null, 剑一, 25, LocalDateTime.now()));list.add(new Account(null, 剑二, 25, LocalDateTime.now()));list.add(new Account(null, 剑三, 25, LocalDateTime.now()));int row accountMapper.insertBatch(list, 2);System.err.println(新增数量: row 条);} 9.insertOrUpdate(entity)插入或者更新若主键有值则更新若没有主键值则插入插入或者更新都不会忽略 null 值。 /*** insertOrUpdate(entity)插入或者更新若主键有值则更新若没有主键值则插入插入或者更新都不会忽略 null 值。*/Testvoid insertOrUpdate() {Account account new Account(56, 林二, 25, LocalDateTime.now());int row accountMapper.insertOrUpdate(account);System.err.println(新增/更新 数量: row 条);} 10.insertOrUpdateSelective(entity)插入或者更新若主键有值则更新若没有主键值则插入插入或者更新都会忽略 null 值。 /*** insertOrUpdateSelective(entity)插入或者更新若主键有值则更新若没有主键值则插入插入或者更新都会忽略 null 值。*/Testvoid insertOrUpdateSelective() {Account account new Account(56, 林二, null, LocalDateTime.now());int row accountMapper.insertOrUpdateSelective(account);System.err.println(新增/更新 数量: row 条);} 11. insertOrUpdate(entity, ignoreNulls)插入或者更新若主键有值则更新若没有主键值则插入。 /*** insertOrUpdate(entity, ignoreNulls)插入或者更新若主键有值则更新若没有主键值则插入。* insertOrUpdate insertOrUpdate(entity, false)* insertOrUpdateSelective insertOrUpdate(entity, true)*/Testvoid insertOrUpdate2() {Account account new Account(56, 林二, null, LocalDateTime.now());int row accountMapper.insertOrUpdate(account, false);System.err.println(新增/更新 数量: row 条);} 12.用 UpdateWrapper 新增数据 /*** 用 UpdateWrapper 新增数据* INSERT INTO tb_account(user_name, birthday)* VALUES (?, now())*/Testpublic void testInsertWithRaw() {Account account new Account();account.setUserName(剑一);Account newAccount UpdateWrapper.of(account) // .setRaw(birthday, now()) // .setRaw(ACCOUNT.BIRTHDAY, now()).setRaw(Account::getBirthday, now()).toEntity();int row accountMapper.insert(newAccount);System.err.println(新数量: row 条);}/*** 用 UpdateWrapper 新增数据 复杂一点* INSERT INTO tb_account(user_name, birthday)* VALUES (?, (select xxx from ...))*/Testpublic void testInsertWithRaw2() {Account account new Account();account.setUserName(剑二);Account newAccount UpdateWrapper.of(account).setRaw(Account::getBirthday, (select a.birthday from (SELECT birthday FROM tb_account where id 1) a )).toEntity();int row accountMapper.insert(newAccount);System.err.println(新数量: row 条);} 二 删除数据 不忽略 null 值。 就是允许有null 忽略null  就是不允许有null BaseMapper 的接口提供了 deleteById、deleteBatchByIds、deleteByMap、deleteByQuery 方法用于删除数据 deleteById(id)根据主键删除数据。如果是多个主键的情况下需要传入数组例如new Integer[]{100,101}。delete(entity)根据实体主键来删除数据。相比deleteById(id)此方法更便于对复合主键实体类的删除。deleteBatchByIds(ids)根据多个主键批量删除数据。deleteBatchByIds(ids, size)根据多个主键批量删除数据。deleteByMap(whereConditions)根据 Map 构建的条件来删除数据。deleteByCondition(whereConditions)根据查询条件来删除数据。deleteByQuery(queryWrapper)根据查询条件来删除数据。 1. deleteById(id)根据主键删除数据。如果是多个主键的情况下需要传入数组例如new Integer[]{100,101}。 /*** deleteById(id)根据主键删除数据。如果是多个主键的情况下需要传入数组例如new Integer[]{100,101}。*/Testpublic void deleteById() {int row accountMapper.deleteById(59);System.err.println(删除数量: row 条);} 2. deleteBatchByIds(ids)根据多个主键批量删除数据。 /*** deleteBatchByIds(ids)根据多个主键批量删除数据。*/Testpublic void deleteBatchByIds() {ListInteger array new ArrayListInteger();array.add(59);array.add(60);array.add(61);int row accountMapper.deleteBatchByIds(array);System.err.println(删除数量: row 条);}3. deleteBatchByIds(ids, size)根据多个主键批量删除数据。 分片删除 /*** deleteBatchByIds(ids, size)根据多个主键批量删除数据。 分片删除*/Testpublic void deleteBatchByIds2() {ListInteger array new ArrayListInteger();array.add(62);array.add(64);array.add(65);int row accountMapper.deleteBatchByIds(array, 2);System.err.println(删除数量: row 条);} 4. deleteByMap(whereConditions)根据 Map 构建的条件来删除数据。 /*** deleteByMap(whereConditions)根据 Map 构建的条件来删除数据。*/Testpublic void deleteByMap() {//条件 where id 63 and age 18MapString, Object map new HashMap();map.put(id, 63);map.put(age, 18);int row accountMapper.deleteByMap(map);System.err.println(删除数量: row 条);}5.deleteByCondition(whereConditions)根据查询条件来删除数据。 /*** deleteByCondition(whereConditions)根据查询条件来删除数据。* ge * le * gt * eq * lt * notIN*/Testpublic void deleteByCondition() {//accountMapper.deleteByCondition(ACCOUNT.ID.ge(100)); // int row accountMapper.deleteByCondition(ACCOUNT.ID.in(67,69));int row accountMapper.deleteByCondition(ACCOUNT.ID.eq(70));System.err.println(删除数量: row 条);} 6.deleteByQuery(queryWrapper)根据查询条件来删除数据。 /*** deleteByQuery(queryWrapper)根据查询条件来删除数据。*/Testpublic void deleteByQuery() {QueryWrapper queryWrapper QueryWrapper.create();queryWrapper.where(ACCOUNT.ID.ge(66));//通过 queryWrapper 删除int row accountMapper.deleteByQuery(queryWrapper);System.err.println(删除数量: row 条);} 三 更新数据 不忽略 null 值。 就是允许有null 忽略null  就是不允许有null BaseMapper 的接口提供了 update、updateByMap、updateByQuery 方法用于更新数据 update(entity)根据主键来更新数据若实体类属性数据为 null该属性不会更新到数据库。update(entity, ignoreNulls)根据主键来更新数据到数据库。updateByMap(entity, whereConditions)根据 Map 构建的条件来更新数据。updateByMap(entity, ignoreNulls, whereConditions)根据 Map 构建的条件来更新数据。updateByCondition(entity, whereConditions)根据查询条件来更新数据。updateByCondition(entity, ignoreNulls, whereConditions)根据查询条件来更新数据。updateByQuery(entity, queryWrapper)根据查询条件来更新数据。updateByQuery(entity, ignoreNulls, queryWrapper)根据查询条件来更新数据。updateNumberAddByQuery(fieldName, value, queryWrapper)执行类似 update table set field field 1 where ... 的场景。updateNumberAddByQuery(column, value, queryWrapper)执行类似 update table set field field 1 where ... 的场景。updateNumberAddByQuery(fn, value, queryWrapper)执行类似 update table set field field 1 where ... 的场景。 1.update(entity)根据主键来更新数据若实体类属性数据为 null该属性不会更新到数据库。 /*** update(entity)根据主键来更新数据若实体类属性数据为 null该属性不会更新到数据库。*/Testpublic void update() {Account account new Account();account.setUserName(小明);account.setAge(18);account.setBirthday(LocalDateTime.now());account.setId(72);int row accountMapper.update(account);System.err.println(修改数量: row 条);} 2.update(entity, ignoreNulls)根据主键来更新数据到数据库。 /*** update(entity, ignoreNulls)根据主键来更新数据到数据库。*/Testpublic void update2() {Account account new Account();account.setUserName(小明1);account.setId(72);int row accountMapper.update(account,false);System.err.println(修改数量: row 条);} 3.updateByMap(entity, whereConditions)根据 Map 构建的条件来更新数据。不忽略NUll /*** updateByMap(entity, whereConditions)根据 Map 构建的条件来更新数据。* 不忽略NUll**/Testpublic void updateByMap() {Account account new Account();account.setUserName(小明2);MapString, Object map new HashMap();map.put(id,72);int row accountMapper.updateByMap(account,map);System.err.println(修改数量: row 条);} 4.updateByMap(entity, ignoreNulls, whereConditions)根据 Map 构建的条件来更新数据。  忽略null /*** updateByMap(entity, ignoreNulls, whereConditions)根据 Map 构建的条件来更新数据。* 忽略null*/Testpublic void updateByMap2() {Account account new Account(); // account.setUserName(小明2);account.setUserName(null); //会报错MapString, Object map new HashMap();map.put(id,72);int row accountMapper.updateByMap(account,true,map);System.err.println(修改数量: row 条);} 5.updateByCondition(entity, whereConditions)根据查询条件来更新数据。 不忽略NUll /*** updateByCondition(entity, whereConditions)根据查询条件来更新数据。* 不忽略NUll*/Testpublic void updateByCondition() {Account account new Account();account.setUserName(剑南山2); // account.setUserName(null); //会报错// update tb_account set user_name剑南山2 , age21 where id 73 // int row accountMapper.updateByCondition(account,ACCOUNT.ID.eq(73));// update tb_account set user_name剑南山2 , age21 where id 73int row accountMapper.updateByCondition(account,ACCOUNT.ID.gt(73));System.err.println(修改数量: row 条);} 6.updateByCondition(entity, ignoreNulls, whereConditions)根据查询条件来更新数据。忽略NUll,传入空不修改 /*** updateByCondition(entity, ignoreNulls, whereConditions)根据查询条件来更新数据。* 忽略NUll,传入空不修改*/Testpublic void updateByCondition2() {Account account new Account();account.setUserName(null); //默认不修改account.setAge(18); // account.setUserName(null); //会报错// update tb_account set age18 where id 73 // int row accountMapper.updateByCondition(account,ACCOUNT.ID.eq(73));// update tb_account set age18 where id 73int row accountMapper.updateByCondition(account,true,ACCOUNT.ID.gt(73));System.err.println(修改数量: row 条);} 7.updateByQuery(entity, queryWrapper)根据查询条件来更新数据。不忽略NUll /*** updateByQuery(entity, queryWrapper)根据查询条件来更新数据。* 不忽略NUll*/Testpublic void updateByQuery() {Account account new Account();account.setUserName(神奇的小鱼人);account.setAge(20);QueryWrapper queryWrapper new QueryWrapper();// update tb_account set user_name神奇的小鱼人 , age21 where id 73 or id 74queryWrapper.where(ACCOUNT.ID.eq(73)).or(ACCOUNT.ID.eq(74));int row accountMapper.updateByQuery(account,queryWrapper);System.err.println(修改数量: row 条);} 7.updateByQuery(entity, ignoreNulls, queryWrapper)根据查询条件来更新数据。 忽略NUll /*** updateByQuery(entity, ignoreNulls, queryWrapper)根据查询条件来更新数据。* 忽略NUll*/Testpublic void updateByQuery2() {Account account new Account();account.setUserName(null); //忽略NULL 不进行updateaccount.setAge(20);QueryWrapper queryWrapper new QueryWrapper();// update tb_account set age21 where id 73 or id 74queryWrapper.where(ACCOUNT.ID.eq(73)).or(ACCOUNT.ID.eq(74));int row accountMapper.updateByQuery(account,queryWrapper);System.err.println(修改数量: row 条);} 8.updateByQuery(entity, ignoreNulls, queryWrapper)根据查询条件来更新数据。 不忽略NUll /*** updateByQuery(entity, ignoreNulls, queryWrapper)根据查询条件来更新数据。* ignoreNulls:false 忽略NUll* ignoreNulls:true 不忽略NUll**/Testpublic void updateByQuery2() {Account account new Account();account.setUserName(null); //忽略NULL 不进行updateaccount.setAge(20);QueryWrapper queryWrapper new QueryWrapper();// update tb_account set age21 where id 73 or id 74queryWrapper.where(ACCOUNT.ID.eq(73)).or(ACCOUNT.ID.eq(74));int row accountMapper.updateByQuery(account,false,queryWrapper);System.err.println(修改数量: row 条);} 9. 部分字段更新 update (1) 部分字段 在很多场景下我们希望只更新部分字段而更新的字段中一些为 null一些非 null。此时需要用到 UpdateEntity 工具类以下是示例代码 以下的示例中会把 id (主键)为 100 这条数据中的 user_name 字段更新为 nullage 字段更新为 10其他字段不会被更新。 也就是说通过 UpdateEntity 创建的对象只会更新调用了 setter 方法的字段若不调用 setter 方法不管这个对象里的属性的值是什么都不会更新到数据库。 /*** updateByQuery(entity, ignoreNulls, queryWrapper)根据查询条件来更新数据。* 不忽略NUll*/Testpublic void UpdateEntity () {//update tb_account//set user_name ?, age ? where id ?//#参数: null,10,100//写法1 不忽略NUll // Account account UpdateEntity.of(Account.class, 100);//写法2 不忽略NUll // Account account UpdateEntity.of(Account.class); // account.setId(74);//写法3 忽略null//update tb_account//set age ? where id ?//#参数: 10,100Account account new Account();account.setId(74);account.setUserName(null);account.setAge(11);int row accountMapper.update(account);System.err.println(修改数量: row 条);} (2) 部分字段更新增强 /*** 部分字段更新增强*/Testpublic void UpdateEntity2 () {Account account UpdateEntity.of(Account.class, 100);account.setUserName(null);// 通过 UpdateWrapper 操作 account 数据UpdateWrapper wrapper UpdateWrapper.of(account);wrapper.setRaw(age, age 1);accountMapper.update(account);// update tb_account//set user_name null, age age 1 where id 100int row accountMapper.update(account);System.err.println(修改数量: row 条);} (3) 更高级的用法 /*** 更高级的用法2*/Testpublic void UpdateEntity4 () {Account account UpdateEntity.of(Account.class, 100);// account.setUserName(Michael2); // 通过 UpdateWrapper 操作 account 数据UpdateWrapper wrapper UpdateWrapper.of(account); // wrapper.setRaw(ACCOUNT.AGE, (select a.age from (select age from tb_account where id 101) a ));wrapper.set(ACCOUNT.USER_NAME, (select name from tb_account where id 101));accountMapper.update(account);int row accountMapper.update(account);System.err.println(修改数量: row 条);} 10. 链式修改-UpdateChain UpdateChain 是一个对 UpdateEntity、UpdateWrapper 等进行封装的一个工具类方便用户用于进行链式操作。 假设我们要更新 Account 的 userName 为 张三更新年龄在之前的基础上加 1更新代码如下 /*** UpdateChain 是一个对 UpdateEntity、UpdateWrapper 等进行封装的一个工具类方便用户用于进行链式操作。* 不忽略空* UPDATE tb_account SET user_name 张三 , age age 1* WHERE id 1** UPDATE tb_account SET user_name null , age age 1* WHERE id 1*/Testpublic void testUpdateChain() {UpdateChain.of(Account.class) // .set(Account::getUserName, 张三).set(Account::getUserName, null).setRaw(Account::getAge, age 1).where(Account::getId).eq(1).update();}/*** 假设我们要更新 Account 的 userName 为 张三更新年龄在之前的基础上加 1更新代码如下* UPDATE tb_account SET age age 1* WHERE id 100 AND age 18**/Testpublic void testUpdateChain2() {//更新数据UpdateChain.of(Account.class).set(Account::getAge, ACCOUNT.AGE.add(1)).where(Account::getId).ge(100).and(Account::getAge).eq(18).update();//查询所有数据并打印QueryChain.of(accountMapper).where(Account::getId).ge(100).and(Account::getAge).eq(18).list().forEach(System.out::println);}四 基础查询 单条数据查询​ 在 MyBatis-Flex 的 BaseMapper 中提供了如下的功能用于查询数据库的数据 selectOneById(id)根据主键查询数据。selectOneByEntityId(entity)根据实体主键查询数据便于对复合主键实体类的查询。selectOneByMap(whereConditions)根据 Map 构建的条件来查询数据。selectOneByCondition(whereConditions)根据查询条件查询数据。selectOneByQuery(queryWrapper)根据查询条件来查询 1 条数据。selectOneByQueryAs(queryWrapper, asType)根据查询条件来查询 1 条数据。selectOneWithRelationsByMap(whereConditions)根据 Map 构建的条件来查询 1 条数据。selectOneWithRelationsByCondition(whereConditions)根据查询条件查询 1 条数据。selectOneWithRelationsByQuery(queryWrapper)根据查询条件来查询 1 条数据。selectOneWithRelationsByQueryAs(queryWrapper, asType)根据查询条件来查询 1 条数据。selectListByIds(ids)根据多个主键来查询多条数据。selectListByMap(whereConditions)根据 Map 来构建查询条件查询多条数据。selectListByMap(whereConditions, count)根据 Map 来构建查询条件查询多条数据。selectListByCondition(whereConditions)根据查询条件查询多条数据。selectListByCondition(whereConditions, count)根据查询条件查询多条数据。selectListByQuery(queryWrapper)根据查询条件查询数据列表。selectListByQuery(queryWrapper, consumers)根据查询条件查询数据列表。selectCursorByQuery(queryWrapper)根据查询条件查询游标数据该方法必须在事务中才能正常使用非事务下无法获取数据。selectRowsByQuery(queryWrapper)根据查询条件查询 Row 数据。selectListByQueryAs(queryWrapper, asType)根据查询条件查询数据列表要求返回的数据为 asType。这种场景一般用在 left join 时有多出了实体类本身的字段内容可以转换为 dto、vo 等场景。selectListByQueryAs(queryWrapper, asType, consumers)根据查询条件查询数据列表要求返回的数据为 asType 类型。selectListWithRelationsByQuery(queryWrapper)查询实体类及其 Relation 注解字段。selectListWithRelationsByQueryAs(queryWrapper, asType)查询实体类及其 Relation 注解字段。selectListWithRelationsByQueryAs(queryWrapper, asType, consumers)查询实体类及其 Relation 注解字段。selectAll()查询全部数据。selectAllWithRelations()查询全部数据及其 Relation 字段内容。selectObjectByQuery(queryWrapper)查询第一列返回的数据QueryWrapper 执行的结果应该只有 1 列例如QueryWrapper.create().select(ACCOUNT.id).where(...);selectObjectByQueryAs(queryWrapper, asType)查询第一列返回的数据QueryWrapper 执行的结果应该只有 1 列例如QueryWrapper.create().select(ACCOUNT.id).where(...);selectObjectListByQuery(queryWrapper)查询第一列返回的数据集合QueryWrapper 执行的结果应该只有 1 列例如QueryWrapper.create().select(ACCOUNT.id).where(...);selectObjectListByQueryAs(queryWrapper, asType)查询第一列返回的数据集合QueryWrapper 执行的结果应该只有 1 列例如QueryWrapper.create().select(ACCOUNT.id).where(...);selectCountByQuery(queryWrapper)查询数据量。selectCountByCondition(whereConditions)根据条件查询数据总量。 1. selectOneById(id)根据主键查询数据。 /*** selectOneById(id)根据主键查询数据。*/Testpublic void testUpdateChain() {Account account accountMapper.selectOneById(1L);System.err.println();System.err.println(account);System.err.println();} 2.selectOneByEntityId(entity)根据实体主键查询数据便于对复合主键实体类的查询。 只能根据主键查询 /*** selectOneByEntityId(entity)根据实体主键查询数据便于对复合主键实体类的查询。*/Testpublic void selectOneByEntityId() {Account param new Account();param.setId(1);Account account accountMapper.selectOneByEntityId(param);System.err.println();System.err.println(account);System.err.println();Account param2 new Account();param.setAge(18);param.setUserName(剑南山2);Account account2 accountMapper.selectOneByEntityId(param2);System.err.println();System.err.println(account2);System.err.println();} 3.selectOneByMap(whereConditions)根据 Map 构建的条件来查询数据。 /*** selectOneByMap(whereConditions)根据 Map 构建的条件来查询数据。* * selectOneByMap(MapString, Object whereConditions)*/Testpublic void selectOneByMap() {MapString,Object param new HashMap();param.put(id,2);param.put(user_name,李四);Account account accountMapper.selectOneByMap(param);System.err.println();System.err.println(account);System.err.println();} 4.selectOneByCondition(whereConditions)根据查询条件查询数据。 /*** selectOneByCondition(whereConditions)根据查询条件查询数据。** selectOneByCondition(QueryCondition whereConditions)*/Testpublic void selectOneByCondition() {Account account accountMapper.selectOneByCondition(ACCOUNT.ID.eq(2).or(ACCOUNT.ID.eq(1)));System.err.println();System.err.println(account);System.err.println();} 5. selectOneByQuery(queryWrapper)根据查询条件来查询 1 条数据。 /*** selectOneByQuery(queryWrapper)根据查询条件来查询 1 条数据。* selectOneByQuery(QueryWrapper queryWrapper)*/Testpublic void selectOneByQuery() {QueryWrapper param new QueryWrapper();// where id 1 // param.where(ACCOUNT.ID.eq(1));//SELECT id, user_name, age, birthday FROM tb_account WHERE user_name LIKE ? LIMIT 1//Parameters: %李四%(String)param.where(ACCOUNT.USER_NAME.like(李四));Account account accountMapper.selectOneByQuery(param);System.err.println();System.err.println(account);System.err.println();} 6. selectOneWithRelationsByMap(whereConditions)根据 Map 构建的条件来查询 1 条数据。 /*** selectOneWithRelationsByMap(whereConditions)根据 Map 构建的条件来查询 1 条数据。** selectOneWithRelationsByMap(MapString, Object whereConditions)*/Testpublic void selectOneWithRelationsByMap() {MapString,Object param new HashMap();param.put(id,1);// Preparing: SELECT id, user_name, age, birthday FROM tb_account WHERE tb_account.id ? LIMIT 1// Parameters: 1(Integer)Account account accountMapper.selectOneWithRelationsByMap(param);System.err.println();System.err.println(account);System.err.println();} 7.selectOneWithRelationsByCondition(whereConditions)根据查询条件查询 1 条数据。 /*** selectOneWithRelationsByCondition(whereConditions)根据查询条件查询 1 条数据。*/Testpublic void selectOneWithRelationsByCondition() { // Preparing: SELECT id, user_name, age, birthday FROM tb_account WHERE tb_account.id ? LIMIT 1// Parameters: 1(Integer)Account account accountMapper.selectOneWithRelationsByCondition(ACCOUNT.ID.eq(1));System.err.println();System.err.println(account);System.err.println();}8.selectOneWithRelationsByQuery(queryWrapper)根据查询条件来查询 1 条数据。 /*** selectOneWithRelationsByQuery(queryWrapper)根据查询条件来查询 1 条数据。*/Testpublic void selectOneWithRelationsByQuery() {// Preparing: SELECT id, user_name, age, birthday FROM tb_account WHERE tb_account.id ? LIMIT 1// Parameters: 1(Integer)QueryWrapper param new QueryWrapper();param.where(ACCOUNT.ID.eq(1));Account account accountMapper.selectOneWithRelationsByQuery(param);System.err.println();System.err.println(account);System.err.println();} 9.selectOneWithRelationsByQueryAs(queryWrapper, asType)根据查询条件来查询 1 条数据。 /*** selectOneWithRelationsByQueryAs(queryWrapper, asType)根据查询条件来查询 1 条数据。*/Testpublic void selectOneWithRelationsByQueryAs() {// Preparing: SELECT id, user_name, age, birthday FROM tb_account WHERE tb_account.id ? LIMIT 1// Parameters: 1(Integer)QueryWrapper param new QueryWrapper();param.where(ACCOUNT.ID.eq(1));Account account accountMapper.selectOneWithRelationsByQueryAs(param,Account.class);System.err.println();System.err.println(account);System.err.println();} 多条数据查询 1.selectListByIds(ids)根据多个主键来查询多条数据。 /*** selectListByIds(ids)根据多个主键来查询多条数据。* selectListByIds(Param($$primaryValue) Collection? extends Serializable var1)*/Testpublic void selectListByIds() {ListInteger param Arrays.asList(1, 2);//Preparing: SELECT id, user_name, age, birthday FROM tb_account WHERE id ? OR id ?//Parameters: 1(Integer), 2(Integer)////Account(id1, userNamenull, age20, birthday2020-01-11T00:00)//Account(id2, userName李四, age19, birthday2021-03-21T00:00)//ListAccount accounts accountMapper.selectListByIds(param);System.err.println();accounts.forEach(System.err::println);System.err.println();}2.selectListByMap(whereConditions)根据 Map 来构建查询条件查询多条数据。 /*** selectListByMap(whereConditions)根据 Map 来构建查询条件查询多条数据。*/Testpublic void selectListByMap() {MapString, Object param new HashMap();param.put(user_name,剑南山2);//Preparing: SELECT id, user_name, age, birthday FROM tb_account WHERE tb_account.user_name ?//Parameters: 剑南山2(String)////Account(id99, userName剑南山2, age18, birthday2023-12-29T18:17:31)//Account(id101, userName剑南山2, age19, birthday2020-01-11T00:00)//ListAccount accounts accountMapper.selectListByMap(param);System.err.println();accounts.forEach(System.err::println);System.err.println();}
http://www.hkea.cn/news/14361482/

相关文章:

  • 苏州网站建设方案策划中文 域名的网站
  • 主做收影视出版的小说网站广州企业网站设计方案
  • 网站模块是什么温州招聘网
  • 免费做App和网站的平台彭阳网站建设多少钱
  • 沈阳网站建设教案模板如何用dw制作简单网页
  • 中国建设银行个人网上银行网站wordpress怎么安装老版编辑器
  • 济宁网站建设制作设计兰州400电话网站建设
  • 企业网站建设的总体架构做企业网站赚钱吗
  • 廊坊高端网站建设网络营销策略分析论文
  • 网站开发信息平台项目总结上海市建筑业官网
  • 江苏省水利工程建设局网站深圳seo排名
  • 南充建设公司网站wordpress首部如何添加自定义代码
  • 汝州市文明建设网站中国知名企业有哪些
  • 网站中文字内容左右切换的js代码asp.net网站入侵
  • 网站建设如何算成本农产品网站建设及优化项目
  • 资金盘网站怎么建设北京海淀区工商局网站
  • 怎么给网站做推广工作组赴平凉事故现场
  • 游戏网站的设计方案wordpress 漏洞
  • 手机电商网站 模板上海汽车网站建设
  • 怎么让网站无法自适应wordpress免费版
  • 找人做网站需要注意什么网站建设公司巨头
  • 免费教育网站建设网站建设运营预算明细
  • 湘潭网站建设厦门网站制作迁移wordpress 500
  • 金华公司建站模板淄博乐达网站建设吧
  • 网站页面设计说明书网站如何做市场推广
  • 电子商务网站建设开发文档网页设计与制作实训报告结果
  • 建设网站的和服务器用myeclipse做网站
  • 网站seo是干什么的中小企业网络架构
  • wordpress免备案空间seo网站优化
  • 网站顶部悬浮广告代码宜宾建设教育培训中心网站