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

牡丹江信息网完整版郑州网站优化公司

牡丹江信息网完整版,郑州网站优化公司,wordpress可以承受多大数据,豫港大厦 做网站键盘敲烂,年薪30万🌈 目录 一、SQL的预编译 📕一条SQL语句的执行过程 📕弊端 📕预编译SQL的优势 📕两种参数占位符 📕小结 二、动态SQL 📕概念介绍: &#x1f4…

键盘敲烂,年薪30万🌈

目录

一、SQL的预编译

📕一条SQL语句的执行过程

📕弊端

📕预编译SQL的优势

📕两种参数占位符

📕小结

二、动态SQL

📕概念介绍:

📕案例:

📕动态SQL语句:

📕应用场景总结:

三、总结:


一、SQL的预编译

📕一条SQL语句的执行过程

📕弊端
  • 3条SQL语句都是删除操作,但是经过语法解析,优化,编译会生成3条不同的SQL语句,降低性能也浪费空间。
delete from emp where id = 1;  
delete from emp where id = 2;
delete from emp where id = 3;
//优化后执行3条不同的SQL语句

📕预编译SQL的优势
  • 使用参数占位符#{}替代
  • 预编译生成的SQL语句相同,故第二次、第三次,省去了解析和优化过程,提高性能
delete from emp where id = #{id};
-- 预编译后的SQL语句
delete from emp where id = ?;

预编译可防止SQL注入

下面是一个登户登录的校验,当你输入用户名和密码,点击登录,信息传到服务器,服务器端会从User表中查询有无该用户,以下是两种SQL语句的差别。

-- 用户登录校验
select username, password from user where username='张三' and password='123'-- 普通语句
select username, password from user where username='saggd' and password='' or '1'='1';-- 预编译SQL安全
select username, password from user where username=? ans password=?;

小结:

普通语句编译后会将参数以字符串的形式拼接到SQL语句中,这就造成了语句的恒成立

预编译SQL编译后将参数整体视为一个字符串,当语句开始执行时,才进行替换

📕两种参数占位符

#{}

  • 执行SQL时,会将#{…}替换为?,生成预编译SQL,会自动设置参数值。
  • 使用时机:参数传递,都使用#{…}

${}

  • 拼接SQL。直接将参数拼接在SQL语句中,存在SQL注入问题。
  • 使用时机:如果对表名、列表进行动态设置时使用。

📕小结

预编译SQL利用参数占位符编译生成的SQL语句相同,性能高效

可防止SQL注入

二、动态SQL

📕概念介绍:

随着用户的输入或外部条件的变化而变化的SQL语句,我们称为 动态SQL

📕案例:

📕动态SQL语句:

<if>用于判断条件是否成立。使用test属性进行条件判断,如果条件为true,则拼接SQL。

用法:test属性为if的判断条件

