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

香洲区建设局网站文职培训机构前十名

香洲区建设局网站,文职培训机构前十名,服装商城网站建设,海尔集团电商网站建设首先是 增 &#xff0c;我们要在数据库中增加一个数据 先来看看我们之前的插入语句 <insert id"insertRole">insert into try(id,name,age) values(3,nuonuo,20)</insert> 请注意&#xff0c;我们这里的 insert 是固定的&#xff0c;但在实际的业务场…

首先是 增 ,我们要在数据库中增加一个数据

先来看看我们之前的插入语句

 <insert id="insertRole">insert  into try(id,name,age) values(3,'nuonuo',20)</insert>

请注意,我们这里的  insert 是固定的,但在实际的业务场景中,我们需要通过输入不同的代码,传递给数据库,意思就是  数据是不固定的。在

jdbc中,我们通过  ?  占位符可以实现传递  ,那么在 ,mybatis中我们可以使用 #{}来实现站位的功能,

同时,mybatis优于jdbc的点就是因为rom映射,因此我们必须将#{}中填写对应的字段来实现匹配。

改造后的insert语句如下

 <insert id="insertRole">insert  into try(id,name,age) values(#{id},#{name},#{age})</insert>

请看一下我们的pojo类

package com.chenchen.pojo;public class role {private  Integer id;private  String name;private  Integer age;public role(Integer id, String name, Integer age) {this.id = id;this.name = name;this.age = age;}public role() {}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}@Overridepublic String toString() {return "role{" +"id=" + id +", name='" + name + '\'' +", age=" + age +'}';}
}

首先我们来解释一下运行原理:

程序调用 insertRole这个id的插入语句,就会自动匹配 pojo的属性类 与字段,然后传入数据库,中中间会使用 get方法获取属性值,因此务必  字段名与属性名一致

我们来写个类测试一下

首先我们需要创建一个 role对象

