JDBC Maven MyBatis

news2024/9/28 13:24:22

文章目录

  • JDBC(Java Database Connectivity)
    • 入门
    • API详解
        • DriverManger(驱动管理类)
        • Connection(数据库连接对象)作用
        • Statement
        • ResultSet(结果集对象)
        • PreparedStatement
    • 连接池
  • Maven
    • Maven模型
    • Maven 常用命令
    • 依赖范围
  • MyBatis
    • 快速入门
    • Mapper代理开发
    • Mybatis核心配置文件
      • 查看所有数据
      • 查看详情
      • 条件查询
      • 动态sql
      • 添加
      • 修改
      • 删除
    • MyBatis 参数传递
    • 注解开发

JDBC(Java Database Connectivity)

链接
概念:用JAVA操作关系型数据库的API
本质:JDBC是sun公司定义的接口/规则,实现类由数据库厂商实现,称为驱动。
好处:同一套代码操作不同的关系型数据库;可以随时替换底层数据库,访问数据库的Java代码基本不变。

入门

下载jar包
在项目新建路径,放入jar包,add as library

代码

public class demo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
      1.注册驱动  在mysql5之后的驱动jar包可以不写,在jar包中的meta-inf中services中的java.sql.Driver中记录
//        Class.forName("com.mysql.cj.jdbc.Driver");

//        Driver中有静态代码块,进行注册驱动
//        static {
//        try {
//            DriverManager.registerDriver(new Driver());注册驱动
//        } catch (SQLException var1) {
//            throw new RuntimeException("Can't register driver!");
//        }
//    }
//      2.获取连接   如果是本机的3306可以简写url="jdbc:mysql:///jdbcdemo?useSSL=false&serverTimezone=UTC";
        String url="jdbc:mysql://127.0.0.1:3306/jdbcdemo?useSSL=false&serverTimezone=UTC";
        String usr="root";
        String pwd="000000";

        Connection connection= DriverManager.getConnection(url,usr,pwd);

//      3.定义sql
        String sql="update user set pwd ='2' where user='1'";

//      4.获取执行sql的对象的statement
        Statement statement=connection.createStatement();
//      5.执行sql,返回受影响的行数
        int count=statement.executeUpdate(sql);
//      6.释放资源
        statement.close();
        connection.close();


    }
}

API详解

DriverManger(驱动管理类)

1.注册驱动 registerDriver
2.获取数据库连接 getConnection

Connection(数据库连接对象)作用

1.获取执行SQL的对象

createStatement 普通执行
prepareStatement 防止sql注入
CallableStatement prepareCall 执行存储过程的对象
获取的CallableStatement 执行对象是用来执行存储过程的,而存储过程在mysql中不常用。

2.管理事务

MySQL事务管理
开启事务:BEGIN;/START TRANSACTION
提交事务:COMMIT;
回滚事务:ROLLBACK;
mysql默认自动提交事务

JDBC事务管理:Connection接口中定义了三个对应的方法
开启事务:setAutoCommit(boolean autoCommit):true为自动提交事务;false为手动提交事务,即为开启事务。
提交事务:commit();
回滚事务:rollback();

public static void main(String[] args) throws ClassNotFoundException, SQLException {
      1.注册驱动  在mysql5之后的驱动jar包可以不写,在jar包中的meta-inf中services中的java.sql.Driver中记录
//        Class.forName("com.mysql.cj.jdbc.Driver");

//        Driver中有静态代码块,进行注册驱动
//        static {
//        try {
//            DriverManager.registerDriver(new Driver());注册驱动
//        } catch (SQLException var1) {
//            throw new RuntimeException("Can't register driver!");
//        }
//    }
//      2.获取连接   如果是本机的3306可以简写url="jdbc:mysql:///jdbcdemo?useSSL=false&serverTimezone=UTC";
        String url="jdbc:mysql://127.0.0.1:3306/jdbcdemo?useSSL=false&serverTimezone=UTC";
        String usr="root";
        String pwd="000000";

        Connection connection= DriverManager.getConnection(url,usr,pwd);

//      3.定义sql
        String sql1="update user set pwd ='3' where user='1'";
        String sql2="update user set pwd ='3' where user='2'";

//      4.获取执行sql的对象的statement
      Statement statement=connection.createStatement();
        try {
            connection.setAutoCommit(false);

            int count1=statement.executeUpdate(sql1);
            System.out.println(count1);
            int i=3/0;
            int count2=statement.executeUpdate(sql2);
            System.out.println(count2);
//            提交
            connection.commit();
        }catch (Exception e){
            connection.rollback();
//            出现异常回滚
            e.printStackTrace();
        }

//      6.释放资源
        statement.close();
        connection.close();


    }

