Java web(二)MyBatis

news2024/7/6 17:44:39

文章目录

  • 一、概述
    • 1.1 快速入门(普通映射方式)
    • 1.2 IDEA操作MySQL数据库
    • 1.3 Mapper代理方式
  • 二、数据库操作【增删改查】
    • 2.1 配置文件方式(将SQL语句写入配置文件中)【完成复杂功能】
    • 2.2 注解方式【完成简单功能】


一、概述

MyBatis是一款持久层框架,用于简化JDBC开发。JavaEE三层架构:表现层[页面展示]、业务层[逻辑处理]、持久层[负责将数据保存到数据库]。
由于JDBC存在一些缺点:硬编码(例如,参数、SQL语句写入到代码中)、操作繁琐(手动设置参数和封装结果集),MyBatis就会设置配置文件、自动完成繁琐操作来解决上述问题。

1.1 快速入门(普通映射方式)

在这里插入图片描述

1.创建user表tb_user

create database mybatis;
use mybatis;

drop table if exists tb_user;

create table tb_user(
	id int primary key auto_increment,
	username varchar(20),
	password varchar(20),
	gender char(1),
	addr varchar(30)
);



INSERT INTO tb_user VALUES (1, 'zhangsan', '123', '', '北京');
INSERT INTO tb_user VALUES (2, '李四', '234', '女', '天津');
INSERT INTO tb_user VALUES (3, '王五', '11', '男', '西安');

2.创建模块导入坐标,配置pom.xml

<?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>Mybatis-demo</groupId>
    <artifactId>Mybatis-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!--mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.3</version>
        </dependency>
        <!--数据库连接-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>
        <!--junit单元测试-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--添加日志slf4j的api-->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>
        <!--添加logback-classic-->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <!--添加日志logback-core-->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.3</version>
        </dependency>
    </dependencies>

</project>

3.编写MyBatis核心配置文件mybatis-config.xml(替换链接信息)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://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.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=false"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <!-- 加载sql映射文件 -->
        <mapper resource="UserMapper.xml"/>
    </mappers>
</configuration>

4.编写SQL映射文件UserMapper.xml(统一管理sql语句)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<!--
    namespace:名称空间
-->
<mapper namespace="test">
    <select id="selectAll" resultType="com.bhy.pojo.User">
    select * from tb_user;
    </select>
</mapper>

5.定义User类,连接数据库

package com.bhy;

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;
import java.util.List;

/**
 * @author 神代言
 * @version 1.0
 */
public class MybatisDemo {
    public static void main(String[] args) throws IOException {
        // 1.加载myatis的核心配置文件,获取SqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        // 2. 获取SqlSession对象,其执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();

        // 3.执行sql
        List<Object> users = sqlSession.selectList("test.selectAll");
        System.out.println(users);
        // 4.释放资源
        sqlSession.close();
    }
}

1.2 IDEA操作MySQL数据库

在这里插入图片描述

输入数据库名、用户名、密码,即可连接数据库。
在这里插入图片描述
连接成功如图所示,点击右侧笔的图标,即可在IDEA中编写SQL语句。
在这里插入图片描述

1.3 Mapper代理方式

在这里插入图片描述
在这里插入图片描述
与1.1方式不同的是,设置了一个UserMapper接口UserMapper.xml对应
mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://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.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=false"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <!-- 1.加载sql映射文件 -->
        <!--<mapper resource="com\bhy\mapper\UserMapper.xml"/>-->
        
        <!-- 2.Mapper代理方式 -->
        <package name="com.bhy.mapper"/>
    </mappers>
</configuration>

UserMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<!--
    namespace:名称空间,   代理方式保证命名空间namesapce与Mapper接口对应
-->
<mapper namespace="com.bhy.mapper.UserMapper">
    <select id="selectAll" resultType="com.bhy.pojo.User">
    select * from tb_user;
    </select>
</mapper>

UserMapper.java

package com.bhy.mapper;

import com.bhy.pojo.User;

import java.util.List;

/**
 * @author 神代言
 * @version 1.0
 */
public interface UserMapper {
    List<User> selectAll();
}

MybatisDemo2.java

package com.bhy;

import com.bhy.mapper.UserMapper;
import com.bhy.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 java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author 神代言
 * @version 1.0
 */
