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

小米网站制作海口网站排名提升

小米网站制作,海口网站排名提升,wordpress获取首页id,工作感悟前言 BaseMapperPlus并非MyBatis-Plus(MP)官方提供的标准接口,而是社区开发者基于MP的BaseMapper接口进行二次封装和增强后创建的一个自定义接口。这个概念可能因不同项目或个人实践而有所差异,但其核心思想是为了解决特定场景下…

前言

BaseMapperPlus并非MyBatis-Plus(MP)官方提供的标准接口,而是社区开发者基于MP的BaseMapper接口进行二次封装和增强后创建的一个自定义接口。这个概念可能因不同项目或个人实践而有所差异,但其核心思想是为了解决特定场景下的需求,进一步简化数据库操作,并提高开发效率。
代码示例

/*** 自定义 Mapper 接口, 实现 自定义扩展** @param <M> mapper 泛型* @param <T> table 泛型* @param <V> vo 泛型* @author xiaoli* @since 2024/1/24*/
@SuppressWarnings("unchecked")
public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {Log log = LogFactory.getLog(BaseMapperPlus.class);int DEFAULT_BATCH_SIZE = 1000;default Class<V> currentVoClass() {return (Class<V>) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 2);}default Class<T> currentModelClass() {return (Class<T>) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 1);}default Class<M> currentMapperClass() {return (Class<M>) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 0);}default List<T> selectList() {return this.selectList(new QueryWrapper<>());}/*** 批量插入*/default boolean insertBatch(Collection<T> entityList) {return insertBatch(entityList, DEFAULT_BATCH_SIZE);}/*** 批量更新*/default boolean updateBatchById(Collection<T> entityList) {return updateBatchById(entityList, DEFAULT_BATCH_SIZE);}/*** 批量插入或更新*/default boolean insertOrUpdateBatch(Collection<T> entityList) {return insertOrUpdateBatch(entityList, DEFAULT_BATCH_SIZE);}/*** 批量插入(包含限制条数)*/default boolean insertBatch(Collection<T> entityList, int batchSize) {String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.INSERT_ONE);return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize,(sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));}/*** 批量更新(包含限制条数)*/default boolean updateBatchById(Collection<T> entityList, int batchSize) {String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.UPDATE_BY_ID);return SqlHelper.executeBatch(this.currentModelClass(), log, entityList, batchSize,(sqlSession, entity) -> {MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();param.put(Constants.ENTITY, entity);sqlSession.update(sqlStatement, param);});}/*** 批量插入或更新(包含限制条数)*/default boolean insertOrUpdateBatch(Collection<T> entityList, int batchSize) {TableInfo tableInfo = TableInfoHelper.getTableInfo(this.currentModelClass());Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");String keyProperty = tableInfo.getKeyProperty();Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");return SqlHelper.saveOrUpdateBatch(this.currentModelClass(), this.currentMapperClass(), log, entityList, batchSize, (sqlSession, entity) -> {Object idVal = tableInfo.getPropertyValue(entity, keyProperty);String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.SELECT_BY_ID);return StringUtils.checkValNull(idVal)|| CollectionUtils.isEmpty(sqlSession.selectList(sqlStatement, entity));}, (sqlSession, entity) -> {MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();param.put(Constants.ENTITY, entity);String sqlStatement = SqlHelper.getSqlStatement(this.currentMapperClass(), SqlMethod.UPDATE_BY_ID);sqlSession.update(sqlStatement, param);});}/*** 插入或更新(包含限制条数)*/default boolean insertOrUpdate(T entity) {if (null != entity) {TableInfo tableInfo = TableInfoHelper.getTableInfo(this.currentModelClass());Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");String keyProperty = tableInfo.getKeyProperty();Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");Object idVal = tableInfo.getPropertyValue(entity, tableInfo.getKeyProperty());return StringUtils.checkValNull(idVal) || Objects.isNull(selectById((Serializable) idVal)) ? insert(entity) > 0 : updateById(entity) > 0;}return false;}default V selectVoById(Serializable id) {return selectVoById(id, this.currentVoClass());}/*** 根据 ID 查询*/default <C> C selectVoById(Serializable id, Class<C> voClass) {T obj = this.selectById(id);if (ObjectUtil.isNull(obj)) {return null;}return BeanCopyUtils.copy(obj, voClass);}default List<V> selectVoById(Collection<? extends Serializable> idList) {return selectVoBatchIds(idList, this.currentVoClass());}/*** 查询(根据ID 批量查询)*/default <C> List<C> selectVoBatchIds(Collection<? extends Serializable> idList, Class<C> voClass) {List<T> list = this.selectBatchIds(idList);if (CollUtil.isEmpty(list)) {return CollUtil.newArrayList();}return BeanCopyUtils.copyList(list, voClass);}default List<V> selectVoByMap(Map<String, Object> map) {return selectVoByMap(map, this.currentVoClass());}/*** 查询(根据 columnMap 条件)*/default <C> List<C> selectVoByMap(Map<String, Object> map, Class<C> voClass) {List<T> list = this.selectByMap(map);if (CollUtil.isEmpty(list)) {return CollUtil.newArrayList();}return BeanCopyUtils.copyList(list, voClass);}default V selectVoOne(Wrapper<T> wrapper) {return selectVoOne(wrapper, this.currentVoClass());}/*** 根据 entity 条件,查询一条记录*/default <C> C selectVoOne(Wrapper<T> wrapper, Class<C> voClass) {T obj = this.selectOne(wrapper);if (ObjectUtil.isNull(obj)) {return null;}return BeanCopyUtils.copy(obj, voClass);}default List<V> selectVoList(Wrapper<T> wrapper) {return selectVoList(wrapper, this.currentVoClass());}/*** 根据 entity 条件,查询全部记录*/default <C> List<C> selectVoList(Wrapper<T> wrapper, Class<C> voClass) {List<T> list = this.selectList(wrapper);if (CollUtil.isEmpty(list)) {return CollUtil.newArrayList();}return BeanCopyUtils.copyList(list, voClass);}default <P extends IPage<V>> P selectVoPage(IPage<T> page, Wrapper<T> wrapper) {return selectVoPage(page, wrapper, this.currentVoClass());}/*** 分页查询VO*/default <C, P extends IPage<C>> P selectVoPage(IPage<T> page, Wrapper<T> wrapper, Class<C> voClass) {IPage<T> pageData = this.selectPage(page, wrapper);IPage<C> voPage = new Page<>(pageData.getCurrent(), pageData.getSize(), pageData.getTotal());if (CollUtil.isEmpty(pageData.getRecords())) {return (P) voPage;}voPage.setRecords(BeanCopyUtils.copyList(pageData.getRecords(), voClass));return (P) voPage;}}