Statement

执行sql语句
int executeUpdate(sql) 执行DML,DDL语句(DML操作数据,DDL操作表结构)
返回值:DML为影响的行数,DDL执行成功也可能返回0

ResultSet executeQuery 执行DQL语句
返回值:Result结果集对象

ResultSet(结果集对象)

boolean next(): 1.将光标从当前位置向下移动一行 2.判断当前行是否为有效行
xxx getXXX(参数);
参数:int 列的编号,从1开始。String 列的名称。

public static void main(String[] args) throws ClassNotFoundException, SQLException {
      1.注册驱动  在mysql5之后的驱动jar包可以不写,在jar包中的meta-inf中services中的java.sql.Driver中记录
//        Class.forName("com.mysql.cj.jdbc.Driver");

//        Driver中有静态代码块,进行注册驱动
//        static {
//        try {
//            DriverManager.registerDriver(new Driver());注册驱动
//        } catch (SQLException var1) {
//            throw new RuntimeException("Can't register driver!");
//        }
//    }
//      2.获取连接   如果是本机的3306可以简写url="jdbc:mysql:///jdbcdemo?useSSL=false&serverTimezone=UTC";
        String url="jdbc:mysql://127.0.0.1:3306/jdbcdemo?useSSL=false&serverTimezone=UTC";
        String usr="root";
        String pwd="000000";

        Connection connection= DriverManager.getConnection(url,usr,pwd);

//      3.定义sql
        String sql1="select * from user";

//      4.获取执行sql的对象的statement
      Statement statement=connection.createStatement();


      ResultSet rs=  statement.executeQuery(sql1);
      while (rs.next()){
//          int user=rs.getInt(1);
//          String password=rs.getString(1);
          int user=rs.getInt("user");
          String password=rs.getString("pwd");
          System.out.println("id="+user+"  pwd="+password);
      }




//      6.释放资源
        rs.close();
        statement.close();
        connection.close();


    }

PreparedStatement

继承Statement
预编译sql,性能更高
预防SQL注入:将敏感字符进行转义

public static void main(String[] args) throws ClassNotFoundException, SQLException {
      1.注册驱动  在mysql5之后的驱动jar包可以不写,在jar包中的meta-inf中services中的java.sql.Driver中记录
//        Class.forName("com.mysql.cj.jdbc.Driver");

//        Driver中有静态代码块,进行注册驱动
//        static {
//        try {
//            DriverManager.registerDriver(new Driver());注册驱动
//        } catch (SQLException var1) {
//            throw new RuntimeException("Can't register driver!");
//        }
//    }
//      2.获取连接   如果是本机的3306可以简写url="jdbc:mysql:///jdbcdemo?useSSL=false&serverTimezone=UTC";
        String url="jdbc:mysql://127.0.0.1:3306/jdbcdemo?useSSL=false&serverTimezone=UTC&useServerPrepStmts=true";
        String usr="root";
        String pwd="000000";

        Connection connection= DriverManager.getConnection(url,usr,pwd);

//      3.定义sql
        String sql="update user set pwd =? where user='1'";

//      4.获取PreparedStatement对象  此时已经进行了预编译
      PreparedStatement statement=connection.prepareStatement(sql);
//      5.设置?的值
       statement.setString(1,"2");
//      执行sql
        int count=statement.executeUpdate();

        System.out.println(count);


//      6.释放资源
        statement.close();
        connection.close();


    }

开启预编译 在建立连接的url后面加上&useServerPrepStmts=true

配置mysql执行日志
在mysql配置文件(my.ini)中添加如下配置 (需要重启)
log-output=FILE
general-log=1
general_log_file=“D:\mysql.log”
slow-query-log=1
slow_query_log_file=“D:\mysql_slow.log”
long_query_time=2