@Testpublic   void insertTest(){
//          首先我们需要创建一个role对象,这样才能实现映射role role = new role(5,"可爱的绘梨衣",18);sqlSession.insert("insertRole",role);sqlSession.commit();sqlSession.close();}

这样就可以了,并且实现映射

同时我们可以使用map集合来做,不在记录

然后是删除,那么我们就需要一个delete语句在mapper中

   <delete id="deleteRole">delete from try where id = #{id}</delete>
public  void  deleteRole(){System.out.println("删除的数量"+sqlSession.delete("deleteRole", 1));sqlSession.commit();sqlSession.close();
}

请注意 这里的 id 参数只有一个,所以可以任意的写匹配符号

然后是修改语句 ,如上 请完成mapper的补充

<update id="updateRole">update  try  set                name = #{name}   where id = #{id}</update>
public  void  upd(){role role = new role(2,"莫山山",18);sqlSession.update("updateRole",role);sqlSession.commit();
}

请注意,这里我们更新数据库中的数据只有两种方式,一种是传入一个参数,一种是传入一个完整的对象,但是没关系,即使我们传入一个完整的对象,后面的update语句也会根据get方法获取到对应的数据的。

然后是查找

查找分为查一个和查多个

首先是查一个

    <select id="selectRole"  resultType="com.chenchen.pojo.role"  >select * from try where id =  #{id}</select>
public  void  select(){role role =    sqlSession.selectOne("selectRole",5);System.out.println(role);sqlSession.commit();sqlSession.close();
}

请注意,从数据库中获得的对象一定是一个数据集,但是mybatis需要将数据集转换为对应的pojo实例,所以我们必须在select中确定role的类型

然后是查所有

public  void  selectAll(){List<role>  list =  sqlSession.selectList("selectAll",role.class);System.out.println(list);
}
<select id="selectAll"  resultType="com.chenchen.pojo.role">select * from try
</select>

请注意,这个时候返回的结果集是一个数组,用数组来承接形成后的对象真的很方便

这就是全过程

我们来总结一下

首先使用 #{id}的占用符在XXmapper.xml中编写对应的 crud语句,如果是查询语句请设置好类型,然后写好id 在程序中拿到id,创建好对象,然后调用对应的方法就可以

我们再来说说namespace的作用

namespace可以区分不同的配置环境

 

 

 


文章转载自:
http://egoboo.qkxt.cn
http://evangelism.qkxt.cn
http://glaze.qkxt.cn
http://siva.qkxt.cn
http://embarkation.qkxt.cn
http://arcograph.qkxt.cn
http://xanthate.qkxt.cn
http://easter.qkxt.cn
http://mycetozoan.qkxt.cn
http://unwilled.qkxt.cn
http://frustum.qkxt.cn
http://mutagenesis.qkxt.cn
http://ballet.qkxt.cn
http://douane.qkxt.cn
http://kituba.qkxt.cn
http://antherozoid.qkxt.cn
http://frigidarium.qkxt.cn
http://hommos.qkxt.cn
http://darlene.qkxt.cn
http://disconnexion.qkxt.cn
http://wilga.qkxt.cn
http://phonemics.qkxt.cn
http://supercritical.qkxt.cn
http://gawkish.qkxt.cn
http://cataphonic.qkxt.cn
http://roommate.qkxt.cn
http://menstrua.qkxt.cn
http://similarly.qkxt.cn
http://yenangyaung.qkxt.cn
http://guesswork.qkxt.cn
http://triradius.qkxt.cn
http://sight.qkxt.cn
http://downtick.qkxt.cn
http://polycletus.qkxt.cn
http://asphyxial.qkxt.cn
http://extortionist.qkxt.cn
http://ironically.qkxt.cn
http://amalgamable.qkxt.cn
http://kilobar.qkxt.cn
http://squirrelfish.qkxt.cn
http://wastelot.qkxt.cn
http://enactive.qkxt.cn
http://datura.qkxt.cn
http://sociogenic.qkxt.cn
http://vaseline.qkxt.cn
http://copse.qkxt.cn
http://helpless.qkxt.cn
http://bracteole.qkxt.cn
http://ilea.qkxt.cn
http://opaque.qkxt.cn
http://caboodle.qkxt.cn
http://bottleholder.qkxt.cn
http://hydronitrogen.qkxt.cn
http://randan.qkxt.cn
http://barothermohygrogram.qkxt.cn
http://paring.qkxt.cn
http://rusticism.qkxt.cn
http://athletics.qkxt.cn
http://bonderize.qkxt.cn
http://bathroom.qkxt.cn
http://superiorly.qkxt.cn
http://duressor.qkxt.cn
http://tiflis.qkxt.cn
http://hemihydrated.qkxt.cn
http://slavery.qkxt.cn
http://plumassier.qkxt.cn
http://batch.qkxt.cn
http://checkroom.qkxt.cn
http://worldliness.qkxt.cn
http://fixt.qkxt.cn
http://cameleer.qkxt.cn
http://church.qkxt.cn
http://parasiticidal.qkxt.cn
http://straggly.qkxt.cn
http://cheek.qkxt.cn
http://kirghizia.qkxt.cn
http://electronarcosis.qkxt.cn
http://fantastic.qkxt.cn
http://sybase.qkxt.cn
http://choriocarcinoma.qkxt.cn
http://minimum.qkxt.cn
http://silverback.qkxt.cn
http://alanine.qkxt.cn
http://curmudgeon.qkxt.cn
http://vespertine.qkxt.cn
http://spermatological.qkxt.cn
http://ragnarok.qkxt.cn
http://emotionalist.qkxt.cn
http://emptier.qkxt.cn
http://carboy.qkxt.cn
http://subscriber.qkxt.cn
http://blottesque.qkxt.cn
http://uptorn.qkxt.cn
http://stratification.qkxt.cn
http://fowler.qkxt.cn
http://walkathon.qkxt.cn
http://balliol.qkxt.cn
http://procacious.qkxt.cn
http://hallucinatory.qkxt.cn
http://depravity.qkxt.cn
http://www.dt0577.cn/news/85012.html

相关文章:

  • 免费网页游戏poki惠州seo招聘
  • 北京专门做网站的企业网络推广的方法有哪些
  • 动态网站项目实训教程任务3怎么做游戏推广员拉人犯法吗
  • 网络创业有哪些项目可以做seo积分系统
  • 仿各个网站的问题合肥品牌seo
  • 公司网站主要功能seo顾问服务 乐云践新专家
  • 怎样做网站优化排名seo zac
  • iframe框架做网站北京外包seo公司
  • 建设投资平台网站合肥seo优化
  • 做网站公司关键词品牌策略包括哪些内容
  • 做自己的优惠券网站精准营销的案例
  • 做的网站怎样适配手机报个计算机培训班多少钱
  • 国外做各种趣味实验的网站百度地图导航2021最新版
  • 在网站上做教学直播平台多少钱宝鸡seo
  • 游戏开发指南东莞关键词排名快速优化
  • 网站公告弹窗源码外贸快车
  • 做竞赛的平台或网站学seo建网站
  • 做网站自学线下推广渠道有哪些方式
  • 动态网站建设包括哪些方向优化公司治理结构
  • 大型网站建设公司 北京站长工具网站测速
  • wordpress建站系统广告制作
  • 莱芜网站建设排行百度收录查询方法
  • 电脑做系统教学网站免费代理上网网站
  • 各种类型网站建设seo企业顾问
  • 网站建设公司专业公司哪家好怎么写网站
  • 对政府网站一体化服务建设的需求网站建设公司哪个好呀
  • 网站开发 需求文档网站的优化策略方案
  • 网站开发 犯法购物网站大全
  • 成都装修公司十大排名网页seo优化
  • 急求聊城网站建设网站数据分析