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

多举措加强政府网站建设外贸获客软件

多举措加强政府网站建设,外贸获客软件,海口网约车平台,网架结构MyBatis 为啥MyBatis会使用xml 在一个程序中,若需要操作数据表,那么 SQL 语句有两种存放方式:1. 放到 Java 类里面(这个就存在大量的字符串拼接,还有占位符需要处理-----JDBC);2:放…

MyBatis

为啥MyBatis会使用xml

在一个程序中,若需要操作数据表,那么 SQL 语句有两种存放方式:1. 放到 Java 类里面(这个就存在大量的字符串拼接,还有占位符需要处理-----JDBC);2:放到 xml 中(但是 xml 无法被 Java 代码调用的,所以就在 Java代码和 xml 中加了一层 对xml中方法的接口声明)

image-20230201102331856

MyBatis的基本使用

MyBatis 就是一个ORM(对象关系映射)框架,将数据库中的每张表映射成Java中的类,以此可以使用OOP思想来操作数据表了

程序启动时,@Mapper注解会根据配置文件里配置的mybatis路径+命名来讲接口与xml文件进行关联,并将@Mapper注解修饰的接口放入Spring中

配置数据库连接 + MyBatis 的 xml 存放路径 + 命名格式(xml中存放的就是数据表的操作语句)

image-20230115144955108

@Mapper

@Mapper注解比较特殊,虽然是修饰接口的,但是也能将其放入Spring中,然后使用@Autowired进行注入,并直接当作对象来调用其中的方法

image-20230201133703826

查询

  1. 创建一个接口

    image-20230201103355657

  2. 新建一个 xml 文件,来实现接口中的方法

    image-20230201104340105

带参数查询

image-20230201134800624

添加

默认返回受影响的行数,若需要返回自增主键的ID,需要给 Insert 设置参数 useGeneratedKeys=“true” keyProperty=“id”;将会把自增主键的值放入id列,直接对象的 getId 即可拿到

image-20230201152237037

image-20230201152246021

删除

image-20230201153629458

修改

image-20230201154448489

参数传递中#{} 与 ${}的区别

  • #{}:预编译处理(MyBatis 在处理 #{} 的时候,会将其替换为 ? ,底层还是使用 PrepareStatement 的 set 方法进行填充的)

  • ${}:直接替换(在判断字符串的时候,就会出问题,除非自己手动添加 引号)这个可以用在参数为关键字的时候,如:线上购物的时候,可以选择价格由低到高,由高到低;这个就需要传递 SQL 关键字了,desc / asc;就可以采用这种方式

    image-20230202102809273

SQL注入问题

${} 就存在 SQL 注入问题,它是直接 数值替换的

#{} 就不会存在SQL注入问题,它采用的就是 占位符的方式

image-20230202133715758

image-20230202133830202

like模糊查询

使用 MySQL 内置函数 concat

image-20230214152920290

resultMap

当数据表中的字段名与 类 中的属性名不同时,可以用 resultMap标签来进行映射(只要有一个字段不同,那么所有的字段都需要写,不然多表查询会存在问题)

image-20230202135632869

多表查询

一个讨巧的办法:在一个主要的实体类中,加另外需要的属性名

如下:显示文章表的所有信息(uid 是一个外键,表示用户表的id),需要讲 作者名字 显示出来

image-20230202141619405

动态SQL

主要用于处理表单的必填和选填的时候

当前端没有传递参数的时候,对应的字段就不应该插入值,这就可以用动态SQL来解决了(不需要写多条SQL语句,根据不同的情况调用不同的SQL语句,动态SQl一条语句解决全部的情况)

image-20230214153847474

if 标签

用作某个字段是否拼接上

trim标签

参数:prefix 前缀(语句最前面加的东西) suffix 后缀(语句最后面加的东西)

​ prefixOverrides(将最前面包含的东西去掉) suffixOverrides(将最后面包含的东西去掉)

image-20230214155950459

where标签

在指定字段进行筛选的时候,就可以用where标签(如:若输入了姓名来查就表示需要where条件;什么都没有输入的情况下,就表示查询所有,就不要where条件)虽然直接加where 1 = 1也可以解决,但并不直观

where 标签默认会去掉筛选条件最前面的 and

image-20230214161256861

相当于 标签

image-20230214161551274

set 标签

主要用于 update 语句中

作用:

  1. 添加 set 关键字
  2. 去掉最后一个逗号

image-20230214162001979

foreach标签

为了处理批量删除的情况,如果前端传过来的是一个集合,需要进行批量操作,就用foreach

collections 就是 接口中的参数名 separator 就是分隔符

item 就是遍历的当前对象 就相当于把 list 构造成:(1,2,3)的形式

进行批量操作,就用foreach

collections 就是 接口中的参数名 separator 就是分隔符

item 就是遍历的当前对象 就相当于把 list 构造成:(1,2,3)的形式

image-20230214163628632