Java代码操作数据库流程:

  • 将sql语句发送到MySQL服务器端

  • MySQL服务端会对sql语句进行如下操作

    • 检查SQL语句

      检查SQL语句的语法是否正确。

    • 编译SQL语句。将SQL语句编译成可执行的函数。

      检查SQL和编译SQL花费的时间比执行SQL的时间还要长。如果我们只是重新设置参数,那么检查SQL语句和编译SQL语句将不需要重复执行。这样就提高了性能。

    • 执行SQL语句

    开启预编译,第二次执行可以省略前面两步

连接池

简介
数据库连接池是个容器,负责分配连接。
允许应用重复使用一个现有的数据库连接,而不是再重新建立一个。
使用之后不成功释放资源称为连接泄露。

连接池是一开始就创建连接,使用从中取,使用完毕归还即可。
实现
SUN提供数据库连接池标准接口,由第三方实现
Connection getConnection();
不需要通过DriverManager获取connection对象,而是从连接池datasource获取connection对象。

常见的数据库连接池:DBCP,C3p0,Druid

Druid(德鲁伊)

  • Druid连接池是阿里巴巴开源的数据库连接池项目
  • 功能强大,性能优秀,是Java语言最好的数据库连接池之一

druid.properties

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/jdbcdemo?useSSL=false&serverTimezone=UTC&useServerPrepStmts=true
username=root
password=000000
# 初始化连接数量
initialSize=5
# 最大连接数
maxActive=10
# 最大等待时间
maxWait=3000
public static void main(String[] args) throws Exception {
//        1.导入jar包
//        2.定义配置文件
//        3.加载配置文件
        Properties properties=new Properties();
        properties.load(new FileInputStream("D:\\project2\\headfirst\\src\\main\\resources\\druid.properties"));
//        4.获取连接池对象
        DataSource dataSource= DruidDataSourceFactory.createDataSource(properties);
//        5.获取数据库连接
        Connection connection=dataSource.getConnection();
        System.out.println(connection);

//        System.out.println(System.getProperty("user.dir"));
    }

Maven

管理和构建Java项目的工具

  • 提供标准化的项目结构
    在这里插入图片描述

  • 提供标准化的构建流程 (编译,测试,打包,发布…)
    在这里插入图片描述

  • 提供了一套依赖管理机制
    在这里插入图片描述
    在这里插入图片描述

Maven模型

项目对象模型(Project Object Model)pom
依赖管理模型(Dependency)
插件(Plugin)

阿里云私服

<mirror>  
    <id>alimaven</id>  
    <name>aliyun maven</name>  
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>          
</mirror>

Maven 常用命令

compile :编译 生成target
clean:清理 清除target
package:打包 生成jar包
install:打包 并安装到仓库

Maven 坐标主要组成

  • groupId:组织名称(通常是域名反写,例如:com.itheima)
  • artifactId:项目名称(通常是模块名称,例如 order-service、goods-service)
  • version:版本号

依赖范围

dependency中的scope属性,不设置默认为compile

依赖范围编译classpath测试classpath运行classpath例子
compileYYYlogback
test-Y-Junit
providedYY-servlet-api
runtime-YYjdbc驱动
systemYY-存储在本地的jar包

MyBatis

官网
持久层框架,用来简化JDBC开发
Mybatis是apache的一个开源项目ibatis,2010年这个项目由apache software foundation迁移到了google code 并且改名为Mybatis,2013年11月迁移到了Github。

持久层

  • 负责将数据保存到数据库的那一层代码
  • JAVA EE三层架构:表现层,业务层,持久层

JDBC缺点
1.硬编码 :注册驱动,获取连接;sql语句;
2.操作繁琐:手动设置参数;手动封装结果集;

快速入门

1.编写核心配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
<!--                数据库连接信息-->
                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql:///mybatis?useSSL=false&amp;serverTimezone=UTC&amp;useServerPrepStmts=true"/>
                <property name="username" value="root"/>
                <property name="password" value="000000"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
<!--        加载sql映射文件-->
        <mapper resource="UserMapper.xml"/>
    </mappers>
</configuration>

2.编写sql映射文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace:名称空间-->
<mapper namespace="test">
    <select id="selectAll" resultType="com.ln.pojo.User">
        select * from tb_user
    </select>
</mapper>

3.编写代码

 public static void main(String[] args) throws IOException {
//        1.添加mybatis的核心配置文件,获取sqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

//        2.获取sqlSession对象
        SqlSession sqlSession=sqlSessionFactory.openSession();

//        3.执行sql
        List<User> users=sqlSession.selectList("test.selectAll");

        System.out.println(users);

//        4.释放资源
        sqlSession.close();
    }

