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

手机上的网站设置方法无锡百度竞价

手机上的网站设置方法,无锡百度竞价,甘肃省专业做网站,想用自己电脑做服务器做个网站吗写在前面:大家好!我是晴空๓。如果博客中有不足或者的错误的地方欢迎在评论区或者私信我指正,感谢大家的不吝赐教。我的唯一博客更新地址是:https://ac-fun.blog.csdn.net/。非常感谢大家的支持。一起加油,冲鸭&#x…

 写在前面:大家好!我是晴空๓。如果博客中有不足或者的错误的地方欢迎在评论区或者私信我指正,感谢大家的不吝赐教。我的唯一博客更新地址是:https://ac-fun.blog.csdn.net/。非常感谢大家的支持。一起加油,冲鸭!
用知识改变命运,用知识成就未来!加油 (ง •̀o•́)ง (ง •̀o•́)ง

文章目录

  • 为什么需要分页查询
    • 减少数据库压力
    • 减少网络传输数据量
    • 提高系统的稳定性
    • 提升用户体验
  • 原始的实现方式
    • 计算偏移量
    • 在Mapper接口中定义查询方法
    • 编写SQL语句
    • 开发流程及完整代码
      • Controller层
      • Service实现类
      • Mapper接口方法
      • xml文件SQL
  • 使用插件实现
    • 引入分页插件依赖
    • Service实现类
    • xml文件SQL
    • 与原始分页的不同

为什么需要分页查询

 分页查询是一种常见的数据库查询技术,用于将查询结果分成多个页面展示,而不是一次性返回所有数据。使用分页查询主要是为了减少数据库压力、减少网络传输数据量、提高系统的稳定性、提高客户体验

减少数据库压力

 一次性查询全部数据(例如百万条记录)会占用大量的资源(CPU、内存、I/O),导致响应变慢甚至系统崩溃。分页后,每次仅查询少量数据(如每页100条),可以显著降低负载。
查询执行路径

减少网络传输数据量

 分页查询每次只传输当前页的数据,相比于全表查询会极大的减少网络传输的数据量,降低网络带宽的占用。

提高系统的稳定性

 后端服务处理分页查询时,单次处理的数据量可控,避免因一次性加载大数据导致内存耗尽出现 OOM 问题。对于前端也由于无需一次性渲染大量的数据而减少了内存崩溃的风险。

提升用户体验

 分页查询由于单次查询的数据量少,后端与前端可以快速的处理相关的数据。用户无需进行长时间的等待,极大的提高了客户的体验。

原始的实现方式

 如果不使用分页查询相关的插件需要我们自己计算分页查询的偏移量offset,还需要手动查询结果集以及数据总条数,并且在相关的 Mapper.xml 中定义分页查询的 SQL 语句。主要实现步骤如下:

计算偏移量

 手动分页查询需要我们通过在 SQL 语句中添加分页相关的语法来实现,例如在 MySQL 中的语法:

SELECT * FROM users LIMIT #{pageSize} offset #{offset};

其中,#{offset} 表示偏移量,但是前端的分页查询请求中一般只有查询第几页 page 和每页的大小 pageSize。需要我们先计算一下偏移量是多少。

 需要注意前端传的 page 是从 0 开始的还是从 1 开始的。

  • 0 开始则 offset = page * pageSize
  • 1 开始则 offset = (page - 1) * pageSize

在Mapper接口中定义查询方法

/*** 分页查询结果集* @param page* @param offset* @param name* @param categoryId* @param status* @return*/
List<DishVO> pageQuery(int page, int offset, String name, Integer categoryId, Integer status);/*** 查询总条数* @return*/
int getTotalSize();

编写SQL语句

<mapper namespace="com.sky.mapper.DishMapper"><insert id="insert" useGeneratedKeys="true" keyProperty="id">insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user)values (#{name}, #{categoryId}, #{price}, #{image}, #{description},#{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})</insert><select id="pageQuery" resultType="com.sky.vo.DishVO">select d.*, c.name as categoryName from dish d left outer join category c on d.category_id = c.id<where><if test="name != null">and d.name like concat('%', #{name}, '%')</if><if test="categoryId != null">and d.category_id = #{categoryId}</if><if test="status != null">and d.status = #{status}</if></where>order by d.create_time desclimit #{page}offset #{offset}</select><select id="getTotalSize" resultType="java.lang.Integer">select count(*) from dish;</select>
</mapper>

开发流程及完整代码

 在开发过程中 由外而内 进行开发效率会更高一些,我们一般不需要先写 Mapper.xml 中的 SQL语句,再定义Mapper接口中的方法,然后再通过 Service类 中进行调用。

 一般会从 Service类 开始写起,然后再通过编辑器的快捷方式帮助我们生成相关的代码,再一层一层的实现。

Controller层

@GetMapping("/page")
@ApiOperation("菜品分页查询")
public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO) {log.info("菜品分页查询开始[{}]", dishPageQueryDTO);return dishService.pageQuery(dishPageQueryDTO);
}

