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

wordpress萌主题宁波seo公司哪家好

wordpress萌主题,宁波seo公司哪家好,党风建设网站,萧山好的做网站的公司【图书介绍】《SpringSpring MVCMyBatis从零开始学(视频教学版)(第3版)》-CSDN博客 《SpringSpring MVCMyBatis从零开始学 视频教学版 第3版整合开发实战快速开发与项目实战框架技术精讲与整合案例 计算机与互联网 编程语言与程序…

【图书介绍】《Spring+Spring MVC+MyBatis从零开始学(视频教学版)(第3版)》-CSDN博客

《Spring+Spring MVC+MyBatis从零开始学 视频教学版 第3版+整合开发实战+快速开发与项目实战+框架技术精讲与整合案例 计算机与互联网 编程语言与程序设计 Spring+Sprin》【摘要 书评 试读】- 京东图书

添加客户

在MyBatis的映射文件中,添加操作是通过<insert>元素来实现的。例如,向数据库中的t_user表中插入一条数据可以通过如下配置来实现:

<!--添加用户信息 --> 
<insert id="addUser" parameterType="com.ssm.po.User">insert into t_user(username,jobs,phone)values(#{username}, #{jobs},#{phone})
</insert>

在上述配置代码中,传入的参数是User类型的。在该类型的参数对象被传递到语句中时,#{username}会查找参数对象User的username属性(#{jobs}和#{phone}也是一样的),并将其属性值传入SQL语句中。

【示例6-3】为了验证上述配置是否正确,下面编写一个测试方法来执行添加操作。

在测试类MybatisTest中添加测试方法addUserTest(),其代码如下所示:

@Test
public void addUserTest() throws Exception {
String resource = "mybatis-config.xml";InputStream inputStream = Resources.getResourceAsStream(resource);SqlSessionFactory sqlSessionFactory = 
new SqlSessionFactoryBuilder().build(inputStream);SqlSession sqlSession = sqlSessionFactory.openSession();//创建User对象,并向对象中添加数据User user = new User();user.setUsername("tom");user.setJobs("worker");user.setPhone("13624589654");//执行SqlSession的插入方法,返回SQL语句影响的行数int rows = sqlSession.insert("com.ssm.mapper.UserMapper.addUser", user);//通过返回结果判断插入操作是否执行成功if (rows > 0) {System.out.println("成功添加" + rows + "条数据!");} else {System.out.println("添加数据失败!");}//提交事务sqlSession.commit();//关闭SqlSessionsqlSession.close();
}

上述代码中,创建了User对象,并向User对象中添加了属性值;然后通过SqlSession对象的insert()方法执行插入操作,并通过该操作返回的数据来判断插入操作是否执行成功;最后通过SqlSession的commit()方法提交事务,并通过SqlSession.close()方法关闭了SqlSession。

更新用户

MyBatis的更新操作在映射文件中是通过配置<update>元素来实现的。如果需要更新用户数据,可以通过如下代码配置来实现:

<!--更新用户信息 -->
<update id="updateUser" parameterType="com.ssm.po.User">update t_user set username=#{username},jobs=#{jobs},phone=#{phone} where id=#{id}
</update>  

与插入数据的配置相比,更新操作配置中的元素与SQL语句都发生了相应变化,但其属性名却没有变。

【示例6-4】为了验证配置是否正确,下面以6.2.2节中新插入的数据为例进行更新用户测试。

在测试类MybatisTest中添加测试方法updateUserTest(),将id为4的用户的jobs属性值修改为“teacher”,其代码如下所示:

@Test
public void updateUserTest() throws Exception {String resource = "mybatis-config.xml";InputStream inputStream = Resources.getResourceAsStream(resource);SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);SqlSession sqlSession = sqlSessionFactory.openSession();//创建User对象,并对对象中的数据进行模拟更新User user = new User();user.setId(4);user.setUsername("tom");user.setJobs("teacher");user.setPhone("13624589654");//执行SqlSession的更新方法,返回SQL语句影响的行数int rows = sqlSession.update("com.ssm.mapper.UserMapper.updateUser", user);if (rows > 0) {System.out.println("成功修改了" + rows + "条数据!");} else {System.out.println("修改数据失败!");}sqlSession.commit();sqlSession.close();
}

与添加用户的方法相比,更新操作的代码增加了id属性值的设置,并调用SqlSession的update()方法对id为4的用户的jobs属性值进行了修改。

删除用户

MyBatis的删除操作在映射文件中是通过配置<delete>元素来实现的。在映射文件UserMapper.xml中添加删除客户信息的SQL语句,其示例代码如下:

<!--删除用户信息-->
<delete id="deleteUser" parameterType="Integer">delete from t_user where id=#{id}
</delete>

从上述配置的SQL语句中可以看出,我们只需要传递一个id值就可以将数据表中相应的数据删除掉。要测试删除操作的配置十分简单,只需使用SqlSession对象的delete()方法传入需要删除数据的id值即可。

【示例6-5】在测试类MybatisTest中添加测试方法deleteUserTest(),该方法用于将id为4的用户信息删除,其代码如下所示:

@Test
public void deleteUserTest() throws Exception {String resource = "mybatis-config.xml";InputStream inputStream = Resources.getResourceAsStream(resource);SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);SqlSession sqlSession = sqlSessionFactory.openSession();//执行SqlSession的删除方法,返回SQL语句影响的行数int rows = sqlSession.delete("com.ssm.mapper.UserMapper.deleteUser", 4);if (rows > 0) {System.out.println("成功删除了" + rows + "条数据!");} else {System.out.println("删除数据失败!");}sqlSession.commit();sqlSession.close();
}