Mapper代理开发

1.定义同名mapper接口,将接口和sql映射文件放在同一目录下
2.设置名称空间为接口的全类名
3.在接口定义方法,方法名就是sql映射文件中的id,并保持参数类型和返回值一致。

 public static void main(String[] args) throws IOException {
//        1.添加mybatis的核心配置文件,获取sqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

//        2.获取sqlSession对象
        SqlSession sqlSession=sqlSessionFactory.openSession();

//        3.执行sql
//        List<User> users=sqlSession.selectList("test.selectAll");

//        3.1 获取UserMapper接口的代理对象
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = userMapper.selectAll();


        System.out.println(users);

//        4.释放资源
        sqlSession.close();
    }

配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
<!--                数据库连接信息-->
                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql:///mybatis?useSSL=false&amp;serverTimezone=UTC&amp;useServerPrepStmts=true"/>
                <property name="username" value="root"/>
                <property name="password" value="000000"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
<!--&lt;!&ndash;        加载sql映射文件&ndash;&gt;-->
<!--        <mapper resource="com/ln/mapper/UserMapper.xml"/>-->

<!--        Mapper代理方式-->
        <package name="com.ln.mapper"/>
    </mappers>
</configuration>

Mybatis核心配置文件

环境配置

在核心配置文件的 environments 标签中其实是可以配置多个 environment ,使用 id 给每段环境起名,在 environments 中使用 default='环境id' 来指定使用哪儿段配置。我们一般就配置一个 environment 即可。

别名

<typeAliases>
  <package name="domain.blog"/>
</typeAliases>

此时resulttype不需要带包名了。

配置需要遵循官网的顺序。

在idea中安装mybatisX来协助开发。

Mybatis完成操作需要几步?
1.编写接口方法
2.编写SQL
3.执行方法

查看所有数据

数据库字段名和实体类字段名称不一致,无法自动封装。
1.起别名
缺点:每次查询都要定义别名,可以用sql片段解决
sql片段

<sql id="brand_column">
	id, brand_name as brandName, company_name as companyName, ordered, description, status
</sql>

<select id="selectAll" resultType="brand">
    select
    <include refid="brand_column" />
    from tb_brand;
</select>

缺点:不灵活

2.resultMap

<resultMap id="brandResultMap" type="com.ln.mybatis.pojo.Brand">
<!--        id:完成主键的映射,result:完成一般字段的映射-->
<!--        column 列名       property 属性名-->
        <result column="brand_name" property="brandName"></result>
        <result column="company_name" property="companyName"></result>
    </resultMap>

    <select id="selectAll" resultMap="brandResultMap">
        select * from tb_brand;
    </select>

查看详情

参数占位符
1.#{}: 会将其替换为 ?,为了防止sql注入
2.${}: 拼sql。会存在sql注入的问题
3.使用时机:
参数传递时使用 #{}
表名或者列名不固定的情况下使用 ${}

parameterType
用来设置参数类型,可以省略

<select id="selectById" parameterType="int" resultMap="brandResultMap">
    select *
    from tb_brand where id = ${id};
</select>

特殊字符处理
1.转义字符 &lt; 就是 < 的转义字符
2.CDATA区 <![CDATA[内容]]>

条件查询

多条件查询
1.@Param(“sql中参数占位符的名称”)
2.实体类对象 sql参数名和实体属性名对应
3.Map集合 sql参数名和map中的key对应

List<Brand> selectByCondition(@Param("status") int status, @Param("companyName") String companyName,@Param("brandName") String brandName);

List<Brand> selectByCondition(Brand brand);

List<Brand> selectByCondition(Map map);
 @Test
    public void testSelectByCondition() throws IOException {

        int staues=1;
        String companyName="%华为%";
        String brandName="%华为%";

        Brand brand=new Brand();
        brand.setStatus(1);
        brand.setCompanyName("%华为%");
        brand.setBrandName("%华为%");

        Map map = new HashMap();
        map.put("status" , staues);
        map.put("companyName", companyName);
        map.put("brandName" , brandName);

//        1、获取sqlsessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

//        2.获取sqlsession对象
        SqlSession sqlSession = sqlSessionFactory.openSession();

//        3.获取Mapper接口的代理对象  crtl alt v 快速声明对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

//        4.执行方法
        List<Brand> brands=mapper.selectByCondition(staues,companyName,brandName);
        System.out.println("结果为"+brands);

        List<Brand> brands2=mapper.selectByCondition(brand);
        System.out.println("结果为"+brands2);

        List<Brand> brands3=mapper.selectByCondition(map);
        System.out.println("结果为"+brands3);

//        5.释放资源
        sqlSession.close();

    }

