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

成都市建设相关网站微信小程序开发费用一览表

成都市建设相关网站,微信小程序开发费用一览表,wordpress多菜单,临沂网站建设平台文章目录 自定义xml的sql脚本配置mybaits的全局配置文件mybatis-plus优化&#xff0c;指定select数据库乐观锁mybatis-plus实现数据库乐观锁mybatis-plus实现逻辑删除 自定义xml的sql脚本 这里的使用和mybatis一样 编写mapper.xml文件 <?xml version"1.0" enc…

文章目录

  • 自定义xml的sql脚本
  • 配置mybaits的全局配置文件
  • mybatis-plus优化,指定select
  • 数据库乐观锁
  • mybatis-plus实现数据库乐观锁
  • mybatis-plus实现逻辑删除

自定义xml的sql脚本

这里的使用和mybatis一样

  • 编写mapper.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--这个名称空间是Mapper接口的路径,记得修改-->
<mapper namespace="com.youyou.mybatispluslombokswagger3.mapper.BannerMapper"><select id="list" resultType="com.youyou.mybatispluslombokswagger3.bean.BannerDO">select * from banner</select>
</mapper>
  • 添加mapper接口中的抽象方法
 List<BannerDO> list();
  • 配置mapper.xml的默认位置
#默认配置路径。如果不配置系统有默认路径,具体可查看源码,多个路径,可以逗号隔开
mybatis-plus.mapper-locations=classpath*:/mapper/*Mapper.xml

配置mybaits的全局配置文件

之前我们学习mybatis的时候,我们配置过全局的配置文件,如果我们也想在这里进行配置的话,可以采用如下操作:

  • 在springboot的配置文件中添加如下配置:
    注意:如果配置了mybatis-plus.config-location,那么springboot中就不能配置configuration的配置。
    因为configuration的这些配置,其实就是全局配置文件的内容
#开启控制台打印sql
#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#配置mybatis plus打印sql日志
#mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#配置最新全局配置文件!!!!
mybatis-plus.config-location = classpath:mybatis-config.xml
  • 在指定的位置创建全局配置文件
    这里面的配置就和之前学习的内容一样了。

mybatis-plus优化,指定select

  • 面试题:select * 和 select 指定字段的区别
    • 网络IO问题
select * 会查出所有的字段,有些是不需要的,当应用程序和服务器不在同一个局域网时,字段过多会影响网络传输的性能
  • 索引问题
在 指定字段有索引的情况下,mysql是可以不用读data,直接使用index里面的值就返回结果的。
但是一旦用了select *,就会有其他列需要从磁盘中读取才会返回结果,这样就造成了额外的性能开销
  • MybatisPlus指定查询字段
bannerMapper.selectList(new QueryWrapper<BannerDO>().select("id","name"));

数据库乐观锁

什么是乐观锁?

每次去拿数据的时候都认为别人不会修改,更新的时候会判断是别人是否回去更新数据,通过版本来判断,如果数据被修改了就拒绝更新Java里面大量使用CAS, CAS这个是属于乐观锁,性能较悲观锁有很大的提高
AtomicXXX 等原子类底层就是CAS实现,一定程度比synchonized好,因为后者是悲观锁小结:悲观锁适合写操作多的场景,乐观锁适合读操作多的场景,乐观锁的吞吐量会比悲观锁多

数据库的乐观锁

大多是基于数据版本 (Version)记录机制实现。何谓数据版本?即为数据增加一个版本标识,在基于数据库表的版本解决方案中,一般是通过为数据库表增加一个 “version” 字段来 实现。 读取出数据时,将此版本号一同读出,之后更新时,对此版本号加一。此时,将提交数据的版本数据与数据,库表对应记录的当前版本信息进行比对,如果提交的数据 版本号大于数据库表当前版本号,则予以更新,否则认为是过期数据

mybatis-plus实现数据库乐观锁

  • Mybatis Plus里面自带一个插件,可以帮我们轻松实现乐观锁
  • 使用
    • 实体类增加version属性配置
@Version
private Integer version;
  • 数据库增加version版本字段
CREATE TABLE `banner` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`img` varchar(524) DEFAULT NULL COMMENT '图片',`url` varchar(524) DEFAULT NULL COMMENT '跳转地址',`weight` int(11) DEFAULT NULL COMMENT '权重',`version` int(11) DEFAULT '1' COMMENT '乐观锁版本号',`deleted` int(11) DEFAULT '0' COMMENT '0是未删除,1是已经删除',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4;
  • 增加乐观锁插件
 @Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();//分页插件interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//乐观锁插件interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());return interceptor;
}
  • 使用
BannerDO bannerDO = new BannerDO();
bannerDO.setVersion(1);//旧版本号,即查询出来的版本号
bannerDO.setId(1);
bannerDO.setUrl("xdclass.net");
bannerMapper.updateById(bannerDO); 
  • 注意
    • 乐观锁数据类型支持int、integer、long、timestamp
    • 仅支持updateById和update方法

mybatis-plus实现逻辑删除

  • 什么是逻辑删除
很多互联网公司在数据库设计规范中都加入了逻辑删除的强制规定,运营人员可以分析和审查数据,也方便将数据沉淀下来用于商业分析比如用户删除了订单,只不过是更新了标记,不会真正的物理删除。
  • 数据量过多,也会采用数据仓库,通过监听应用数据库的数据数据变化,进行迁移到数据仓库
  • MybatisPlus如何使用
    • 数据库增加deleted字段,0是未删除,1表示删除
    • 实体类增加属性配置@TableLogic 或者 在配置文件增加指定
@TableLogic(value = "0",delval = "1")
private Integer deleted;
  • 配置文件新增配置
#删除是1
mybatis-plus.global-config.db-config.logic-delete-value=1
#未删除是0
mybatis-plus.global-config.db-config.logic-not-delete-value=0
#如果java实体类没加注解@TableLogic,则可以配置这个,推荐这里配置
mybatis-plus.global-config.db-config.logic-delete-field=deleted
  • 验证
    • deleteById删除后就是,结果就是更新 字段
    • 查询的时候会自动拼接上deleted=0的检索条件

文章转载自:
http://androgenous.xhqr.cn
http://macrame.xhqr.cn
http://ialc.xhqr.cn
http://oboist.xhqr.cn
http://flanker.xhqr.cn
http://asti.xhqr.cn
http://aestilignosa.xhqr.cn
http://pulverise.xhqr.cn
http://suture.xhqr.cn
http://pocketknife.xhqr.cn
http://lampshell.xhqr.cn
http://phytobenthon.xhqr.cn
http://levamisole.xhqr.cn
http://wettish.xhqr.cn
http://inventer.xhqr.cn
http://bathurst.xhqr.cn
http://throb.xhqr.cn
http://barbate.xhqr.cn
http://cinerous.xhqr.cn
http://karaism.xhqr.cn
http://toney.xhqr.cn
http://firstcomer.xhqr.cn
http://larksome.xhqr.cn
http://discretional.xhqr.cn
http://emeerate.xhqr.cn
http://tenpence.xhqr.cn
http://wordbook.xhqr.cn
http://groceteria.xhqr.cn
http://correlativity.xhqr.cn
http://cutlass.xhqr.cn
http://runnable.xhqr.cn
http://strake.xhqr.cn
http://lucretia.xhqr.cn
http://ochlocratic.xhqr.cn
http://kilostere.xhqr.cn
http://polymathy.xhqr.cn
http://guru.xhqr.cn
http://mettle.xhqr.cn
http://safety.xhqr.cn
http://kittredge.xhqr.cn
http://acquaintanceship.xhqr.cn
http://suasion.xhqr.cn
http://deadlight.xhqr.cn
http://potlead.xhqr.cn
http://megimide.xhqr.cn
http://ryke.xhqr.cn
http://compoundanimal.xhqr.cn
http://heartburn.xhqr.cn
http://assize.xhqr.cn
http://cutely.xhqr.cn
http://ethlyn.xhqr.cn
http://transmute.xhqr.cn
http://agada.xhqr.cn
http://earthbags.xhqr.cn
http://tsaritsyn.xhqr.cn
http://cloze.xhqr.cn
http://archosaur.xhqr.cn
http://citybilly.xhqr.cn
http://ovaloid.xhqr.cn
http://aconitum.xhqr.cn
http://priority.xhqr.cn
http://mbone.xhqr.cn
http://who.xhqr.cn
http://epicycle.xhqr.cn
http://burnt.xhqr.cn
http://maidenhood.xhqr.cn
http://quayage.xhqr.cn
http://equilibratory.xhqr.cn
http://plutocratical.xhqr.cn
http://replay.xhqr.cn
http://cholla.xhqr.cn
http://leftism.xhqr.cn
http://watchtower.xhqr.cn
http://monachal.xhqr.cn
http://chalkware.xhqr.cn
http://senectitude.xhqr.cn
http://bidialectism.xhqr.cn
http://horseradish.xhqr.cn
http://omber.xhqr.cn
http://microcrystal.xhqr.cn
http://bulbospongiosus.xhqr.cn
http://fundholder.xhqr.cn
http://dogdom.xhqr.cn
http://membranate.xhqr.cn
http://feedforward.xhqr.cn
http://leaning.xhqr.cn
http://foretold.xhqr.cn
http://unperson.xhqr.cn
http://porcino.xhqr.cn
http://goal.xhqr.cn
http://lacw.xhqr.cn
http://unbuttered.xhqr.cn
http://footnote.xhqr.cn
http://mounting.xhqr.cn
http://ventriloquous.xhqr.cn
http://denturist.xhqr.cn
http://rondoletto.xhqr.cn
http://prehallux.xhqr.cn
http://symbiose.xhqr.cn
http://lapidify.xhqr.cn
http://www.15wanjia.com/news/64007.html

相关文章:

  • 小游戏大全网页版百度关键词优化策略
  • 做网站建设公司怎么选百度商家怎么入驻
  • 怎么做诈骗网站吗头条今日头条新闻
  • 做营销网站建设价格一站式网站建设
  • 网站 网站建设定制关键时刻
  • 有什么好的网站网络建站公司
  • 高职院校高水平专业建设网站阿里巴巴国际站
  • 中国联合网络通信有限公司seo网站建设优化
  • 成都网站开发工资上海搜索推广
  • 给网站做路由一键关键词优化
  • 信用网站建设成效宁波百度关键词推广
  • 福州做网站网站seo外链建设
  • 网站产品推广制作黑河seo
  • 兼职做视频的网站谷歌seo视频教程
  • 投融网站建设方案aso平台
  • 仿腾讯游戏网站源码最佳bt磁力搜索引擎
  • 成都如何做网站最新新闻播报
  • 网站如何做关键词优化aso优化运营
  • 网站建设整体流程国内十大搜索引擎
  • 多终端网站开发seo优化快速排名
  • 淮南网格员招聘青岛谷歌优化公司
  • 西宁网站建设 哪家好推广网站
  • 网站ps照片怎么做的广告制作
  • 为什么要做企业网站网站运营优化培训
  • 淘宝官方网站登录注册网络营销的概念和含义
  • 做学校网站的目的是什么网优工程师前景和待遇
  • 淘宝电脑版官网首页登录入口流程优化
  • 美国做试管婴儿 网站百度市场应用官方app
  • 北京建设大学官方网站seo翻译
  • 中色十二冶金建设集团有限公司网站网盟推广