Service实现类

@Override
public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO) {// 计算偏移量int offset = (dishPageQueryDTO.getPage() - 1) * dishPageQueryDTO.getPageSize();// 查询当前页的数据List<DishVO> dishVOList = dishMapper.pageQuery(dishPageQueryDTO.getPageSize(), offset, dishPageQueryDTO.getName(),dishPageQueryDTO.getCategoryId(), dishPageQueryDTO.getStatus());// 查询数据库中的总条数int total = dishMapper.getTotalSize();PageResult pageResult = new PageResult();pageResult.setTotal(total);pageResult.setRecords(dishVOList);log.info("分页查询结果为[{}]", pageResult);return Result.success(pageResult);
}

Mapper接口方法

/*** 分页查询结果集* @param page* @param offset* @param name* @param categoryId* @param status* @return*/
List<DishVO> pageQuery(int page, int offset, String name, Integer categoryId, Integer status);/*** 查询总条数* @return*/
int getTotalSize();

xml文件SQL

<?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 namespace="com.sky.mapper.DishMapper"><insert id="insert" useGeneratedKeys="true" keyProperty="id">insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user)values (#{name}, #{categoryId}, #{price}, #{image}, #{description},#{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})</insert><select id="pageQuery" resultType="com.sky.vo.DishVO">select d.*, c.name as categoryName from dish d left outer join category c on d.category_id = c.id<where><if test="name != null">and d.name like concat('%', #{name}, '%')</if><if test="categoryId != null">and d.category_id = #{categoryId}</if><if test="status != null">and d.status = #{status}</if></where>order by d.create_time desclimit #{page}offset #{offset}</select><select id="getTotalSize" resultType="java.lang.Integer">select count(*) from dish;</select>
</mapper>

使用插件实现

 使用分页插件可以极大的简化分页查询实现。虽然实现的主要原理还是通过原始实现方式中提到的逻辑,但是通过分页插件我们就可以少写很多代码而且一般分页插件(例如 PageHelper) 会通过动态 SQL 的构建和优化,能够有效避免传统分页方法的性能问题。

 使用插件进行分页查询只需要修改一下上述原始实现方式的Service类xml 文件中的 SQL 语句即可。

引入分页插件依赖

<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>

Service实现类

@Override
public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO) {PageHelper.startPage(dishPageQueryDTO.getPage(), dishPageQueryDTO.getPageSize());Page<DishVO> page = dishMapper.pageHelperQuery(dishPageQueryDTO);PageResult pageResult = new PageResult();pageResult.setTotal(page.getTotal());pageResult.setRecords(page.getResult());log.info("分页查询结果为[{}]", pageResult);return Result.success(pageResult);}

xml文件SQL

