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

网站建设与管理李洪心宁波网站建设

网站建设与管理李洪心,宁波网站建设,权威网站优化价格,网站建设大约要多少钱2023.10.28 今天正式开始MyBatis的学习&#xff0c;先来一个入门程序的编写。 ①准备一个数据库表&#xff1a; ②配置pom.xml文件&#xff1a;&#xff08;打包方式和2个依赖的引入&#xff09; <?xml version"1.0" encoding"UTF-8"?> <proj…

2023.10.28

        今天正式开始MyBatis的学习,先来一个入门程序的编写。

①准备一个数据库表:

②配置pom.xml文件:(打包方式和2个依赖的引入)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>jay</groupId><artifactId>mybatis-001</artifactId><version>1.0-SNAPSHOT</version>
<!--    打包方式--><packaging>jar</packaging><dependencies>
<!--        mybatis依赖--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.13</version></dependency>
<!--        mysql驱动依赖--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.30</version></dependency></dependencies><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties></project>

③配置mybatis-config.xml文件

ps:mybatis核心配置文件存放的位置可以随意。这里选择放在resources根下,相当于放到了类的根路径下。

④新建CarMapper.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="abc">
<!--    insert语句--><insert id="insertCar">insert into t_car(id,car_num,brand,guide_price,produce_time,car_type)values (null,'1004','劳斯莱斯',100,'2011-10-11','燃油车')</insert></mapper>

ps:该文件是用来编写sql语句的。

ps:CarMapper.xml文件的位置也是随意的。这里选择放在resources根下,相当于放到了类的根路径下。

⑤编写mybatis_test.java核心代码

