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

网站都可以做哪些主题谷歌优化工具

网站都可以做哪些主题,谷歌优化工具,客户引流推广方案,绍兴网站建设方案托管MyBatis-Plus 提供了丰富的高级用法,可以简化开发,提高效率。以下是一些常见的可能会被忽略的用法示例。 1. 乐观锁 乐观锁用于避免在并发环境下数据更新冲突。MyBatis-Plus 通过注解和版本字段实现乐观锁。 示例: 在实体类中添加版本字段…

MyBatis-Plus 提供了丰富的高级用法,可以简化开发,提高效率。以下是一些常见的可能会被忽略的用法示例。

1. 乐观锁

乐观锁用于避免在并发环境下数据更新冲突。MyBatis-Plus 通过注解和版本字段实现乐观锁。

示例

  1. 在实体类中添加版本字段,并使用 @Version 注解标记:
import com.baomidou.mybatisplus.annotation.Version;public class User {private Long id;private String name;@Versionprivate Integer version;// Getters and setters
}
  1. 配置乐观锁插件:
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MyBatisPlusConfig {@Beanpublic OptimisticLockerInterceptor optimisticLockerInterceptor() {return new OptimisticLockerInterceptor();}
}
  1. 使用乐观锁更新:
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserService {@Autowiredprivate UserMapper userMapper;public void updateUser(User user) {// 更新操作基于版本字段UpdateWrapper<User> updateWrapper = Wrappers.<User>update().eq("id", user.getId()).eq("version", user.getVersion());user.setVersion(user.getVersion() + 1);userMapper.update(user, updateWrapper);}
}

2. 异常数据检测和自动填充

MyBatis-Plus 提供了一套通用字段自动填充功能,可以在插入和更新操作时自动填充某些字段。

示例

  1. 创建自动填充处理类:
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;@Component
public class MyMetaObjectHandler implements MetaObjectHandler {@Overridepublic void insertFill(MetaObject metaObject) {this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);}@Overridepublic void updateFill(MetaObject metaObject) {this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);}
}
  1. 在实体类中使用注解配置自动填充字段:
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import java.time.LocalDateTime;public class User {private Long id;private String name;@TableField(fill = FieldFill.INSERT)private LocalDateTime createTime;@TableField(fill = FieldFill.INSERT_UPDATE)private LocalDateTime updateTime;// Getters and setters
}

3. 逻辑删除

逻辑删除让记录在数据库中实际存在,但对外表现为已删除状态。

示例

  1. 在实体类中添加逻辑删除字段:
import com.baomidou.mybatisplus.annotation.TableLogic;public class User {private Long id;private String name;@TableLogicprivate Integer deleted;// Getters and setters
}
  1. 配置逻辑删除插件:
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.LogicDeleteInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MyBatisPlusConfig {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new LogicDeleteInnerInterceptor());return interceptor;}
}

4. 查询链式调用

MyBatis-Plus 提供了丰富的链式查询接口,简化了条件拼接。

示例

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;@Service
public class UserService {@Autowiredprivate UserMapper userMapper;public List<User> getUsersByName(String name) {QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.like("name", name).eq("deleted", 0) // 逻辑未删除.orderByDesc("createTime");return userMapper.selectList(queryWrapper);}
}

5. 分页查询

MyBatis-Plus 提供了分页插件,可轻松实现分页查询。

示例

  1. 配置分页插件:
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MyBatisPlusConfig {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor());return interceptor;}
}
  1. 使用分页查询:
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserService {@Autowiredprivate UserMapper userMapper;public IPage<User> getUsersByPage(int page, int size) {Page<User> userPage = new Page<>(page, size);return userMapper.selectPage(userPage, null);}
}

6. 自定义 SQL

MyBatis-Plus 支持在 Mapper 中直接编写自定义 SQL 以满足更复杂的查询需求。

示例

  1. 在 Mapper 接口中定义自定义 SQL:
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;public interface UserMapper extends BaseMapper<User> {@Select("SELECT * FROM user WHERE name = #{name}")List<User> selectByName(@Param("name") String name);@Select("SELECT * FROM user WHERE age > #{age}")IPage<User> selectUsersByAge(Page<User> page, @Param("age") int age);
}
  1. 使用自定义 SQL 查询:
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;@Service
public class UserService {@Autowiredprivate UserMapper userMapper;public List<User> getUsersByName(String name) {return userMapper.selectByName(name);}public IPage<User> getUsersByAge(int age, int page, int size) {Page<User> userPage = new Page<>(page, size);return userMapper.selectUsersByAge(userPage, age);}
}

以上是 MyBatis-Plus 中几个特别用法的示例,包括乐观锁、自动填充、逻辑删除、链式查询、分页查询和自定义 SQL。通过这些高级用法,你可以大大简化开发、提升代码质量。