动态sql

多条件

<select id="selectByCondition" resultMap="brandResultMap">
    select *
    from tb_brand
    <where>
        <if test="status != null">
            and status = #{status}
        </if>
        <if test="companyName != null and companyName != '' ">
            and company_name like #{companyName}
        </if>
        <if test="brandName != null and brandName != '' ">
            and brand_name like #{brandName}
        </if>
    </where>
</select>

and 必须要加,mybatis会帮你删掉第一个and,但是不会帮你多加
单条件

/**
  * 单条件动态查询
  * @param brand
  * @return
  */
List<Brand> selectByConditionSingle(Brand brand);
<select id="selectByConditionSingle" resultMap="brandResultMap">
    select *
    from tb_brand
    <where>
        <choose><!--相当于switch-->
            <when test="status != null"><!--相当于case-->
                status = #{status}
            </when>
            <when test="companyName != null and companyName != '' "><!--相当于case-->
                company_name like #{companyName}
            </when>
            <when test="brandName != null and brandName != ''"><!--相当于case-->
                brand_name like #{brandName}
            </when>
        </choose>
    </where>
</select>

添加

mybatis事务
openSession(); 默认开启事务,需要sqlSession.commit();
openSession(true); 可以设置为自动提交事务(关闭事务)

 /**
   * 添加
   */