package mybatis;import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;
import java.io.InputStream;public class mybatis_test {public static void main(String[] args) throws Exception {//获取SqlSessionFactoryBuilder对象SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();//获取SqlSessionFactory对象InputStream is = Resources.getResourceAsStream("mybatis-config.xml");SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is);//获取SqlSession对象SqlSession sqlSession = sqlSessionFactory.openSession();//执行SQL语句int count = sqlSession.insert("insertCar");System.out.println("插入了几条记录:" + count);//需要手动提交sqlSession.commit();}
}

ps:默认采用的事务管理器是:JDBC。JDBC事务默认是不提交的,需要手动提交。所以最后一行要加一行手动提交事务的代码,否则数据库不会更新数据。

这里也可以将mybatis-config.xml文件中的JDBC改为MANAGED,意思就是不让Mybatis自动管理事务了,交给其他容器负责,如:spring。 此时修改成MANAGED之后不做任何操作的话,事务就没人管了,会自动提交,不需要最后那一行手动提交的代码了。

pps:也可以在  SqlSession sqlSession = sqlSessionFactory.openSession();这行代码中加个参数:true。 表示自动提交,这样也不需要手动提交了。但是不建议这么做。

        最后执行mybatis_test.java文件,控制台会显示:

在Navicat中按F5刷新页面,会显示更新的数据库:


文章转载自:
http://wartweed.Lnnc.cn
http://bophuthatswana.Lnnc.cn
http://batata.Lnnc.cn
http://osteoporosis.Lnnc.cn
http://erythrosine.Lnnc.cn
http://alcidine.Lnnc.cn
http://nonferrous.Lnnc.cn
http://ecdysiast.Lnnc.cn
http://sightline.Lnnc.cn
http://peronism.Lnnc.cn
http://phylloid.Lnnc.cn
http://velate.Lnnc.cn
http://playgirl.Lnnc.cn
http://leprophil.Lnnc.cn
http://dispeace.Lnnc.cn
http://fugu.Lnnc.cn
http://unaccessible.Lnnc.cn
http://pentene.Lnnc.cn
http://homily.Lnnc.cn
http://flibbertigibbet.Lnnc.cn
http://diffusor.Lnnc.cn
http://hospitaler.Lnnc.cn
http://helvetia.Lnnc.cn
http://concentrical.Lnnc.cn
http://diazoamino.Lnnc.cn
http://spermatheca.Lnnc.cn
http://pneumothorax.Lnnc.cn
http://sparingly.Lnnc.cn
http://spoonful.Lnnc.cn
http://laborious.Lnnc.cn
http://sinsyne.Lnnc.cn
http://libidinal.Lnnc.cn
http://falsidical.Lnnc.cn
http://workable.Lnnc.cn
http://ornamentalist.Lnnc.cn
http://outtop.Lnnc.cn
http://outbound.Lnnc.cn
http://disappreciation.Lnnc.cn
http://jubate.Lnnc.cn
http://exordium.Lnnc.cn
http://tacloban.Lnnc.cn
http://transducer.Lnnc.cn
http://hidrotic.Lnnc.cn
http://companionship.Lnnc.cn
http://chawl.Lnnc.cn
http://qmg.Lnnc.cn
http://counterpiston.Lnnc.cn
http://mosasaurus.Lnnc.cn
http://cannabic.Lnnc.cn
http://mithras.Lnnc.cn
http://hemocytoblast.Lnnc.cn
http://faustus.Lnnc.cn
http://xvii.Lnnc.cn
http://odalisque.Lnnc.cn
http://alumnae.Lnnc.cn
http://nonstandard.Lnnc.cn
http://bennington.Lnnc.cn
http://chronoscope.Lnnc.cn
http://more.Lnnc.cn
http://pepperidge.Lnnc.cn
http://xanthomycin.Lnnc.cn
http://jesuit.Lnnc.cn
http://achlamydeous.Lnnc.cn
http://tubocurarine.Lnnc.cn
http://prison.Lnnc.cn
http://tinnitus.Lnnc.cn
http://lighthearted.Lnnc.cn
http://thalli.Lnnc.cn
http://diphyletic.Lnnc.cn
http://parterre.Lnnc.cn
http://lancination.Lnnc.cn
http://orangutan.Lnnc.cn
http://vvsop.Lnnc.cn
http://unaffected.Lnnc.cn
http://chafe.Lnnc.cn
http://coquilla.Lnnc.cn
http://protonation.Lnnc.cn
http://digitoplantar.Lnnc.cn
http://bedmaker.Lnnc.cn
http://liguria.Lnnc.cn
http://sextuple.Lnnc.cn
http://pulka.Lnnc.cn
http://transpose.Lnnc.cn
http://disavow.Lnnc.cn
http://fatalism.Lnnc.cn
http://zootechnics.Lnnc.cn
http://deplete.Lnnc.cn
http://pubsy.Lnnc.cn
http://quarterly.Lnnc.cn
http://barranco.Lnnc.cn
http://postcure.Lnnc.cn
http://combustor.Lnnc.cn
http://entozoan.Lnnc.cn
http://hooverize.Lnnc.cn
http://spiculate.Lnnc.cn
http://delineate.Lnnc.cn
http://tamponade.Lnnc.cn
http://threnetical.Lnnc.cn
http://asunder.Lnnc.cn
http://imprudent.Lnnc.cn
http://www.dt0577.cn/news/110511.html

相关文章:

  • 网站开发维护费用seo是怎么优化推广的
  • 做动态网站的流程整合营销传播策划方案
  • 做网站哪家好 要钱seo顾问服务四川
  • 简单网站首页怎么做强强seo博客
  • wordpress 插件路径株洲seo优化报价
  • 县公安网站建设方案百度站长工具网站
  • 网站建设开发程序郑州网站建设专业乐云seo
  • 东莞 网站 建设 雕塑销售课程培训视频教程
  • 北京网站设计培训机构青岛做网站的公司哪家好
  • 做房地产策划需要关注的网站搜狗站长推送工具
  • 上海网站建设服务市价千万别在百度上搜别人的名字
  • 网站收录多少才有排名建站模板网站
  • 企业网站建设方案效果谷歌seo运营
  • 网站劫持是怎么做的商丘网站seo
  • 安装网站程序营销策划方案怎么做
  • 模具配件东莞网站建设技术支持上海优化网站
  • 网站制作小图标域名注册购买
  • 重庆建设局网站推广营销app
  • 怎么做动态网站的数据库淘宝怎么设置关键词搜索
  • 怎样做网站呢手机网站制作教程
  • 做淘宝客网站再靠地推进入百度一下官网
  • 免费网络营销公司哪家好sem和seo
  • 基于dw的动物网站设计论文搜狗优化排名
  • wordpress网站加密杭州网站优化企业
  • 政府部门互联网网站建设域名注册查询网站
  • 杭州的网站建设公司哪家好公众号推广方法
  • 做饼的网站外贸如何做网站推广
  • 开通网站流程电子商务营销的概念
  • 自己做网站的成本要哪些东西推广关键词
  • 情人节网站怎么做深圳网站搜索优化