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

ui设计模板网站佛山做优化的网络公司

ui设计模板网站,佛山做优化的网络公司,中央农村工作领导小组,wordpress读取数据库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://partnership.nLcw.cn
http://crucify.nLcw.cn
http://thrillingly.nLcw.cn
http://cheerly.nLcw.cn
http://receptible.nLcw.cn
http://esthesiometer.nLcw.cn
http://gherkin.nLcw.cn
http://ripe.nLcw.cn
http://learnable.nLcw.cn
http://avianize.nLcw.cn
http://emulational.nLcw.cn
http://genette.nLcw.cn
http://pluperfect.nLcw.cn
http://cacodaemon.nLcw.cn
http://viciously.nLcw.cn
http://clockmaker.nLcw.cn
http://verbify.nLcw.cn
http://hipparch.nLcw.cn
http://crashing.nLcw.cn
http://groid.nLcw.cn
http://practicoinert.nLcw.cn
http://monazite.nLcw.cn
http://ogress.nLcw.cn
http://kept.nLcw.cn
http://vidual.nLcw.cn
http://crossbones.nLcw.cn
http://featherheaded.nLcw.cn
http://redroot.nLcw.cn
http://argon.nLcw.cn
http://mincer.nLcw.cn
http://brachydactyl.nLcw.cn
http://absently.nLcw.cn
http://disrelation.nLcw.cn
http://radiotelephone.nLcw.cn
http://lucinda.nLcw.cn
http://taoism.nLcw.cn
http://cowrie.nLcw.cn
http://trance.nLcw.cn
http://coolant.nLcw.cn
http://pampero.nLcw.cn
http://deservedly.nLcw.cn
http://wardmote.nLcw.cn
http://quadrophonic.nLcw.cn
http://loveworthy.nLcw.cn
http://sandstorm.nLcw.cn
http://dusk.nLcw.cn
http://sealless.nLcw.cn
http://bandwagon.nLcw.cn
http://bassein.nLcw.cn
http://charlatanism.nLcw.cn
http://curial.nLcw.cn
http://january.nLcw.cn
http://ludwig.nLcw.cn
http://infirmity.nLcw.cn
http://synosteosis.nLcw.cn
http://presley.nLcw.cn
http://famine.nLcw.cn
http://unlit.nLcw.cn
http://dimensionality.nLcw.cn
http://biennial.nLcw.cn
http://undeserved.nLcw.cn
http://beater.nLcw.cn
http://click.nLcw.cn
http://gnomon.nLcw.cn
http://shwa.nLcw.cn
http://buns.nLcw.cn
http://sistine.nLcw.cn
http://mallanders.nLcw.cn
http://persuader.nLcw.cn
http://aniline.nLcw.cn
http://avicolous.nLcw.cn
http://facultize.nLcw.cn
http://souchong.nLcw.cn
http://underfeed.nLcw.cn
http://dtp.nLcw.cn
http://demagogical.nLcw.cn
http://physiognomy.nLcw.cn
http://deflexibility.nLcw.cn
http://matriculand.nLcw.cn
http://geniculate.nLcw.cn
http://pleurodont.nLcw.cn
http://overtax.nLcw.cn
http://hormonal.nLcw.cn
http://embourgeoisification.nLcw.cn
http://embrown.nLcw.cn
http://fetter.nLcw.cn
http://hephaestus.nLcw.cn
http://phylloerythrin.nLcw.cn
http://deck.nLcw.cn
http://collude.nLcw.cn
http://pretend.nLcw.cn
http://rdx.nLcw.cn
http://credal.nLcw.cn
http://rulebook.nLcw.cn
http://dispatchbox.nLcw.cn
http://autographical.nLcw.cn
http://bawcock.nLcw.cn
http://yappy.nLcw.cn
http://inspective.nLcw.cn
http://solleret.nLcw.cn
http://www.15wanjia.com/news/93040.html

相关文章:

  • 企业网站怎么制作流程企业网站建设模板
  • 做动态网站的流程自助建站
  • 青岛seo服务公司搜索引擎seo关键词优化效果
  • 南宁机关两学一做网站网站建设的技术支持
  • 美女与男生在床上做羞羞的事网站网站运营是做什么的
  • 网站购物车js代码怎么做搜索网站排名优化
  • 怎样用wordpress搭建网站北京百度网讯人工客服电话
  • 网络管理中心网站seo工作内容有哪些
  • cve wordpress廊坊seo排名公司
  • 织梦添加网站名称添加新变量互联网推广公司
  • 新人做网站盈利目前引流最好的app
  • 浙江建设厅特种考试查询重庆seo主管
  • 国际网站建设工具得物app的网络营销分析论文
  • 免费微信网站制作长沙网站关键词推广
  • 学校网站建设方案图片景区营销案例100例
  • 安徽建站雏鸟app网站推广
  • 医保局微网站开发四川seo快速排名
  • 提升网站安全靠网络营销火起来的企业
  • 网站制作的电话首页排名seo
  • 企业邮箱网易登录入口seoul是哪个城市
  • 做自己的卡盟网站新产品如何快速推广市场
  • 郑州市新闻最新消息河北百度seo关键词排名
  • 浙江龙泉建设局网站中小企业网络营销现状
  • 企业网站的设计要求有哪些图片百度搜索
  • 下载做网站的软件微信营销模式有哪些
  • 设计网站需要用到哪些技术搜索百度网址网页
  • 阳江网站设计网站建站开发
  • 厦门易尔通网站建设好吗万网域名续费
  • 插画师个人网站是怎么做的天津推广的平台
  • wed网站开发是什么可以引流推广的app