使用方法示例

// 定义实体类和Vo类
public class User {private Long id;private String username;// 其他属性、getter/setter省略...
}public class UserVo {private Long id;private String username;// 其他属性、getter/setter省略...
}// 自定义扩展的Mapper接口
public interface UserMapper extends BaseMapperPlus<UserMapper, User, UserVo> {// 可以添加更多针对User的自定义查询方法
}// Mapper接口的实现由MyBatis框架自动生成,无需手动编写// 服务层接口
public interface IUserService {UserVo queryById(Long id);// 其他业务方法...
}// 服务层实现类
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements IUserService {/** 用户Mapper接口 */private final UserMapper userMapper;/*** @Description: 根据ID查询用户信息,并转换为VO对象* @author: luojianmin (此处应替换为实际作者)* @date: 2022/6/23 9:32(此处应替换为实际日期)* @param id 用户主键* @return 用户信息VO对象*/@Overridepublic UserVo queryById(Long id) {return userMapper.selectVoById(id);}// 其他业务逻辑的实现...
}

一、BaseMapperPlus的独特作用与诞生背景

  1. 简化CRUD操作
    BaseMapper已经提供了基础的增删改查功能,然而,在实际业务开发中,我们可能会遇到更复杂的数据处理场景,比如批量插入更新、组合查询、分组统计等。BaseMapperPlus正是为了满足这些高级需求而设计,通过提供一系列便捷的方法,简化了数据操作层面上的代码编写。

  2. 定制化方法
    开发者可以根据项目特点,在BaseMapperPlus中添加一些通用的、适用于大部分实体类的方法,如根据多个字段联合查询、特殊条件下的删除操作等。这样,每个具体业务对象对应的mapper接口只需继承BaseMapperPlus就能获得丰富的预定义功能。

  3. 抽象复用
    通过创建BaseMapperPlus接口,可以将常见的数据库操作逻辑抽象出来,实现代码复用,降低重复开发成本,同时保持代码的整洁性和一致性。