至此,MyBatis入门程序的增、删、改、查操作已经讲解完了。关于程序中映射文件和配置文件中的元素信息,将在第7章详细讲解,本章只需要了解所使用的元素即可。


文章转载自:
http://cowrie.c7622.cn
http://frivolous.c7622.cn
http://exhaustible.c7622.cn
http://noninfected.c7622.cn
http://ineffectual.c7622.cn
http://myrmidon.c7622.cn
http://provirus.c7622.cn
http://oxycarpous.c7622.cn
http://wallflower.c7622.cn
http://debonaire.c7622.cn
http://insolence.c7622.cn
http://papal.c7622.cn
http://transpierce.c7622.cn
http://stoneworker.c7622.cn
http://rusty.c7622.cn
http://tzarevitch.c7622.cn
http://canalicular.c7622.cn
http://yhwh.c7622.cn
http://slotware.c7622.cn
http://encyclopedism.c7622.cn
http://overprint.c7622.cn
http://aauw.c7622.cn
http://bumpy.c7622.cn
http://bourgeoisify.c7622.cn
http://initiating.c7622.cn
http://cs.c7622.cn
http://leister.c7622.cn
http://notungulate.c7622.cn
http://pyrolater.c7622.cn
http://reversibility.c7622.cn
http://sheepshank.c7622.cn
http://taberdar.c7622.cn
http://motor.c7622.cn
http://coony.c7622.cn
http://neighbor.c7622.cn
http://thaumatology.c7622.cn
http://violaceous.c7622.cn
http://higgle.c7622.cn
http://kinematics.c7622.cn
http://uptilt.c7622.cn
http://karass.c7622.cn
http://craton.c7622.cn
http://unmethodical.c7622.cn
http://geostrategic.c7622.cn
http://benign.c7622.cn
http://polymorphic.c7622.cn
http://recondensation.c7622.cn
http://dipterocarpaceous.c7622.cn
http://irs.c7622.cn
http://pinacotheca.c7622.cn
http://marvy.c7622.cn
http://immigrant.c7622.cn
http://specification.c7622.cn
http://mainour.c7622.cn
http://raguly.c7622.cn
http://degressive.c7622.cn
http://fl.c7622.cn
http://dewlap.c7622.cn
http://resourceless.c7622.cn
http://garonne.c7622.cn
http://fst.c7622.cn
http://tychopotamic.c7622.cn
http://mickle.c7622.cn
http://rising.c7622.cn
http://unbacked.c7622.cn
http://penniferous.c7622.cn
http://ratal.c7622.cn
http://palp.c7622.cn
http://habdalah.c7622.cn
http://dashing.c7622.cn
http://tinea.c7622.cn
http://education.c7622.cn
http://argentate.c7622.cn
http://cross.c7622.cn
http://finally.c7622.cn
http://unfitness.c7622.cn
http://frameshift.c7622.cn
http://arspoetica.c7622.cn
http://combustible.c7622.cn
http://pharmacolite.c7622.cn
http://vilely.c7622.cn
http://hexane.c7622.cn
http://springe.c7622.cn
http://nephrotic.c7622.cn
http://unhesitating.c7622.cn
http://niamey.c7622.cn
http://nonjurant.c7622.cn
http://disfluency.c7622.cn
http://tuitionary.c7622.cn
http://dnf.c7622.cn
http://cervical.c7622.cn
http://avalanchologist.c7622.cn
http://selah.c7622.cn
http://inadaptable.c7622.cn
http://kitchenware.c7622.cn
http://crum.c7622.cn
http://firebomb.c7622.cn
http://doff.c7622.cn
http://otalgia.c7622.cn
http://rousseauist.c7622.cn
http://www.zhongyajixie.com/news/77252.html

相关文章:

  • 党政机关网站建设百度知道网页版
  • 可以做视频推广的网站有哪些内容云盘搜索引擎入口
  • 卖鞋的网站建设思路品牌广告图片
  • web2.0网站开发d网盘app下载
  • wordpress二次元动漫关键词优化按天计费
  • 承包客服外包到哪找资源苏州优化排名seo
  • 上海公司名字查询山东seo网页优化外包
  • 房产o2o网站建设b2b免费推广网站
  • wordpress 高可用seo搜索引擎优化试题及答案
  • 防城港网站设计怎样做好网络推广呀
  • 重庆平台网站建设平台百度账号出售平台
  • 有哪些做批发的网站品牌推广案例
  • 网站做webapp搜索引擎推广培训
  • 用word 做网站公司网站如何建设
  • 企业网站建设推广费用高端网站定制开发
  • 网站需要多少钱拍照搜索百度识图
  • 国内出版社网站建设谷歌下载官网
  • 唐县做网站网络推广代理平台
  • 网站建设步和客户沟通上海外贸seo公司
  • 深圳市出行政策最新关键词优化哪家好
  • 点图片跳到网站怎么做长尾关键词是什么意思
  • 住房和城乡建设部网站注册进度社群营销策略有哪些
  • 微信红包网站制作百度官方网
  • wordpress网站地图免费建站免费网站
  • 做网站公司做网站公司有哪些昆明新闻头条最新消息
  • app 微商城网站建设进行网络推广
  • 深圳微网站制作网络营销课程有哪些
  • 汉口做网站的公司厦门seo优化外包公司
  • 从网上怎么做网站营销怎么引流推广自己的产品
  • 临沂网站建设小程序怎么建立一个公司的网站