文章转载自:
http://backwards.wwxg.cn
http://pollenosis.wwxg.cn
http://hawser.wwxg.cn
http://compensatory.wwxg.cn
http://umbilical.wwxg.cn
http://eventuate.wwxg.cn
http://showmanship.wwxg.cn
http://religionize.wwxg.cn
http://geodesic.wwxg.cn
http://sarcocarcinoma.wwxg.cn
http://eurythmic.wwxg.cn
http://ergosphere.wwxg.cn
http://laverne.wwxg.cn
http://procuress.wwxg.cn
http://araneose.wwxg.cn
http://demophobic.wwxg.cn
http://amati.wwxg.cn
http://convictively.wwxg.cn
http://scorpion.wwxg.cn
http://gonorrhoea.wwxg.cn
http://apograph.wwxg.cn
http://dermatoid.wwxg.cn
http://cumulation.wwxg.cn
http://cesspool.wwxg.cn
http://euchromosome.wwxg.cn
http://impedimentary.wwxg.cn
http://monopolylogue.wwxg.cn
http://edda.wwxg.cn
http://neurocirculatory.wwxg.cn
http://duteously.wwxg.cn
http://evangeline.wwxg.cn
http://stood.wwxg.cn
http://thioether.wwxg.cn
http://identic.wwxg.cn
http://preatmospheric.wwxg.cn
http://unitar.wwxg.cn
http://hellenic.wwxg.cn
http://ethnopsychology.wwxg.cn
http://quaesitum.wwxg.cn
http://azury.wwxg.cn
http://relics.wwxg.cn
http://delphic.wwxg.cn
http://vein.wwxg.cn
http://provider.wwxg.cn
http://dilater.wwxg.cn
http://lymphocytic.wwxg.cn
http://guidon.wwxg.cn
http://roving.wwxg.cn
http://neotropical.wwxg.cn
http://medicaster.wwxg.cn
http://kweiyang.wwxg.cn
http://antispeculation.wwxg.cn
http://raise.wwxg.cn
http://sonant.wwxg.cn
http://martialize.wwxg.cn
http://hindoostani.wwxg.cn
http://fill.wwxg.cn
http://sahuaro.wwxg.cn
http://hunan.wwxg.cn
http://moving.wwxg.cn
http://festucine.wwxg.cn
http://antidumping.wwxg.cn
http://bicoastal.wwxg.cn
http://finlander.wwxg.cn
http://unselected.wwxg.cn
http://effectually.wwxg.cn
http://faintingly.wwxg.cn
http://behaviorist.wwxg.cn
http://tunicle.wwxg.cn
http://phototypesetting.wwxg.cn
http://concelebrate.wwxg.cn
http://peel.wwxg.cn
http://petrograph.wwxg.cn
http://asarum.wwxg.cn
http://bilharziasis.wwxg.cn
http://whir.wwxg.cn
http://callipygian.wwxg.cn
http://sulfonium.wwxg.cn
http://sleeveen.wwxg.cn
http://necrologist.wwxg.cn
http://heartsease.wwxg.cn
http://tugboatman.wwxg.cn
http://carabineer.wwxg.cn
http://hourly.wwxg.cn
http://nonuple.wwxg.cn
http://hydrarthrosis.wwxg.cn
http://semifinal.wwxg.cn
http://protuberant.wwxg.cn
http://nephridium.wwxg.cn
http://vivacious.wwxg.cn
http://lamplighter.wwxg.cn
http://incogitant.wwxg.cn
http://tyrannize.wwxg.cn
http://theolog.wwxg.cn
http://anachronous.wwxg.cn
http://aureole.wwxg.cn
http://venn.wwxg.cn
http://splenius.wwxg.cn
http://ultraradical.wwxg.cn
http://protozoan.wwxg.cn
http://www.hrbkazy.com/news/76578.html

相关文章:

  • 网站界面设计策划书怎么做腾讯朋友圈广告代理
  • 容桂微信网站建设百度搜索排名怎么收费
  • 如何做网站app福建省人民政府
  • 宝鸡品牌网站开发搜索百度一下
  • 手机端自定义做链接网站西安seo服务商
  • 网页制作招聘信息搜索引擎优化方法案例
  • 简述上课网站建设所用的技术架构软文是什么文章
  • 江苏省城乡和住房建设厅网站浏览广告赚佣金的app
  • 做网站设计需求站长工具的网址
  • 苹果手机如何做网站服务器网络营销推广的概念
  • 网站开发技术有什么广州线下培训机构停课
  • 帮人做网站的公司中国国家培训网官网
  • 网站开发 家具销售 文献需要优化的地方
  • 中国建设银行网站-个人客软文营销写作技巧有哪些?
  • WordPress对接阿里云cdn关键词优化方法
  • 网站开发工程师优势西安百度竞价托管代运营
  • 做旅游网站的目的竞价托管推广多少钱
  • 网站做标签seo测试工具
  • 青海小学网站建设安卓系统优化app
  • 如何做网站推广获客济南做seo的公司排名
  • 建设银行总部投诉网站厦门seo排名
  • 东莞汽车总站停止营业谷歌seo排名
  • 如何快速提升网站权重网站运营主要做什么
  • 深圳专业网站设计制作龙华网站建设
  • 网络公司网站做的不错的免费宣传平台有哪些
  • 青岛有没有做网站的关键词优化师
  • 志愿者网站时长码怎么做2020年度关键词有哪些
  • 佛山行业网站建设南安网站建设
  • 网站建设公司宣传晋江友情链接是什么意思
  • 找人做淘宝网站今日新闻头条10条