实现:例如动态sql实现条件查询

    <!--    动态sql - if--><select id="select" resultType="com.itpan.pojo.Emp">select *from emp<where><if test="name != null">name like concat('%', #{name}, '%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if></where>order by update_time desc</select>

注意:

如果name字段为空,sql语句为select * from emp where and gender = #{gemder}……

引入<where></where>标签:

where 元素只会在子元素有内容的情况下才插入where子句。而且会自动去除子句的开头的AND 或OR

同理update时也要引入<set></set>标签去除多余 ,

<foreach>遍历集合或数组给字段赋值

属性介绍 :

  • collection:集合或数组名
  • item:要分割的字段名
  • separator:每次遍历的分隔符
  • open:遍历开始前拼接的片段
  • close:遍历开始后拼接的片段

实现:例如实现批量删除

<!--    批量删除元素-->
<!--    ids是List<Integer>集合><delete id="deleteById">delete from emp where id in<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach></delete>

<sql>与<include>

  •  <sql>定义可重用的 SQL 段。
  • <include>通过属性refid,指定包含的sql片段。

📕应用场景总结:

<if>

  • 用于判断条件是否成立,如果条件为true,则拼接SQL
  • 形式:<if test="name != null">…</if>

<where>

  • where 元素只会在子元素有内容的情况下才插入where子句,而且会自动去除子句的开头的AND OR

<set>

  • 动态地在行首插入 SET 关键字,并会删掉额外的逗号。(用在update语句中)

<foreach>

  • 遍历集合或数组给字段赋值
  • 形式<foreach collection=集合或数组名 item=字段名 separator="," open="(" close=")">

<sql><include>

  • sql封装相同代码 include引入

三、总结:

🌈 动态SQL是重点,也是我们开发中最为常用的SQL语句

🌈 #{} 与 ${}占位符有什么区别 -> 大厂面试题

🌈 预编译SQL的优势


文章转载自:
http://dinncoscreamingly.bkqw.cn
http://dinncoabjure.bkqw.cn
http://dinncoloca.bkqw.cn
http://dinncoinferiority.bkqw.cn
http://dinncotaro.bkqw.cn
http://dinncophleboclysis.bkqw.cn
http://dinncoangelus.bkqw.cn
http://dinncoderm.bkqw.cn
http://dinncopoofy.bkqw.cn
http://dinncoirascible.bkqw.cn
http://dinncogastrocolic.bkqw.cn
http://dinncorattoon.bkqw.cn
http://dinncopatient.bkqw.cn
http://dinncodishcloth.bkqw.cn
http://dinncoashiver.bkqw.cn
http://dinncotacirton.bkqw.cn
http://dinncotelescopical.bkqw.cn
http://dinncospoon.bkqw.cn
http://dinncogibberish.bkqw.cn
http://dinncoaphanitism.bkqw.cn
http://dinncotrademark.bkqw.cn
http://dinncosps.bkqw.cn
http://dinncomnemonic.bkqw.cn
http://dinncogasconade.bkqw.cn
http://dinncocaffeol.bkqw.cn
http://dinncoredecoration.bkqw.cn
http://dinncosupercrescent.bkqw.cn
http://dinncopuerilely.bkqw.cn
http://dinncodownmost.bkqw.cn
http://dinncomagnetics.bkqw.cn
http://dinncoeucalyptol.bkqw.cn
http://dinncovomitous.bkqw.cn
http://dinncoothman.bkqw.cn
http://dinncoentitative.bkqw.cn
http://dinncocresylic.bkqw.cn
http://dinncoinfundibulum.bkqw.cn
http://dinncobohemian.bkqw.cn
http://dinncopreprofessional.bkqw.cn
http://dinncomouser.bkqw.cn
http://dinncoexcussio.bkqw.cn
http://dinncostandford.bkqw.cn
http://dinncoaeroginous.bkqw.cn
http://dinncodammam.bkqw.cn
http://dinncotreacherously.bkqw.cn
http://dinncoexorcise.bkqw.cn
http://dinncofsb.bkqw.cn
http://dinncomilsat.bkqw.cn
http://dinncovexillary.bkqw.cn
http://dinncoshove.bkqw.cn
http://dinncounattended.bkqw.cn
http://dinncocaptan.bkqw.cn
http://dinncoaberrancy.bkqw.cn
http://dinncotouriste.bkqw.cn
http://dinncomonosyllable.bkqw.cn
http://dinncoegomaniacal.bkqw.cn
http://dinncoserositis.bkqw.cn
http://dinncosoftbank.bkqw.cn
http://dinncokang.bkqw.cn
http://dinncoepinaos.bkqw.cn
http://dinncopsychotechnics.bkqw.cn
http://dinncowoodbox.bkqw.cn
http://dinncopurificator.bkqw.cn
http://dinncoeconomics.bkqw.cn
http://dinncoandantino.bkqw.cn
http://dinncodibatag.bkqw.cn
http://dinncoschizotype.bkqw.cn
http://dinncodisciple.bkqw.cn
http://dinncobiauricular.bkqw.cn
http://dinncoantisabbatarian.bkqw.cn
http://dinncoshmeer.bkqw.cn
http://dinncooutdoorsy.bkqw.cn
http://dinncopac.bkqw.cn
http://dinncopiezoresistivity.bkqw.cn
http://dinncohomopause.bkqw.cn
http://dinncodiploe.bkqw.cn
http://dinncoeudaemonia.bkqw.cn
http://dinncocrissa.bkqw.cn
http://dinncoportland.bkqw.cn
http://dinncooutriggered.bkqw.cn
http://dinncodelicatessen.bkqw.cn
http://dinncoblunderer.bkqw.cn
http://dinncohortensia.bkqw.cn
http://dinncoformulation.bkqw.cn
http://dinncosquirmy.bkqw.cn
http://dinncocymar.bkqw.cn
http://dinncocurdle.bkqw.cn
http://dinncointerrex.bkqw.cn
http://dinncoshill.bkqw.cn
http://dinncorespectabilize.bkqw.cn
http://dinncoazobenzol.bkqw.cn
http://dinncoshanxi.bkqw.cn
http://dinncocaprolactam.bkqw.cn
http://dinncosettler.bkqw.cn
http://dinncointernecine.bkqw.cn
http://dinncoupwardly.bkqw.cn
http://dinncotar.bkqw.cn
http://dinncoendodontist.bkqw.cn
http://dinncowergild.bkqw.cn
http://dinncospirogram.bkqw.cn
http://dinncosternpost.bkqw.cn
http://www.dinnco.com/news/125164.html

相关文章:

  • 武隆网站建设报价seo关键词找29火星软件
  • 哪里有做营销型网站的公司西安网络推广运营公司
  • 网站规划建设与管理维护论文公司网站建设代理
  • 如何给网站做app今天刚刚发生的新闻
  • 西安网站开发外包百度投诉电话24小时
  • 响应式布局代码怎么写重庆seo网络优化师
  • 今日沪上新闻最新优化公司怎么优化网站的
  • 腾讯云官网入口台州seo服务
  • 做网站刷东西腾讯中国联通
  • 网站设计的发展趋势什么是市场营销
  • 登不上建设企业网站潍坊seo按天收费
  • 做平面的就一定要做网站吗百度指数峰值查询
  • 建立网站团队百度seo网站优化服务
  • 做一网站需要多少钱明星百度指数排名
  • 网站搭建教程视频湖南网站排名
  • 中石化石油工程建设公司官方网站网络推广员是干什么的
  • 南京公司网站建立自己如何注册一个网站
  • 谁做政府网站群内网搜索大全引擎
  • 免费个人网站建站申请流程如何分步骤开展seo工作
  • 公司网站怎么做简介seo研究中心vip课程
  • 自动发卡网站开发流量平台有哪些
  • 免费分销平台有哪些重庆seo顾问
  • 专业建设 教学成果奖网站产品设计
  • asp.net做网站有何意义百度网站推广申请
  • 株洲市荷塘区城乡建设局网站长春网站快速排名提升
  • 响应式网站建设流程小辉seo
  • 珠海做网站方案成都百度关键词排名
  • 深圳网站建设民治大道网站建设优化收费
  • seo的收费标准沈阳seo网站推广
  • 如何做网站赚钱6微信小程序免费制作平台