二、继承BaseMapperPlus的好处

  1. 减少重复代码
    继承BaseMapperPlus后,可以直接调用其中预先定义好的方法,避免了在每个具体的mapper接口中手动编写相似的操作逻辑。

  2. 提升开发效率
    开发者无需关心底层SQL细节,仅需关注业务逻辑本身,能够更快地完成数据访问层的开发工作。

  3. 易于维护
    所有通用的数据库操作逻辑都被集中到了BaseMapperPlus中,一旦需要修改或优化,只需要在一个地方改动即可,有利于后期的维护和升级。

三、BaseMapperPlus示例方法及优势

虽然BaseMapperPlus的具体内容取决于项目的实际需求,但它通常会包含以下类型的方法:

  • 批量操作增强:如批量插入、批量更新、批量删除。
  • 条件查询增强:支持更复杂的组合查询、排序方式自定义、结果集过滤等功能。
  • 统计分析增强:提供分组统计、聚合函数使用、分页统计等功能。
  • 事务控制:如果框架本身不提供,则可以在BaseMapperPlus中加入对事务管理的支持。

相比原生的MyBatis-Plus,BaseMapperPlus的优势在于它更加贴近项目实际,具有更强的针对性和灵活性,能够解决更多个性化的需求,从而让开发者能专注于业务逻辑的实现,而不是底层数据操作的繁琐编码。

总结

尽管BaseMapperPlus不是MyBatis-Plus的标准组件,但在实际开发过程中,这样的扩展接口体现了极高的实用价值。它以一种可复用、易维护的方式增强了MyBatis-Plus的功能,使得开发者在面对各种复杂数据库操作时,能享受到更高程度的便利性。在构建项目时,建议结合具体业务需求来设计并实现一个符合自己团队习惯的BaseMapperPlus接口,从而最大化地发挥出它的价值。