void add(Brand brand);
<insert id="add">
    insert into tb_brand (brand_name, company_name, ordered, description, status)
    values (#{brandName}, #{companyName}, #{ordered}, #{description}, #{status});
</insert>

返回添加数据的主键

<insert id="add" useGeneratedKeys="true" keyProperty="id">
    insert into tb_brand (brand_name, company_name, ordered, description, status)
    values (#{brandName}, #{companyName}, #{ordered}, #{description}, #{status});
</insert>

修改

 /**
   * 修改
   */
void update(Brand brand);
 <update id="update">
        update tb_brand
        <set>
            <if test="brandName != null and brandName != ''">
                brand_name = #{brandName},
            </if>
            <if test="companyName != null and companyName != ''">
                company_name = #{companyName},
            </if>
            <if test="ordered != null">
                ordered = #{ordered},
            </if>
            <if test="description != null and description != ''">
                description = #{description},
            </if>
            <if test="status != null">
                status = #{status}
            </if>
        </set>
        where id = #{id};
    </update>

删除

单个

/**
  * 根据id删除
  */
void deleteById(int id);
<delete id="deleteById">
    delete from tb_brand where id = #{id};
</delete>

批量

/**
  * 批量删除
  */
void deleteByIds(int[] ids);
<delete id="deleteByIds">
    delete from tb_brand where id
    in
    <foreach collection="array" item="id" separator="," open="(" close=")">
        #{id}
    </foreach>
    ;
</delete>

collection 属性:

  • mybatis会将数组参数,封装为一个Map集合。
    • 默认:array = 数组
    • 使用@Param注解改变map集合的默认key的名称
void deleteByIds(@Param("ids") int[] ids);

MyBatis 参数传递

Mybatis 接口方法中可以接收各种各样的参数,如下:

  • 多个参数:封装为Map集合

MyBatis提供了 ParamNameResolver类来进行参数封装

会将值进行两次放置 一次k为arg0,一次为param0。
使用@param会替换arg0

  • 单个参数

  • POJO 类型

    直接使用。要求 属性名参数占位符名称 一致

  • Map 集合类型

    直接使用。要求 map集合的键名参数占位符名称 一致

  • Collection 集合类型

    Mybatis 会将集合封装到 map 集合中,如下:

    map.put(“arg0”,collection集合);

    map.put(“collection”,collection集合;

    可以使用 @Param 注解替换map集合中默认的 arg 键名。

  • List 集合类型

    Mybatis 会将集合封装到 map 集合中,如下:

    map.put(“arg0”,list集合);

    map.put(“collection”,list集合);

    map.put(“list”,list集合);

    可以使用 @Param 注解替换map集合中默认的 arg 键名。

  • Array 类型

    Mybatis 会将集合封装到 map 集合中,如下:

    map.put(“arg0”,数组);

    map.put(“array”,数组);

    可以使用 @Param 注解替换map集合中默认的 arg 键名。

  • 其他类型

    比如int类型,参数占位符名称 叫什么都可以。尽量做到见名知意

注解开发

注解用于简单语句

@Select(value = "select * from tb_user where id = #{id}")
public User select(int id);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/174976.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

简单二叉树的介绍

1.树的结构&#xff08;了解&#xff09;1.1概念树是一种非线性的数据结构&#xff0c;它是由n&#xff08;n>0)个有限节点总成一个具有层次关系的集合。把它叫做树是因为它看起来像一颗倒挂的树&#xff0c;也就是说它的根是朝上&#xff0c;而叶子是朝下的&#xff08;本人…

工作玩手机识别监测系统 YOLOv5

工作玩手机识别监测系统通过YOLOV5网络深度学习算法模型对画面中人员玩手机行为进行实时监测&#xff0c;当识别到有人在玩手机行为时&#xff0c;无需人为干预立即抓拍存档触发告警。YOLO算法- YOLO算法是一种基于回归的算法&#xff0c;它不是选择图像中有趣的部分&#xff0…

WT588D语音芯片介绍

WT588D语音芯片简介WT588D 语音芯片是一款功能强大的可重复擦除烧写的语音单片机芯片。WT588D 让语音芯片不再为控制方式而寻找合适的外围单片机电路&#xff0c;高度集成的单片机技术足于取代复杂的外围控制电路。配套WT588DVoiceChip 上位机操作软件可随意更换WT588D 语音单片…

基于 docker 搭建 mysql5.7 主从复制

安装 docker 的教程可以看我的另一篇文章&#xff0c;拉取 mysql 镜像的步骤也在里面&#xff0c;在这不再重复&#xff1a;https://blog.csdn.net/wanzijy/article/details/128695674 1. 主机搭建 因为本人虚拟机中已经存在了 mysql &#xff0c;所以在使用镜像创建容器的时…

【论文翻译】End-to-End Human Pose and Mesh Reconstruction with Transformers

【cvpr论文】End-to-End Human Pose and Mesh Reconstruction with Transformers (thecvf.com) 【github】microsoft/MeshTransformer: Research code for CVPR 2021 paper "End-to-End Human Pose and Mesh Reconstruction with Transformers" (github.com) 摘要 我…

学习笔记:Java 并发编程③

若文章内容或图片失效&#xff0c;请留言反馈。 部分素材来自网络&#xff0c;若不小心影响到您的利益&#xff0c;请联系博主删除。 视频链接&#xff1a;https://www.bilibili.com/video/av81461839配套资料&#xff1a;https://pan.baidu.com/s/1lSDty6-hzCWTXFYuqThRPw&am…

在甲骨文云容器实例(Container Instances)上部署Ubuntu Desktop

甲骨文云推出了容器实例&#xff0c;这是一项无服务器计算服务&#xff0c;可以即时运行容器&#xff0c;而无需管理任何服务器。 今天我们尝试一下通过容器实例部署Ubuntu Bionic Desktop。 创建容器实例 在甲骨文容器实例页面&#xff0c;单击"创建容器实例"&…

Java 笔试题

Java 笔试题目录概述需求&#xff1a;设计思路实现思路分析1.java 面试题参考资料和推荐阅读Survive by day and develop by night. talk for import biz , show your perfect code,full busy&#xff0c;skip hardness,make a better result,wait for change,challenge Surviv…

分享151个PHP源码,总有一款适合您

PHP源码 分享151个PHP源码&#xff0c;总有一款适合您 下面是文件的名字&#xff0c;我放了一些图片&#xff0c;文章里不是所有的图主要是放不下...&#xff0c; 151个PHP源码下载链接&#xff1a;https://pan.baidu.com/s/1T_Hs4j0t39b-Y8UWHmAKyw?pwd7ao0 提取码&#…

论文浅尝 | DB4Trans:数据库内置知识图谱嵌入模型训练引擎

笔记整理&#xff1a;柳鹏凯&#xff0c;天津大学硕士发表期刊&#xff1a;计算机学报 第45卷Vol.45, 第9期 No.9链接&#xff1a;http://cjc.ict.ac.cn/online/onlinepaper/lpk-202297212908.pdf动机知识图谱嵌入技术主要将知识图谱中的实体和关系嵌入到连续的向量空间中&…

Centos Java1.8+Nginx+redis+pgsql 手工配置

一、系统升级&#xff0c;安装系统常用工具及配置 1.1 升级软件及Centos 内核 yum update -y yum clean all cat /etc/redhat-release 1.2 安装虚拟机守护进程 yum install qemu-guest-agent -y 1.3 安装系统常用工具包 yum install lrzsz vim wget dnf -y 1.4关…

2023牛客寒假算法基础集训营3 -- E-勉强拼凑的记忆(贪心 + 二分)

题目如下&#xff1a; 题解 or 思路&#xff1a; 我们可以发现&#xff1a;除了 n2n 2n2 无解&#xff0c; 其他情况答案至少为 n12\frac{n 1}{2}2n1​ 答案在 n12\frac{n 1}{2}2n1​ 到 nnn 之间 我们可以假设 答案为 ansansans 最优摆放为&#xff1a; 所以可以二分去求…

软件工程 黄金点游戏

这个故事最初出现在 《移山之道》中&#xff0c;我经常拿来做和创新的时机相关课堂练习和讨论&#xff0c;效果很好。我把这个练习和它的一些延伸话题都搬到这个新博客里。 黄金点游戏 N个同学&#xff08;N通常大于10&#xff09;&#xff0c;每人写一个 0~100之间的有理数 …

1、认识IntelliJ IDEA

文章目录1、认识IntelliJ IDEA1.1 JetBrains公司介绍1.2 IntelliJ IDEA介绍1.3 IDEA的主要优势&#xff08;对比Eclipse&#xff09;1.3.1 功能强大1.3.2 符合人体工程学1.4 IDEA的下载【尚硅谷】idea实战教程-讲师&#xff1a;宋红康 生活是属于每个人自己的感受&#xff0c;不…

Python:Docx文档模板创建使用

✨博文作者 wangzirui32 &#x1f496; 喜欢的可以 点赞 收藏 关注哦~~ &#x1f449;本文首发于CSDN&#xff0c;未经许可禁止转载 &#x1f60e;Hello&#xff0c;大家好&#xff0c;我是wangzirui32&#xff0c;今天我们来学习Docx文档模板创建与使用&#xff0c;开始学习吧…

2023新春祝福html代码,包你学会

前言大家新年好&#xff01;今天是年三十&#xff0c;在这个充满喜悦和欢乐的节日里&#xff0c;祝大家新年快乐。不论你在外面过的风生水起还是不尽人意&#xff0c;回到家一家人团团聚聚才是最好的。进入正题&#xff0c;我们作为IT民工&#xff0c;我们要用自己的方式表达对…

第三天总结 之 商品管理界面的实现 之 页面中 下拉框问题的解决

页面中下拉框问题的解决 在页面中 点击商品类型这个图标 会出现下拉框 展示所有的商品类型 然后通过选择的 类型 来作为 查询时的一个条件 即 当不选或选择展示所有商品时 按照 不对这个条件进行操作 选择其他的商品类型时 会查询出含有该类型的商品 下拉框中 数据的展示与 如…

java设计模式中责任链模式是什么/怎么用责任链模式避免if-else语句

继续整理记录这段时间来的收获&#xff0c;详细代码可在我的Gitee仓库SpringBoot克隆下载学习使用&#xff01; 6.5 责任链模式 6.5.1 定义 职责链模式&#xff0c;为避免请求发生者与多个处理者耦合在一起&#xff0c;将所有请求处理者通过前一对象记住其下一对象的引用而连…

重学Attention

注意力机制对比RNN 主要解决了RNN无法并行&#xff0c;并且不能解决长序列依赖问题 所以为什么设计 Q K V这三个矩阵 一边来是让 K V的 首先通过Q 和 K点击计算Attention矩阵&#xff0c;这个矩阵表明的是V上每一个特征与Q的相关程度&#xff0c;相关程度高的&#xff0c;权重…

解剖一道有意思的指针题

这道指针题挺有意思的&#xff0c;将各级指针之间的联系联系起来&#xff0c;仔细分析会发现也不难&#xff0c;重在逻辑思维&#xff0c;做完将会加深你对指针的理解的&#xff0c;好好享受指针带来的乐趣吧&#xff01;&#xff01;&#xff01;结果是什么呢&#xff1f;//题…