From 774fd65a7a67721b3667268d58aa6d8e9f2383bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E7=BF=94?= <2045602860@qq.com> Date: Tue, 19 Dec 2023 16:09:42 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=BB=BA=2034=20=E5=88=98?= =?UTF-8?q?=E6=99=BA=E7=BF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "34 \345\210\230\346\231\272\347\277\224/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "34 \345\210\230\346\231\272\347\277\224/.keep" diff --git "a/34 \345\210\230\346\231\272\347\277\224/.keep" "b/34 \345\210\230\346\231\272\347\277\224/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From bc81da58cdea54f37bbe8871f33a7795514650cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E7=BF=94?= <2045602860@qq.com> Date: Tue, 19 Dec 2023 16:10:01 +0000 Subject: [PATCH 2/4] =?UTF-8?q?34=20=E5=88=98=E6=99=BA=E7=BF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘智翔 <2045602860@qq.com> --- ...64\345\220\210\347\254\224\350\256\260.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "34 \345\210\230\346\231\272\347\277\224/SSM\346\241\206\346\236\266\346\225\264\345\220\210\347\254\224\350\256\260.md" diff --git "a/34 \345\210\230\346\231\272\347\277\224/SSM\346\241\206\346\236\266\346\225\264\345\220\210\347\254\224\350\256\260.md" "b/34 \345\210\230\346\231\272\347\277\224/SSM\346\241\206\346\236\266\346\225\264\345\220\210\347\254\224\350\256\260.md" new file mode 100644 index 0000000..f15f98e --- /dev/null +++ "b/34 \345\210\230\346\231\272\347\277\224/SSM\346\241\206\346\236\266\346\225\264\345\220\210\347\254\224\350\256\260.md" @@ -0,0 +1,53 @@ +# SSM框架整合课堂笔记 + +Maven:专门用于管理和构建Java项目的工具 + +1.提供了一套标准化的项目结构 + +2.提供了一套标准化的构建流程(编译、测试、打包、发布...) + +3.提供了一套依赖管理机制 + + + +ApacheMaven是一个项目管理和构建工具,它基于项目对象 + + + +Maven模型: + +项目对象模型 + +依赖管理模型 + +插件 + + + +仓库: + +1.本地仓库:自己计算机上的一个目录 + +2.由Maven团队维护的全球唯一的仓库 + +3.远程仓库(私服):一般由公司团队搭建的私有仓库 + + + +坐标分的组成三部分: + +groupld:哪个组织开发的,组织名称 + +artifactID 工作ID:开发的什么项目,项目名称 + +version:哪个版本,版本号 + + + +专门用来查询maven坐标的网址: + +https://mvnrepository.com/ + + + +快捷引入坐标的方式:在pom.xml中按alt+insert,选择Dependency \ No newline at end of file -- Gitee From f750b650798a7cd7854c0ae38594c037982b7086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E7=BF=94?= <2045602860@qq.com> Date: Thu, 21 Dec 2023 14:57:06 +0000 Subject: [PATCH 3/4] =?UTF-8?q?34=20=E5=88=98=E6=99=BA=E7=BF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘智翔 <2045602860@qq.com> --- .../mybatis.MD" | 304 ++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 "34 \345\210\230\346\231\272\347\277\224/mybatis.MD" diff --git "a/34 \345\210\230\346\231\272\347\277\224/mybatis.MD" "b/34 \345\210\230\346\231\272\347\277\224/mybatis.MD" new file mode 100644 index 0000000..d6cdf5e --- /dev/null +++ "b/34 \345\210\230\346\231\272\347\277\224/mybatis.MD" @@ -0,0 +1,304 @@ +~~~java + mybatis的配置文件的MySQL密码要改 + +App.java测试类 + +```java + + +import com.mdd.pojo.User; +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 org.junit.Test; + +import java.beans.Transient; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +public class App { + @Test +public void selectAll() throws IOException { + //1. 加载mybatis的核心配置文件,获取 SqlSessionFactory + String resource = "mybatis-config.xml"; + + InputStream inputStream = Resources.getResourceAsStream(resource); + SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream); + SqlSession sqlSession = build.openSession(); + + + boolean flag=true; + try { + List userAll = sqlSession.selectList("test.selectAll"); + System.out.println(userAll); + + // 可能抛出异常的代码 + } catch (Exception e1) { + flag=false; + } finally { + sqlSession.close(); + if (flag){ + System.out.println("查询成功"); + } + } + + } + @Test + public void selectId() throws IOException { + //1. 加载mybatis的核心配置文件,获取 SqlSessionFactory + String resource = "mybatis-config.xml"; + + InputStream inputStream = Resources.getResourceAsStream(resource); + SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream); + SqlSession sqlSession = build.openSession(); + + + + + boolean flag=true; + try { + + User one = sqlSession.selectOne("test.selectId",1); + System.out.println(one); + + // 可能抛出异常的代码 + } catch (Exception e1) { + flag=false; + } finally { + sqlSession.close(); + if (flag){ + System.out.println("查询成功"); + } + } + } + + + @Test + public void deleteId() throws IOException { + //1. 加载mybatis的核心配置文件,获取 SqlSessionFactory + String resource = "mybatis-config.xml"; + + InputStream inputStream = Resources.getResourceAsStream(resource); + SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream); + SqlSession sqlSession = build.openSession(true); + + + + + + boolean flag=true; + try { + + sqlSession.delete("test.deleteId", 1); + + // 可能抛出异常的代码 + } catch (Exception e1) { + flag=false; + } finally { + sqlSession.close(); + if (flag){ + System.out.println("删除成功"); + } + } + } + @Test + public void insert() throws IOException { + //1. 加载mybatis的核心配置文件,获取 SqlSessionFactory + String resource = "mybatis-config.xml"; + + InputStream inputStream = Resources.getResourceAsStream(resource); + SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream); + SqlSession sqlSession = build.openSession(); + + + boolean flag=true; + try { + + User user = new User(); + user.setUsername("x狗狗"); + user.setGender("女"); + user.setAddr("狗窝"); + user.setPassword("123456"); + + sqlSession.insert("test.insert",user); + sqlSession.commit(); + sqlSession.close(); + + + // 可能抛出异常的代码 + } catch (Exception e1) { + flag=false; + } finally { + sqlSession.commit(); + sqlSession.close(); + if (flag){ + System.out.println("新建成功"); + } + } + } + @Test + public void update() throws IOException { + //1. 加载mybatis的核心配置文件,获取 SqlSessionFactory + String resource = "mybatis-config.xml"; + InputStream inputStream = Resources.getResourceAsStream(resource); + SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream); + SqlSession sqlSession = build.openSession(); + boolean flag=true; + try { + + User user = new User(); + user.setId(4); + user.setUsername("xmu狗狗"); + user.setGender("女"); + user.setAddr("狗窝"); + user.setPassword("123456"); + sqlSession.update("test.update",user); + + // 可能抛出异常的代码 + } catch (Exception e1) { + flag=false; + } finally { + sqlSession.commit(); + sqlSession.close(); + if (flag){ + System.out.println("修改成功"); + } + } + + } +} + +``` + +mybatis-config.xml + +```java + + + + + + + + + + + + + + + + + + +``` + +UserMapper.xml + +```java + + + + + + + delete from tb_user where id=#{id} + + + insert into tb_user(username,password,gender,addr) values (#{username},#{password},#{gender},#{addr}) + + + update tb_user SET username = #{username}, password = #{password},gender=#{gender},addr=#{addr} where id=#{id} ; + + + + +``` + +User + +```java +package com.mdd.pojo; + +public class User { + private int id; + private String username; + private String password; + private String gender; + private String addr; + + public User(int id, String username, String password, String gender, String addr) { + this.id = id; + this.username = username; + this.password = password; + this.gender = gender; + this.addr = addr; + } + + public User() { + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getAddr() { + return addr; + } + + public void setAddr(String addr) { + this.addr = addr; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", username='" + username + '\'' + + ", password='" + password + '\'' + + ", gender='" + gender + '\'' + + ", addr='" + addr + '\'' + + '}'; + } +} + +``` +~~~ \ No newline at end of file -- Gitee From 7a4448ae7fe378a280c5304bcc17f130e72b4f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E7=BF=94?= <2045602860@qq.com> Date: Mon, 25 Dec 2023 13:43:21 +0000 Subject: [PATCH 4/4] =?UTF-8?q?34=20=E5=88=98=E6=99=BA=E7=BF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘智翔 <2045602860@qq.com> --- ...36\345\210\240\346\224\271\346\237\245.md" | 386 ++++++++++++++++++ .../mybatis\347\273\203\344\271\240.md" | 280 +++++++++++++ 2 files changed, 666 insertions(+) create mode 100644 "34 \345\210\230\346\231\272\347\277\224/mybatis\345\242\236\345\210\240\346\224\271\346\237\245.md" create mode 100644 "34 \345\210\230\346\231\272\347\277\224/mybatis\347\273\203\344\271\240.md" diff --git "a/34 \345\210\230\346\231\272\347\277\224/mybatis\345\242\236\345\210\240\346\224\271\346\237\245.md" "b/34 \345\210\230\346\231\272\347\277\224/mybatis\345\242\236\345\210\240\346\224\271\346\237\245.md" new file mode 100644 index 0000000..9bb7c9d --- /dev/null +++ "b/34 \345\210\230\346\231\272\347\277\224/mybatis\345\242\236\345\210\240\346\224\271\346\237\245.md" @@ -0,0 +1,386 @@ +``` +笔记 + + +使用Mapper代理方式,必须满足以下要求: +1.定义与SQL映射文件同名的Mapper接口, +2.在 Mapper 接口中定义方法,方法名就是SQL映射文件中sql语句的id,并保持 +参数类型和返回值类型一致 + +- namespace:名称空间。必须是对应接口的全限定名 > + + + select * from tb_brand + + + + + + + + + + + delete from tb_brand where id in( + #{id} + ); + + + + update tb_brand + + + brand_name= #{brandName}, + + + company_name= #{companyName}, + + + ordered= #{ordered}, + + + description= #{description}, + + + status= #{status}, + + + where id=#{id}; + + +``` \ No newline at end of file diff --git "a/34 \345\210\230\346\231\272\347\277\224/mybatis\347\273\203\344\271\240.md" "b/34 \345\210\230\346\231\272\347\277\224/mybatis\347\273\203\344\271\240.md" new file mode 100644 index 0000000..3b5f224 --- /dev/null +++ "b/34 \345\210\230\346\231\272\347\277\224/mybatis\347\273\203\344\271\240.md" @@ -0,0 +1,280 @@ +笔记: + +``` +使用Mapper代理方式,必须满足以下要求: +1.定义与SQL映射文件同名的Mapper接口, +2.在 Mapper 接口中定义方法,方法名就是SQL映射文件中sql语句的id,并保持 +参数类型和返回值类型一致 +- namespace:名称空间。必须是对应接口的全限定名 > + +