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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..f15f98ee25d959459d58cf291241eae81356cfbd --- /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 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 0000000000000000000000000000000000000000..d6cdf5eff7614ceab40e79ea48d54f097a5b6fcf --- /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 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 0000000000000000000000000000000000000000..9bb7c9d1fc569708fcb66460fe81c2403f831eec --- /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 0000000000000000000000000000000000000000..3b5f2242a5e686679e666b5294448df103a12061 --- /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:名称空间。必须是对应接口的全限定名 > + +