public class MybatisDemo2 {
    public static void main(String[] args) throws IOException {
        // 1.加载myatis的核心配置文件,获取SqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        // 2. 获取SqlSession对象,其执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
        
//        // 传统方式仍存在硬编码问题
//        List<Object> users = sqlSession.selectList("test.selectAll");
//        System.out.println(users);
        
        // 3.执行sql(通过Mapper代理方式)
        UserMapper usermapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = usermapper.selectAll();
        System.out.println(users);
        // 4.释放资源
        sqlSession.close();
    }
}

二、数据库操作【增删改查】

2.1 配置文件方式(将SQL语句写入配置文件中)【完成复杂功能】

该方式参考1.1和1.3

书写Mapper.xml的注意事项:

一、数据库表的字段名称和实体类的属性名称不一样,则不能自动封装数据
解决方法:
(1)起别名:对不一样的列名起别名,让别名和实体类的属性名一样
缺点:每次查询都要定义一次别名,不灵活
(2)resultMap:定义标签,在标签中,使用resultMap属性替换 resultType属性

二、参数占位符:

  1. #{}:会将其替换为 ?,为了防止SQL注入
  2. ${}:拼sql。会存在SQL注入问题
  3. 使用时机:
    (1)参数传递的时候:#{}
    (2)表名或者列名不固定的情况下:${} 会存在SQL注入问题
  4. 参数类型:parameterType:可以省略
  5. 特殊字符处理:例如 < 号
    (1)转义字符:
    (2)CDATA区:使用“CD”命令,将字符写入CDATA区中

三、动态条件查询
格式:< where>< if test=“条件判断”>and 查询语句< /if>< where>

if语句:(多条件动态查询)
select * from tb_brand
        /* where 1 = 1*/
        <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>

switch case语句:(单条件动态查询)
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>
            
            <otherwise> <!--相当于default-->
                1 = 1
            </otherwise>

        </choose>
        </where>

配置文件BrandMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<!--
    namespace:名称空间
-->

<mapper namespace="com.bhy.mapper.BrandMapper">

    <!--注意细节:
        一、数据库表的字段名称  和  实体类的属性名称 不一样,则不能自动封装数据
            * 起别名:对不一样的列名起别名,让别名和实体类的属性名一样
                * 缺点:每次查询都要定义一次别名
                    * sql片段
                        * 缺点:不灵活
            * resultMap:
                1. 定义<resultMap>标签
                2.<select>标签中,使用resultMap属性替换 resultType属性

    -->
    <!--
        id:唯一标识
        type:映射的类型,支持别名
    -->
    <resultMap id="brandResultMap" type="Brand">
        <!--
            id:完成主键字段的映射
                column:表的列名
                property:实体类的属性名
            result:完成一般字段的映射
                column:表的列名
                property:实体类的属性名
        -->
        <result column="brand_name" property="brandName"/>
        <result column="company_name" property="companyName"/>
    </resultMap>



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


    <!--
        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>
     -->
    <!--<select id="selectAll" resultType="brand">
        select *
        from tb_brand;
    </select>-->


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

         * 参数类型:parameterType:可以省略
         * 特殊字符处理:例如 <1. 转义字符:
            2. CDATA:
    -->
    <!-- <select id="selectById"  resultMap="brandResultMap">
         select *
         from tb_brand where id = #{id};

     </select>
     -->
    <select id="selectById" resultMap="brandResultMap">
        select *
        from tb_brand
        where id
         <![CDATA[
                  <
         ]]>
         #{id};

    </select>

    <!--
        条件查询
    -->
    <!-- <select id="selectByCondition" resultMap="brandResultMap">
         select *
         from tb_brand
         where status = #{status}
           and company_name like #{companyName}
           and brand_name like #{brandName}
     </select>-->


    <!--
        三、动态条件查询
            格式:<where><if test="条件判断">and 查询语句</if><where>
            * if: 条件判断
                * test:逻辑表达式
            * 问题:
                * 恒等式
                * <where> 替换 where 关键字
    -->
    <!-- 多条件动态查询 -->
    <select id="selectByCondition" resultMap="brandResultMap">
        select *
        from tb_brand
        /* where 1 = 1*/
        <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>
    <!--<select id="selectByConditionSingle" resultMap="brandResultMap">
        select *
        from tb_brand
        where
        <choose>&lt;!&ndash;相当于switch&ndash;&gt;
            <when test="status != null">&lt;!&ndash;相当于case&ndash;&gt;
                status = #{status}
            </when>
            <when test="companyName != null and companyName != '' ">&lt;!&ndash;相当于case&ndash;&gt;
                company_name like #{companyName}
            </when>
            <when test="brandName != null and brandName != ''">&lt;!&ndash;相当于case&ndash;&gt;
                brand_name like #{brandName}
            </when>
            <otherwise>
                1 = 1
            </otherwise>

        </choose>

    </select>-->

    <!-- 单条件动态查询 -->
    <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>


    <!-- 插入 -->
    <!-- 返回主键:useGeneratedKeys="true" keyProperty="id" -->
    <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>

    <!-- 动态更新 -->
    <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>


    <delete id="deleteById">
        delete from tb_brand where id = #{id};
    </delete>
    <!--
        mybatis会将数组参数,封装为一个Map集合。
            * 1.collection默认:array = 数组
            * 2.使用@Param注解改变map集合的默认key的名称

        separator="," open="(" close=")"可以解释为(,,,)
    -->

    <delete id="deleteByIds">
        delete from tb_brand where id
        in
        <foreach collection="array" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
        ;
    </delete>


