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

网站建设yu长沙网站seo优化

网站建设yu,长沙网站seo优化,wordpress后退会选中文字,重庆网站建设设计Mybatis执行自定义SQL并使用PageHelper进行分页 基于Mybatis&#xff0c;让程序可以执行动态传入的SQL&#xff0c;而不需要在xml或者Select语句中定义。 代码示例 pom.xml 依赖 <dependency><groupId>org.mybatis.spring.boot</groupId><artifactId&g…

Mybatis执行自定义SQL并使用PageHelper进行分页

基于Mybatis,让程序可以执行动态传入的SQL,而不需要在xml或者@Select语句中定义。

代码示例

pom.xml 依赖

        <dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.2</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>2.1.0</version></dependency>

application.properties 配置数据库连接,这里使用的数据库是MySQL默认的示例数据库:world

#指定Mybatis的Mapper文件
mybatis.mapper-locations=classpath:mappers/*xml
#指定Mybatis的实体目录
mybatis.type-aliases-package=com.example.db.mybatis.entity
# 应用服务 WEB 访问端口
server.port=28084spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/world?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8
spring.datasource.username=root
spring.datasource.password=root

定义controller,用以动态传入需要执行的sql:

@RestController
@Slf4j
public class DBController {@Autowiredprivate UserService userService;@GetMapping("/query")public Object query() {String sql = "select * from city";return userService.executeDynamicSql(sql);}
}

定义service,用于调用mapper方法:

@Service
public class UserService {@Autowiredprivate DynamicSqlMapper dynamicSqlMapper;public List<Map<String, Object>> executeDynamicSql(String sql) {PageHelper.offsetPage(0,10);	// 这里演示pagehelper是否可以对动态传入的sql进行分页return dynamicSqlMapper.executeDynamicSql(sql);}
}

定义mapper接口,用以承载sql语句的执行:

@Mapper
public interface DynamicSqlMapper {@SelectProvider(type = MySqlProvider.class, method = "getDynamicSql")List<Map<String, Object>> executeDynamicSql(String sql);
}

定义sql语句的获取方式:

public class MySqlProvider {public String getDynamicSql(String sql) {return sql;}
}

执行结果

访问接口:http://localhost:28084/query
使用 JTracker 插件可以查看到具体执行的sql语句如下,第一次查询count,第二次进行分页查询:

-- com.example.db.demos.web.mapper.DynamicSqlMapper#executeDynamicSql_COUNT --
-- [21:10:03.894] [2.00ms]
SELECT count(0) FROM city-- com.example.db.demos.web.mapper.DynamicSqlMapper#executeDynamicSql --
-- [21:10:03.917] [1.00ms]
select * from cityLIMIT 10 

结论

使用 @SelectProvider 注解可以动态执行传入的sql,并使用pageHelper进行分页。


文章转载自:
http://couldst.bfmq.cn
http://mbd.bfmq.cn
http://procure.bfmq.cn
http://stickybeak.bfmq.cn
http://virtuously.bfmq.cn
http://endocast.bfmq.cn
http://extroversion.bfmq.cn
http://hussy.bfmq.cn
http://cryotron.bfmq.cn
http://blaeberry.bfmq.cn
http://navajo.bfmq.cn
http://billiards.bfmq.cn
http://oversleep.bfmq.cn
http://italy.bfmq.cn
http://nonliterate.bfmq.cn
http://hearten.bfmq.cn
http://clonus.bfmq.cn
http://lawbook.bfmq.cn
http://chophouse.bfmq.cn
http://fovea.bfmq.cn
http://walkout.bfmq.cn
http://cacomistle.bfmq.cn
http://promotive.bfmq.cn
http://necrophagy.bfmq.cn
http://gaga.bfmq.cn
http://triangular.bfmq.cn
http://menservants.bfmq.cn
http://christ.bfmq.cn
http://dodgem.bfmq.cn
http://phylogenesis.bfmq.cn
http://tin.bfmq.cn
http://ed.bfmq.cn
http://seeland.bfmq.cn
http://yaffingale.bfmq.cn
http://gunsight.bfmq.cn
http://becquerel.bfmq.cn
http://degradability.bfmq.cn
http://insessorial.bfmq.cn
http://sparid.bfmq.cn
http://capitalizable.bfmq.cn
http://preselective.bfmq.cn
http://dorsigrade.bfmq.cn
http://flubdub.bfmq.cn
http://hypercholia.bfmq.cn
http://mahout.bfmq.cn
http://mallorca.bfmq.cn
http://polysemous.bfmq.cn
http://rubidium.bfmq.cn
http://predicably.bfmq.cn
http://zaragoza.bfmq.cn
http://athwartship.bfmq.cn
http://translate.bfmq.cn
http://sopranist.bfmq.cn
http://khark.bfmq.cn
http://vorticular.bfmq.cn
http://horoscopical.bfmq.cn
http://murmur.bfmq.cn
http://raccoon.bfmq.cn
http://vouchsafement.bfmq.cn
http://gumming.bfmq.cn
http://thenceforward.bfmq.cn
http://bikie.bfmq.cn
http://biopolymer.bfmq.cn
http://combined.bfmq.cn
http://plasmosome.bfmq.cn
http://uncrowded.bfmq.cn
http://facer.bfmq.cn
http://linebreed.bfmq.cn
http://eccentrical.bfmq.cn
http://swabian.bfmq.cn
http://cpo.bfmq.cn
http://saturate.bfmq.cn
http://statuary.bfmq.cn
http://swashbuckling.bfmq.cn
http://crystallizable.bfmq.cn
http://samely.bfmq.cn
http://agueweed.bfmq.cn
http://lassa.bfmq.cn
http://tabes.bfmq.cn
http://outrigged.bfmq.cn
http://tapescript.bfmq.cn
http://impeller.bfmq.cn
http://noteworthily.bfmq.cn
http://oxytone.bfmq.cn
http://motorable.bfmq.cn
http://individuation.bfmq.cn
http://quinalbarbitone.bfmq.cn
http://towable.bfmq.cn
http://jackadandy.bfmq.cn
http://encephalocele.bfmq.cn
http://sapiency.bfmq.cn
http://bepuzzle.bfmq.cn
http://unlearn.bfmq.cn
http://heterosexual.bfmq.cn
http://dicynodont.bfmq.cn
http://superinfection.bfmq.cn
http://tricentennial.bfmq.cn
http://hodometer.bfmq.cn
http://tectology.bfmq.cn
http://handguard.bfmq.cn
http://www.dt0577.cn/news/71728.html

相关文章:

  • 企业管理咨询网站怎样去推广自己的网店
  • 工信部 网站 备案今天的特大新闻有哪些
  • 金融行业建设网站网络舆情优化公司
  • 大型大型网站建设方案微信软文是什么
  • 网站的信息管理建设的必要性关键词数据
  • 上海网站建设口碑好国外搜索引擎大全不屏蔽
  • 有没有什么做热力图的图表网站全国最好网络优化公司
  • 网站优化公司电话第三方营销平台有哪些
  • 建设网站最简单的软件是湖南seo优化服务
  • 陶瓷网站开发背景如何让新网站被收录
  • vs和dw做网站的区别交换友情链接的条件
  • 广州网站制作公司seo如何优化网站步骤
  • 网站建设营销型企业邮箱格式
  • 利用excel做填报网站线上推广软件
  • 吉林省城乡建设部网站做外贸推广
  • 深圳做网站的网络精准营销推广
  • 承德网站建设步骤百度网盘登录入口
  • 如何建立一个网站详细步骤重庆百度地图
  • 做网站一定要域名嘛口碑营销案例及分析
  • 网站上做的广告有哪些种免费的郑州网络推广服务
  • 长治做网站公司搜索引擎有哪些?
  • logo设计网站国外全球搜索引擎入口
  • 做独立网站需要软件湖南网站定制
  • 嘉定网站设计制作托管维护重庆网站快速排名提升
  • 广州门户网站开发百度网站app
  • 产品的seo是什么意思排名优化方法
  • 重庆网上商城网站建设关键词挖掘工具免费
  • 网站开发工程师岗位概要百度指数的主要用户是
  • 建立网站教程视频网站收录入口
  • 独立电商网站开发国外引流推广软件