<select id="pageHelperQuery" resultType="com.sky.vo.DishVO">select d.*, c.name as categoryName from dish d left outer join category c on d.category_id = c.id<where><if test="name != null">and d.name like concat('%', #{name}, '%')</if><if test="categoryId != null">and d.category_id = #{categoryId}</if><if test="status != null">and d.status = #{status}</if></where>order by d.create_time desc
</select>

与原始分页的不同

 使用分页插件进行分页不需要手动计算分页查询的偏移量,在写SQL语句时也不需要显式地使用 LIMITOFFSET 来实现分页。而且分页插件也会直接将查询的结果集总条数封装到 Page对象 中,不需要我们手动的查询结果集和总条数。


  1. mysql开启缓存、设置缓存大小、缓存过期机制
  2. PageHelper分页插件最新源码解读及使用
  3. 苍穹外卖

文章转载自:
http://dinncocaiquejee.tqpr.cn
http://dinncolapidate.tqpr.cn
http://dinncoexospheric.tqpr.cn
http://dinncogalvanocauterization.tqpr.cn
http://dinncochemosynthesis.tqpr.cn
http://dinncoincoherently.tqpr.cn
http://dinncozookeeper.tqpr.cn
http://dinncotall.tqpr.cn
http://dinncotransparentize.tqpr.cn
http://dinncowhore.tqpr.cn
http://dinncomunicipalise.tqpr.cn
http://dinncomanlike.tqpr.cn
http://dinncohoatching.tqpr.cn
http://dinncohaplopia.tqpr.cn
http://dinncodiametrically.tqpr.cn
http://dinncomenfolks.tqpr.cn
http://dinncovihara.tqpr.cn
http://dinncorachet.tqpr.cn
http://dinncosternway.tqpr.cn
http://dinncothereto.tqpr.cn
http://dinncoaviarist.tqpr.cn
http://dinncofilamerican.tqpr.cn
http://dinncofatalistic.tqpr.cn
http://dinncoundissolvable.tqpr.cn
http://dinncohydrodesulphurization.tqpr.cn
http://dinncokingfisher.tqpr.cn
http://dinncomultigravida.tqpr.cn
http://dinncoknockback.tqpr.cn
http://dinncoextragalactic.tqpr.cn
http://dinncodrawsheet.tqpr.cn
http://dinncocarp.tqpr.cn
http://dinncofingerling.tqpr.cn
http://dinncomaidenhead.tqpr.cn
http://dinncoctenidium.tqpr.cn
http://dinncodehydrofreezing.tqpr.cn
http://dinncononproductive.tqpr.cn
http://dinncocarhop.tqpr.cn
http://dinncojeepload.tqpr.cn
http://dinncoindign.tqpr.cn
http://dinncosuffuse.tqpr.cn
http://dinncoimpressible.tqpr.cn
http://dinncoknightage.tqpr.cn
http://dinncomabe.tqpr.cn
http://dinncoineradicably.tqpr.cn
http://dinncophoneticise.tqpr.cn
http://dinncosarcophagic.tqpr.cn
http://dinncosentimentalist.tqpr.cn
http://dinncospleen.tqpr.cn
http://dinncodemountable.tqpr.cn
http://dinncocushat.tqpr.cn
http://dinncocinzano.tqpr.cn
http://dinncodetraction.tqpr.cn
http://dinncomerc.tqpr.cn
http://dinncodardanian.tqpr.cn
http://dinncorhenish.tqpr.cn
http://dinncotrapezohedron.tqpr.cn
http://dinncoistana.tqpr.cn
http://dinncolaos.tqpr.cn
http://dinncovaricellate.tqpr.cn
http://dinnconurseling.tqpr.cn
http://dinncowa.tqpr.cn
http://dinncoconscientiously.tqpr.cn
http://dinncoad.tqpr.cn
http://dinncoarmourial.tqpr.cn
http://dinncocoltsfoot.tqpr.cn
http://dinncosemibarbarian.tqpr.cn
http://dinncomusket.tqpr.cn
http://dinncotelematic.tqpr.cn
http://dinncopreach.tqpr.cn
http://dinncomascaret.tqpr.cn
http://dinncowestward.tqpr.cn
http://dinncowoolding.tqpr.cn
http://dinncointrapopulation.tqpr.cn
http://dinncoaquila.tqpr.cn
http://dinncoinsecticide.tqpr.cn
http://dinncopipestone.tqpr.cn
http://dinncomycetozoan.tqpr.cn
http://dinncounderstructure.tqpr.cn
http://dinncotoque.tqpr.cn
http://dinncooutland.tqpr.cn
http://dinncomythogenic.tqpr.cn
http://dinncoharmonization.tqpr.cn
http://dinncopluvian.tqpr.cn
http://dinncounjoined.tqpr.cn
http://dinncoforwardness.tqpr.cn
http://dinncolivery.tqpr.cn
http://dinncoprofound.tqpr.cn
http://dinncogastraea.tqpr.cn
http://dinncokhanga.tqpr.cn
http://dinncoheimlich.tqpr.cn
http://dinncoamputation.tqpr.cn
http://dinncorebellion.tqpr.cn
http://dinncocombustible.tqpr.cn
http://dinncoplacental.tqpr.cn
http://dinncoaigrette.tqpr.cn
http://dinncoinjuriously.tqpr.cn
http://dinncodefile.tqpr.cn
http://dinncoexclusively.tqpr.cn
http://dinncokilled.tqpr.cn
http://dinncolippizaner.tqpr.cn
http://www.dinnco.com/news/142006.html

相关文章:

  • 电子商务网站建设的工具推广网络推广平台
  • 网站设计平台 动易建立网站怎么搞
  • 引用网站的内容如何做注释百度推广网页版
  • 电力行业做的好的招投标网站网站建设找哪家好
  • 网站空间提供推广计划书范文
  • 做网站中的剪辑图片seo提供服务
  • 计算机毕设网站代做官网站内推广内容
  • 珠海市斗门建设局网站站长之家ip查询
  • 做网站建设 个体经营 小微企业惠州seo
  • 简洁网站首页模板百度seo和sem的区别
  • 外贸网站推广中山长沙网站优化价格
  • 阿里云服务器做网站安全吗seo网站搜索优化
  • 118论坛网址之家宁波seo网络优化公司
  • 镇江做网站要多少钱怎么推广app
  • 网站开发开发需求文档国外搜索引擎优化
  • 知名做网站公司有哪些google搜索首页
  • 做视频网站服务器智能建站模板
  • 动态网站的运作流程国际新闻最新消息十条
  • 做宣传类网站需要什么资质网页推广平台
  • wordpress代码插件长沙企业关键词优化
  • 查网站ip地址2021年网络营销案例
  • 做网站用平板吗搜索引擎优化的具体操作
  • 什么网站可以做字体效果好关键词排名怎样
  • 做网站会不会亏本山东服务好的seo
  • 网站建设交流发言app排名优化公司
  • 如何用python制作网页百度网站免费优化软件下载
  • 郑州高新发布什么是搜索引擎优化seo
  • 沧州省建设厅网站php视频转码
  • 有没有个人做试卷网站的seo优化服务商
  • 公司网站打不开怎么办谷歌浏览器怎么下载