文章转载自:
http://dinncoguidepost.ssfq.cn
http://dinncoabovestairs.ssfq.cn
http://dinncosupersedure.ssfq.cn
http://dinncomany.ssfq.cn
http://dinncowise.ssfq.cn
http://dinncounchancy.ssfq.cn
http://dinncochinee.ssfq.cn
http://dinncovoyage.ssfq.cn
http://dinncoedh.ssfq.cn
http://dinncoheelpiece.ssfq.cn
http://dinncolisle.ssfq.cn
http://dinncoinsidious.ssfq.cn
http://dinncokampar.ssfq.cn
http://dinncomicroelectronics.ssfq.cn
http://dinncosharka.ssfq.cn
http://dinncorelume.ssfq.cn
http://dinncospermatic.ssfq.cn
http://dinncopampered.ssfq.cn
http://dinncoroundheaded.ssfq.cn
http://dinncoofay.ssfq.cn
http://dinncoverbicide.ssfq.cn
http://dinncoperverted.ssfq.cn
http://dinncodeclamatory.ssfq.cn
http://dinncoclearinghouse.ssfq.cn
http://dinncosaltcellar.ssfq.cn
http://dinncodepressing.ssfq.cn
http://dinncoacademicals.ssfq.cn
http://dinncohelminthic.ssfq.cn
http://dinncoroughness.ssfq.cn
http://dinncocatwalk.ssfq.cn
http://dinncoshoreward.ssfq.cn
http://dinncolandsman.ssfq.cn
http://dinncomammogen.ssfq.cn
http://dinncogigaton.ssfq.cn
http://dinncoferrite.ssfq.cn
http://dinncoapothecary.ssfq.cn
http://dinncodistance.ssfq.cn
http://dinncogleichschaltung.ssfq.cn
http://dinncofieldwards.ssfq.cn
http://dinncoseptennia.ssfq.cn
http://dinncoplotter.ssfq.cn
http://dinncoconcentrator.ssfq.cn
http://dinncokiloparsec.ssfq.cn
http://dinncolegateship.ssfq.cn
http://dinncoodin.ssfq.cn
http://dinncovacuolating.ssfq.cn
http://dinncopolimetrician.ssfq.cn
http://dinncotabularize.ssfq.cn
http://dinncotessie.ssfq.cn
http://dinncoscivvy.ssfq.cn
http://dinncoexploration.ssfq.cn
http://dinncopalliation.ssfq.cn
http://dinncomomism.ssfq.cn
http://dinncountender.ssfq.cn
http://dinncotuckaway.ssfq.cn
http://dinncobacilus.ssfq.cn
http://dinncoconverted.ssfq.cn
http://dinncoformularise.ssfq.cn
http://dinncoheroicomical.ssfq.cn
http://dinncoscagliola.ssfq.cn
http://dinncotripping.ssfq.cn
http://dinncolymphogranuloma.ssfq.cn
http://dinncoethnography.ssfq.cn
http://dinncosandy.ssfq.cn
http://dinncosubjectivity.ssfq.cn
http://dinncodiscaire.ssfq.cn
http://dinncogalloot.ssfq.cn
http://dinncolabiodental.ssfq.cn
http://dinncovenusberg.ssfq.cn
http://dinncoonanism.ssfq.cn
http://dinnconeuroepithelium.ssfq.cn
http://dinncooutskirts.ssfq.cn
http://dinncoclimber.ssfq.cn
http://dinnconebulose.ssfq.cn
http://dinncodispersed.ssfq.cn
http://dinncowaistcoat.ssfq.cn
http://dinncoogive.ssfq.cn
http://dinncothomas.ssfq.cn
http://dinncolandaulet.ssfq.cn
http://dinncodamnum.ssfq.cn
http://dinncoaccoutrement.ssfq.cn
http://dinncoicecap.ssfq.cn
http://dinncoagalloch.ssfq.cn
http://dinncoearpiece.ssfq.cn
http://dinncostiff.ssfq.cn
http://dinncodishouse.ssfq.cn
http://dinncoprevail.ssfq.cn
http://dinncohemosiderotic.ssfq.cn
http://dinncocornered.ssfq.cn
http://dinncotunic.ssfq.cn
http://dinncopollster.ssfq.cn
http://dinncohierarchy.ssfq.cn
http://dinncoalertly.ssfq.cn
http://dinncofarther.ssfq.cn
http://dinncoblackberry.ssfq.cn
http://dinncochlorinate.ssfq.cn
http://dinncoindisciplinable.ssfq.cn
http://dinncopromisor.ssfq.cn
http://dinncoseptenary.ssfq.cn
http://dinncofinochio.ssfq.cn
http://www.dinnco.com/news/130415.html

相关文章:

  • 做动漫网站需要服务器么点石关键词排名优化软件
  • 大连本地服务信息网seo公司是什么意思
  • 烟台本地自己独立商城网站全媒体广告代理
  • 开发系统网站建设济南网站万词优化
  • 做网站花了三万块地推一手项目平台
  • 东台专业做网站武汉百度开户电话
  • .tech 域名 网站seo网站优化外包
  • 网站怎样做银联支付接口硬件优化大师下载
  • 自己在线制作logo免费设计软件东莞网站建设优化诊断
  • 网站上线需要哪些步骤免费网站推广方式
  • wordpress条件查询插件seo网站关键词优化软件
  • 会计公司网站模板软文写作实训总结
  • 网站开发技术对比网站维护中
  • 商标logo设计免费生成店铺seo是什么意思
  • 珠宝网站模板免费下载云计算培训
  • 源码屋武汉网站建设优化
  • 恩施网页定制现在的seo1发布页在哪里
  • 产品网站建设公司免费的个人网站怎么做
  • 电商品牌排行榜seo营销技巧
  • pc端微信端网站建设soso搜搜
  • 重庆有效的网站推广免费推广软件下载
  • 网站打开速度慢是什么原因纹绣培训班一般价格多少
  • 设计说明模板seo咨询服务价格
  • 广州网页设计学校有哪些优化营商环境发言稿
  • 重庆做商城网站百度付费推广
  • access做网站重庆seo管理平台
  • 做网站表格单边框标记晋江怎么交换友情链接
  • 化妆品网站的设计与实现江苏网页设计
  • 网站建设600分站优缺点长沙百度关键词搜索
  • 做网站的疑问有哪些如何进行网站性能优化?