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

哪个网站可以做1040鞍山吧 百度贴吧

哪个网站可以做1040,鞍山吧 百度贴吧,企业网站建设需要哪些资料,做水果网站用什么域名MyBatis-Plus 提供了丰富的高级用法#xff0c;可以简化开发#xff0c;提高效率。以下是一些常见的可能会被忽略的用法示例。 1. 乐观锁 乐观锁用于避免在并发环境下数据更新冲突。MyBatis-Plus 通过注解和版本字段实现乐观锁。 示例#xff1a; 在实体类中添加版本字段…MyBatis-Plus 提供了丰富的高级用法可以简化开发提高效率。以下是一些常见的可能会被忽略的用法示例。 1. 乐观锁 乐观锁用于避免在并发环境下数据更新冲突。MyBatis-Plus 通过注解和版本字段实现乐观锁。 示例 在实体类中添加版本字段并使用 Version 注解标记 import com.baomidou.mybatisplus.annotation.Version;public class User {private Long id;private String name;Versionprivate Integer version;// Getters and setters }配置乐观锁插件 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();} }使用乐观锁更新 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) {// 更新操作基于版本字段UpdateWrapperUser updateWrapper Wrappers.Userupdate().eq(id, user.getId()).eq(version, user.getVersion());user.setVersion(user.getVersion() 1);userMapper.update(user, updateWrapper);} }2. 异常数据检测和自动填充 MyBatis-Plus 提供了一套通用字段自动填充功能可以在插入和更新操作时自动填充某些字段。 示例 创建自动填充处理类 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);} }在实体类中使用注解配置自动填充字段 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. 逻辑删除 逻辑删除让记录在数据库中实际存在但对外表现为已删除状态。 示例 在实体类中添加逻辑删除字段 import com.baomidou.mybatisplus.annotation.TableLogic;public class User {private Long id;private String name;TableLogicprivate Integer deleted;// Getters and setters }配置逻辑删除插件 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 ListUser getUsersByName(String name) {QueryWrapperUser queryWrapper new QueryWrapper();queryWrapper.like(name, name).eq(deleted, 0) // 逻辑未删除.orderByDesc(createTime);return userMapper.selectList(queryWrapper);} }5. 分页查询 MyBatis-Plus 提供了分页插件可轻松实现分页查询。 示例 配置分页插件 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;} }使用分页查询 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 IPageUser getUsersByPage(int page, int size) {PageUser userPage new Page(page, size);return userMapper.selectPage(userPage, null);} }6. 自定义 SQL MyBatis-Plus 支持在 Mapper 中直接编写自定义 SQL 以满足更复杂的查询需求。 示例 在 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 BaseMapperUser {Select(SELECT * FROM user WHERE name #{name})ListUser selectByName(Param(name) String name);Select(SELECT * FROM user WHERE age #{age})IPageUser selectUsersByAge(PageUser page, Param(age) int age); }使用自定义 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 ListUser getUsersByName(String name) {return userMapper.selectByName(name);}public IPageUser getUsersByAge(int age, int page, int size) {PageUser userPage new Page(page, size);return userMapper.selectUsersByAge(userPage, age);} }以上是 MyBatis-Plus 中几个特别用法的示例包括乐观锁、自动填充、逻辑删除、链式查询、分页查询和自定义 SQL。通过这些高级用法你可以大大简化开发、提升代码质量。
http://www.hkea.cn/news/14467295/

相关文章:

  • 国内p2p网站建设海珠建网站公司
  • 广州网站设计哪家公司好网站介绍怎么写范文
  • 商城网站开发多php网站开发实例教程
  • 凸一品牌策划公司镇江seo方案
  • 找人做网站内容自己编辑吗电子东莞网站建设
  • 如何把网站建设好好的seo平台
  • 网站 规划方案工业企业在线平台
  • 最好网站建站公司上海环球金融中心多少层
  • 深圳网站运营托管青海省建设厅网站执业
  • 免费网站怎么赚钱建设网站会员
  • 网站开发的背景知识和技术建网站大概多少费用
  • 珠海门户网站制作费用深圳app定制开发外包公司
  • 如何自学网站后台如何网页截图快捷键
  • 西宁网站建设开发德州做网站的公司有哪些
  • 济宁软件开发网站建设wordpress 作者 链接
  • 建设银行唐山分行网站怎么维护网站
  • 个人网页模板网站免费网站模板网
  • php网站开发步骤展示性公司网站html
  • 龙岩网站设计 信任推商吧做词金诚信矿业建设集团有限公司网站
  • 四川网站建设培训wordpress 对话
  • 建站系统低价建站新闻资讯如何网站建设公司
  • 网站前台后台齐装网装修公司
  • 网站设计客户需求网站建设方案应该怎么写
  • 上市公司中 哪家网站做的好wordpress 获取评论数
  • 建设项目招标在什么网站公示5在线做网站
  • 做网站用那种数据库建设公司网站需要准备什么科目
  • php简易购物网站开发个人中心html模板
  • 家政服务 技术支持 东莞网站建设开封景区网站建设方案
  • asp.net获取网站虚拟目录网站制作收费
  • 怎么做晒鱼的网站免费下载应用市场