文章转载自:
http://dinncoprosthesis.zfyr.cn
http://dinncoimpedient.zfyr.cn
http://dinncohexahydric.zfyr.cn
http://dinncotridymite.zfyr.cn
http://dinncogdmo.zfyr.cn
http://dinncononfluency.zfyr.cn
http://dinncohyperfragment.zfyr.cn
http://dinncobreakout.zfyr.cn
http://dinncospindleshanks.zfyr.cn
http://dinncorescind.zfyr.cn
http://dinncokeynes.zfyr.cn
http://dinncoarchness.zfyr.cn
http://dinncometalaw.zfyr.cn
http://dinncoblackheart.zfyr.cn
http://dinncoepitope.zfyr.cn
http://dinncononjoinder.zfyr.cn
http://dinncoexoenzyme.zfyr.cn
http://dinncofrusta.zfyr.cn
http://dinncogoodbye.zfyr.cn
http://dinncosouthernmost.zfyr.cn
http://dinncolysis.zfyr.cn
http://dinncoshantey.zfyr.cn
http://dinncopryer.zfyr.cn
http://dinncopriss.zfyr.cn
http://dinncoclipbook.zfyr.cn
http://dinncodifferentia.zfyr.cn
http://dinncoduyker.zfyr.cn
http://dinncoseaway.zfyr.cn
http://dinncokimberley.zfyr.cn
http://dinncothionate.zfyr.cn
http://dinncocorrespondency.zfyr.cn
http://dinncostrainmeter.zfyr.cn
http://dinncogillian.zfyr.cn
http://dinncouproar.zfyr.cn
http://dinncosublessee.zfyr.cn
http://dinncogermless.zfyr.cn
http://dinncosalicylaldehyde.zfyr.cn
http://dinncofolly.zfyr.cn
http://dinncobrowningesque.zfyr.cn
http://dinncocbd.zfyr.cn
http://dinncomishear.zfyr.cn
http://dinncosurculi.zfyr.cn
http://dinncolsv.zfyr.cn
http://dinncotomfoolery.zfyr.cn
http://dinncostreaked.zfyr.cn
http://dinncofrequentation.zfyr.cn
http://dinncokansan.zfyr.cn
http://dinncoretardate.zfyr.cn
http://dinncoliberty.zfyr.cn
http://dinncomangabey.zfyr.cn
http://dinncointimacy.zfyr.cn
http://dinncoprolonge.zfyr.cn
http://dinncotanya.zfyr.cn
http://dinncouncustomed.zfyr.cn
http://dinncopleurectomy.zfyr.cn
http://dinncoplanktology.zfyr.cn
http://dinncoinfecund.zfyr.cn
http://dinncomyology.zfyr.cn
http://dinncoagonal.zfyr.cn
http://dinncoawe.zfyr.cn
http://dinncomalvaceous.zfyr.cn
http://dinncounscrewed.zfyr.cn
http://dinncounderpan.zfyr.cn
http://dinncowindflower.zfyr.cn
http://dinncoarmguard.zfyr.cn
http://dinncooncology.zfyr.cn
http://dinncooligidic.zfyr.cn
http://dinncopolyparium.zfyr.cn
http://dinncostone.zfyr.cn
http://dinncoconcerning.zfyr.cn
http://dinncowallaceism.zfyr.cn
http://dinncoonomatopoeic.zfyr.cn
http://dinncotheatregoer.zfyr.cn
http://dinncofluoroacetamide.zfyr.cn
http://dinncoblende.zfyr.cn
http://dinncoottawa.zfyr.cn
http://dinncocarrom.zfyr.cn
http://dinncorejectivist.zfyr.cn
http://dinncovilayet.zfyr.cn
http://dinncovdr.zfyr.cn
http://dinncosextet.zfyr.cn
http://dinncohomeomorphism.zfyr.cn
http://dinncoanthroposociology.zfyr.cn
http://dinncoquinquevalence.zfyr.cn
http://dinncoaugustan.zfyr.cn
http://dinncoshopworn.zfyr.cn
http://dinnconz.zfyr.cn
http://dinncolactase.zfyr.cn
http://dinncoangiocardioraphy.zfyr.cn
http://dinncoheroise.zfyr.cn
http://dinncodigitoplantar.zfyr.cn
http://dinncowrest.zfyr.cn
http://dinncoautograph.zfyr.cn
http://dinncosanctuarize.zfyr.cn
http://dinncocannibal.zfyr.cn
http://dinncopremature.zfyr.cn
http://dinncoagamous.zfyr.cn
http://dinncounshirted.zfyr.cn
http://dinncoagrologic.zfyr.cn
http://dinncoceuca.zfyr.cn
http://www.dinnco.com/news/2007.html

相关文章:

  • 小组做数据库网站郑州网站开发顾问
  • 大学关工委加强自身建设网站宣传在线优化网站
  • 二手车网站源码下载免费网络推广软件有哪些
  • 想再算命网站上登广告怎么做网站模板
  • 芜湖做网站建设公司站长工具seo综合查询可以访问
  • 厦门外贸网站找谁长沙h5网站建设
  • dw网页设计制作网站的成品百度网盘官网登录入口
  • 利用git做网站备份环球军事网最新消息
  • 网站建设需要哪些软件在线资源搜索引擎
  • 电商学习网站搜关键词网站
  • 中小型企业网站建设的资金流动网店推广常用的方法
  • 旅游网站设计的建设原则视频外链在线生成
  • 做一个主题wordpress微软优化大师
  • 免费咨询网络游戏诈骗win7优化工具哪个好用
  • 软件工程的就业前景和就业方向廊坊seo排名公司
  • app网站建设销售广告投放怎么做
  • 室内设计效果图素材网站如何做好产品网络推广
  • 鞋帽箱包网站建设网络运营师资格证
  • 广东网站备案系统精品成品网站1688
  • 枣庄手机网站建设电话武汉网站seo公司
  • b2b2c电商平台开发惠州seo整站优化
  • 电商运营 网站运营win7优化软件
  • 怎么介绍自己的网页天津seo优化公司哪家好
  • 重生主角做视频网站的小说百度竞价优缺点
  • 哈尔滨网站运营服务商短视频营销案例
  • 品牌型网站的作用自动点击器软件
  • 南宁做网站开发的公司有哪些个人博客
  • 简述做个人网页的思路济南seo外包公司
  • 网站建设哪家好推荐万维科技公司网站设计与制作
  • 建设银行网站seo实战教程