</mapper>

映射接口文件BrandMapper.java

package com.bhy.mapper;


import com.bhy.pojo.Brand;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * @author 神代言
 * @version 1.0
 */
public interface BrandMapper {
    /**
     * 查询所有
     */
    List<Brand> selectAll();


    /**
     * 查看详情:根据Id查询
     */
    Brand selectById(int id);

    /**
     * 条件查询
     *  * 参数接收
     *      1. 散装参数:如果方法中有多个参数,需要使用@Param("SQL参数占位符名称")
     *      2. 对象参数:对象的属性名称要和参数占位符名称一致
     *      3. map集合参数
     *
     */

    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);

    /**
     * 单条件动态查询
     * @param brand
     * @return
     */
    List<Brand> selectByConditionSingle(Brand brand);


    /**
     * 添加
     */
    void add(Brand brand);


    /**
     * 修改
     */
    int update(Brand brand);

    /**
     * 根据id删除
     */
    void deleteById(int id);


    /**
     * 批量删除
     */
    void deleteByIds(int[] ids);
}

测试文件MybatisBrandTest.java

package com.bhy;

import com.bhy.mapper.BrandMapper;
import com.bhy.pojo.Brand;
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.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MybatisBrandTest {
    public static void main(String[] args) throws IOException {
    }

    @Test
    public void testSQL() throws IOException {
        // 1.加载myatis的核心配置文件,获取SqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        // 2. 获取SqlSession对象,其执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();

        // 3.执行sql(通过Mapper代理方式)
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        // 3.1 全部查询
        List<Brand> brands = mapper.selectAll();
        System.out.println(brands);

        // 3.2 条件查询
        Brand brand = mapper.selectById(2);
        System.out.println(brand);

        // (1) 散装参数
        List<Brand> brands1 = mapper.selectByCondition(1, "%华为%", "%华为%");
        System.out.println(brands1);

        // (2)对象参数
        Brand brand2 = new Brand();
        brand2.setStatus(1);
        brand2.setBrandName("%华为%");
        brand2.setCompanyName("%华为%");
        List<Brand> brands2 = mapper.selectByCondition(brand2);
        System.out.println(brands2);

        // (3) map集合参数
        Map hashMap = new HashMap();
        hashMap.put("status","1");
        hashMap.put("brandName","%华为%");
        hashMap.put("companyName","%华为%");
        List<Brand> brands3 = mapper.selectByCondition(hashMap);
        System.out.println(brands3);

        // 3.3 动态查询

        // 3.4 插入
        brand2.setDescription("");
        brand2.setOrdered(1);
        mapper.add(brand2);

        // 3.5 动态更新
        brand2.setId(3);
        brand2.setDescription("一般般");
        mapper.update(brand2);

        // 3.6 删除
        int[] ids = {3,5,6};
        mapper.deleteByIds(ids);


        // 需要提交事务,才能把数据的增删改执行成功,不然会回滚
        // 或者在定义sqlsession时设置为自动提交
        // 例如:sqlSession = sqlSessionFactory.openSession(true);
        sqlSession.commit();

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

}

2.2 注解方式【完成简单功能】

将配置文件中的sql语句用注解方式写在接口BrandMapper.java的方法上。

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

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

相关文章

近期面试小结

作者&#xff1a;究极逮虾户 最近面试了不少的公司&#xff0c;行情整体来说还是非常差的&#xff0c;如果没有必要不建议大家裸辞&#xff0c;另外就不总结面试的题目了。这次打算着重从项目经验上来给大家讨论下&#xff0c;我觉得这部分可能才是面试中得分比重比较大的部分&…

1-1 prometheus 概述

一、概述 二、特点 三、核心组件 四、基础架构 4.1 Prometheus 的主要模块包含 4.2 运行逻辑 五、Prometheus 与 Zabbix 的对比 六、总结 一、概述 1. 什么是prometheus? 开源系统监控 和 警报工具包受启发于Google的Brogmon监控系统(相似的Kubernetes是从Google的Br…

Flutter 开发、测试,网络调试工具

一、Github地址 NetworkCapture 二、效果图 三、使用方式 添加pub依赖latest_version dependencies:network_capture: ^latest_versionChange your App to NetworkCaptureApp void main() {runApp(NetworkCaptureApp(enable: true,navigatorKey: navigatorKey,child: cons…

vue3+jsx+antd的插槽写法之一

如果在jsx里面直接这样按照官方的写法是会报错的 正确写法是&#xff1a;

【C语言初学者周冲刺计划】2.2用选择法对10个整数从小到大排序

目录 1解题思路&#xff1a; 2代码如下&#xff1a; 3运行结果: 4总结&#xff1a; 1解题思路&#xff1a; 首先利用一维数组和循环语句输入10个整数&#xff0c;然后利用双循环的嵌套进行比较大小&#xff0c;最后输出结果&#xff1b; 2代码如下&#xff1a; #include&…

[已解决]虚拟机之前能正常上网,重启之后无法连接网络问题的解决方法

虚拟机之前网络正常&#xff0c;重启之后却始终连接不上网络。 找了许多方法&#xff0c;终于发现一种便捷有效的方法。 解决方法如下&#xff1a; 1、将网络模式更改为NAT模式., 2、打开终端窗口&#xff0c;输入如下命令。 sudo service network-manager stopsudo rm /var/l…

KaiwuDB 联合信通院数据库应用创新实验室召开数据库技术研讨沙龙

10月26日&#xff0c;KaiwuDB 联合中国通信标准化协会大数据技术标准推进委员会&#xff08;CCSA TC601&#xff09;、信通院数据库应用创新实验室主办的“夯实数据库技术底座&#xff0c;探索智能时代发展新篇章”主题技术沙龙在上海成功举办。 活动邀请到行业专家学者、数据…

关于消防应急疏散指示系统的实际应用案例探讨-安科瑞 蒋静

【摘要】&#xff1a;消防应急照明和疏散指示系统由控制器、集中电源和灯具&#xff08;疏散指示灯具、应急照明灯具&#xff09;等几部分组成。系统采用17寸工业平板电脑、Windonws7系统&#xff0c;可支持联动报警、系统监控、故障报警、自检、备电、记录存储与查询、导光流、…

【Linux】安装配置解决CentosMobaXterm的使用及Linux常用命令以及命令模式

目录 Centos的介绍 centos安装配置&MobaXterm 创建 安装 ​编辑 配置 ​编辑 MobaXterm使用 Linux常用命令&模式 常用命令 vi或vim编辑器 三种模式 命令模式 编辑模式 末行模式 拍照备份 Centos的介绍 CentOS&#xff08;Community Enterprise Op…

利用IP地址定位技术与公安部门合作打击网络犯罪

利用IP地址定位技术联合公安部门打击网络犯罪是一种有力的手段&#xff0c;它可以帮助执法机构追踪和定位犯罪嫌疑人的物理位置。以下是一些关于如何通过IP地址定位技术与公安部门合作打击网络犯罪的关键步骤&#xff1a; 合作和协调&#xff1a; 建立紧密的合作关系&#xff0…

单元测试到底测什么,怎么测?我来告诉你

前言&#xff1a; 以国内互联网的开发节奏&#xff0c;在前端业务项目中全面覆盖单元测试有时显得不太可行&#xff0c;主要是因为以下这些绊脚石&#xff1a; UI 交互复杂&#xff0c;路径难以覆盖全面 工期紧&#xff0c;开发对实践 TDD&#xff0c;BDD 所带来的长远效益没有…

11.与JavaScript深入交流-[js一篇通]

文章目录 1.变量的使用1.1基本用法1.2理解 动态类型 2.基本数据类型2.1number 数字类型2.1.1数字进制表示2.1.2特殊的数字值 2.2string 字符串类型2.2.1基本规则2.2.2转义字符2.2.3求长度2.2.4字符串拼接 2.3boolean 布尔类型2.4undefined 未定义数据类型2.5null 空值类型 3.运…

半导体制造中的液体污染控制-液体粒子计数器应用

半导体制造是一个高度复杂的过程&#xff0c;包括许多步骤和阶段&#xff0c;每个步骤和阶段都有可能受到污染。在这种情况下&#xff0c;污染可能导致产量昂贵的损失和时间浪费。为了应对这些挑战&#xff0c;实时监控系统提供了一个强大的解决方案&#xff0c;可以立即检测并…

注意!注意!注意!新规|Temu平台强制欧代英代,警惕产品被拒!

注意&#xff01;注意&#xff01;注意&#xff01;新规&#xff5c;Temu平台强制欧代英代&#xff0c;警惕产品被拒&#xff01; 欧代&#xff0c;英代信息怎么办理呢 TEMU平台上有售卖产品必需要求产品打上英代,欧代信息! 10月15日&#xff0c;Temu正式实施欧代&英代新规…

反射率检测仪如何检测后视镜

后视镜反射率检测是评估后视镜质量的重要步骤&#xff0c;可以反映后视镜的反射效果是否满足设计要求。一般来说&#xff0c;后视镜的反射率越高&#xff0c;驾驶员观察车后的道路状况就越清晰&#xff0c;从而能够更好地判断与后方车辆的距离和速度差。 后视镜反射率检测的原理…

Unity 多图片(带透明通道)合成

取个巧&#xff0c;利用Camera和Render Texture 多个2d图片组合成型 每个Square都单独设置一个层级 相机设置 RenderTexture设置&#xff0c;然后将RenderTexture放在一个RawImage上 以下是生成图片的代码 using UnityEngine.UI; using System.Collections; using System.…

Python爬虫程序中的504错误:原因、常见场景和解决方法

概述 在编写Python爬虫程序时&#xff0c;我们经常会遇到各种错误和异常。其中&#xff0c;504错误是一种常见的网络错误&#xff0c;它表示网关超时。是指客户端与服务器之间的网关通信过程中&#xff0c;服务器在规定的时间内没有返回响应&#xff0c;导致请求超时。此类错误…

关于FreeTypeFont‘ object has no attribute ‘getsize‘问题的解决方案

引言 这个问题是在训练yolov5_obb项目遇到的&#xff0c;大概率又是环境问题。如下图&#xff1a; 解决方法 出现这个问题是Pillow版本太高了&#xff0c;下载低版本的&#xff1a; pip install Pillow9.5 OK&#xff01;

解决proteus仿真stm32,IIC通讯,IIC DEBUG无法显示从机应答信号的问题(问题情况为在8位数据后应答位显示?)

1、错误现象 错误现象如下&#xff0c;在IIC数据传输8位数据后&#xff0c;IIC DEBUG的应答位无法显示应答位 2、错误原因 我们打开信号传输的示波器&#xff0c;直接去查看IIC从机校验位的数据波形&#xff0c;可以看到从机示波器显示的的波形为半高ACK&#xff0c;那错误原…

第19期 | GPTSecurity周报

GPTSecurity是一个涵盖了前沿学术研究和实践经验分享的社区&#xff0c;集成了生成预训练 Transformer&#xff08;GPT&#xff09;、人工智能生成内容&#xff08;AIGC&#xff09;以及大型语言模型&#xff08;LLM&#xff09;等安全领域应用的知识。在这里&#xff0c;您可以…