Mybatis(搭建,CRUD,方法参数,XML映射文件,动态SQL)【详解】

目录

一.准备基础代码

Mybatis的通用配置

二. 基本CURD操作

1.查询-根据id查询一条

2.查询-查询数量

3.删除

4.新增

获取主键值

5.修改

6.查询-模糊查询

预编译SQL

#{}与${}的区别【面试题】

三. Mybatis的方法参数与结果集

1.SQL里取方法参数的值

2.查询结果集的封装

方案一:SQL语句里给字段起别名

方案二:使用@Results和@Result手动映射

四.Mybatis的XML映射文件

1.介绍

2.用法

3.示例

4.给idea配置代码模板

五、Mybatis的动态SQL【重点】

1. 动态SQL介绍

2. if标签和where标签

3. set标签

4. foreach标签

5. sql标签和include标签


一.准备基础代码

把基础工程《资料\00.基础工程\web09-mybatis-curd》拷贝到不含中文、空格、特殊字符的目录里,然后使用idea直接open打开项目

准备基础环境

  • 依赖pom.xml

<properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.0.33</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

配置文件application.properties

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/db4
spring.datasource.username=root
spring.datasource.password=root

引导类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MybatisCurdApplication {
    public static void main(String[] args) {
        SpringApplication.run(MybatisCurdApplication.class, args);
    }
}

查询所有员工

  • 实体类

import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
public class Emp {
    private Integer id;
    private String username;
    private String password;
    private String name;
    private Integer gender;
    private String image;
    private Integer job;
    private LocalDate entrydate;
    private Integer deptId;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
}

EmpMapper

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmpMapper {
    @Select("select * from emp")
    List<Emp> queryAll();
}

功能测试

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class CurdTest {
    @Autowired
    private EmpMapper empMapper;

    @Test
    public void testQueryAll(){
        List<Emp> emps = empMapper.queryAll();
        emps.forEach(System.out::println);
    }
}

Mybatis的通用配置

Mybatis的日志输出

直接修改application.properties,增加配置:

mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

Mybatis下划线与驼峰命名转换

直接修改application.properties,增加配置:

#开启下划线与驼峰命名的自动映射。
# 如果设置为true,那么数据库里下划线命名风格的字段,会自动映射到Java里驼峰式命名的属性
# 比如:数据库字段是dept_id, Java里的成员变量名是deptId。 Mybatis会认为这两个是对应的
mybatis.configuration.map-underscore-to-camel-case=true

基本CURD操作

使用Mybatis,无论什么功能,都只需要:

  • 在Mapper接口里写一个方法

  • 给方法配置SQL语句:用注解

二. 基本CURD操作

1.查询-根据id查询一条

EmpMapper:实现功能

/**
 * 0. 先准备好SQL语句
 * 1. 方法的参数:根据SQL语句需要的参数来定
 *      这些参数都是给SQL语句使用。SQL语句里需要几个参数,方法上就要加几个形参
 *      SQL语句里要获取参数值,如果方法只有一个参数,写法是:#{随意写},建议写成#{参数名}
 * 2. 方法的返回值:根据我们想要得到什么结果来定
 *      我们期望Mybatis帮我们把查询结果封装成什么对象。
 *      写成Emp,Mybatis就会把查询的结果封装成一个Emp对象
 *      注意:实体类里的属性名,要和表的字段名 一致(相同,或者符合下划与驼峰命名的规则)
 */
@Select("select * from emp where id = #{id}")
Emp queryById(Integer id);

CurdTest:功能测试

@Test
public void testQueryById(){
    Emp emp = empMapper.queryById(1);
    System.out.println("emp = " + emp);
}

2.查询-查询数量

EmpMapper:实现功能

/**
 * 查询数量:SQL语句 select count(*) from emp
 * 方法要参数吗?不需要。因为SQL语句不需要参数
 * 方法返回值是什么类型?能够封装查询结果即可,可使用int、long
 */
@Select("select count(*) from emp")
int queryCount();

CurdTest:功能测试

@Test
public void testQueryCount(){
    int count = empMapper.queryCount();
    System.out.println("count = " + count);
}

3.删除

EmpMapper:实现功能

/**
 * 根据id删除一个员工:delete from emp where id = ?
 * 配置查询语句:@Select
 * 配置新增语句:@Insert
 * 配置修改语句:@Update
 * 配置删除语句:@Delete
 */
@Delete("delete from emp where id = #{id}")
void deleteById(Integer id);

CurdTest:功能测试

@Test
public void testDeleteById(){
    empMapper.deleteById(17);
}

4.新增

EmpMapper:实现功能

/**
 * 插入一条员工数据:
 * INSERT INTO emp (id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time)
 * VALUES (16, 'songyuanqiao', '123456', '宋远桥', 1, '16.jpg', 2, '2010-01-01', 2, '2023-08-19 10:39:37', '2023-08-19 10:39:37');
 *
 * 方法的参数:
 *      如果SQL语句需要的参数过多,方法的形参可以使用一个实体类
 *      SQL语句里使用 #{JavaBean的属性名}
 *      注意:
 *          不要写成 '#{JavaBean属性名}'
 *          #{属性名}的顺序,必须与前边的字段顺序是一致对应的
 */
@Insert("INSERT INTO emp (username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time)\n" +
        "VALUES (#{username}, #{password}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
void insert(Emp emp);

CurdTest:功能测试

@Test
public void testInsert(){
    Emp emp = new Emp();
    emp.setUsername("tom");
    emp.setPassword("123");
    emp.setName("汤姆");
    emp.setGender(1);
    emp.setCreateTime(LocalDateTime.now());
    emp.setUpdateTime(LocalDateTime.now());
    empMapper.insert(emp);
}
获取主键值

如果执行insert时,需要获取数据的主键值,我们可以做:

  • 在Mapper接口里插入的方法上,再增加注解:@Options(useGeneratedKeys=true, keyProperty="JavaBean里的属性名")

/**
     * 插入一条员工数据:
     * INSERT INTO emp (id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time)
     * VALUES (16, 'songyuanqiao', '123456', '宋远桥', 1, '16.jpg', 2, '2010-01-01', 2, '2023-08-19 10:39:37', '2023-08-19 10:39:37');
     *
     * 方法的参数:
     *      如果SQL语句需要的参数过多,方法的形参可以使用一个实体类
     *      SQL语句里使用 #{JavaBean的属性名}
     *      注意:
     *          不要写成 '#{JavaBean属性名}'
     *          #{属性名}的顺序,必须与前边的字段顺序是一致对应的
     * 如果插入数据之后,需要获取数据的主键值:@Options
     *      useGeneratedKeys:利用数据库的主键自增得到主键值
     *      keyProperty:把得到的主键值,存储到参数实体类对象的哪个属性上
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("INSERT INTO emp (username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time)\n" +
            "VALUES (#{username}, #{password}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
    void insert(Emp emp);

5.修改

EmpMapper:实现功能

/**
 * 修改id为19的数据:
 * UPDATE emp SET username = 'jerry', password = '123', name = '杰瑞', gender = 1, image = null, job = null, entrydate = null, dept_id = null, create_time = '2023-08-19 14:54:29', update_time = '2023-08-19 14:54:29' WHERE id = 19;
 */
@Update("UPDATE emp SET username = #{username}, password = #{password}, name = #{name}, gender = #{gender}, image = #{image}, job = #{job}, " +
        "entrydate = #{entrydate}, dept_id = #{deptId}, create_time = #{createTime}, update_time = #{updateTime} WHERE id = #{id}")
void updateById(Emp emp);

CurdTest:功能测试

@Test
public void testUpdateById(){
    Emp emp = empMapper.queryById(19);

    emp.setUsername("robin li");
    emp.setGender(2);

    empMapper.updateById(emp);
}

6.查询-模糊查询

EmpMapper:实现功能

/**
     * 模糊查询:查询姓名里包含“张”的员工列表
     * select * from emp where name like '%张%';
     * SQL语句里拼接字符串函数:concat(字符串1, 字符串2, 字符串3,....)
     */
    @Select("select * from emp where name like concat('%', #{name}, '%')")
    List<Emp> queryByName1(String name);

    @Select("select * from emp where name like '%${name}%'")
    List<Emp> queryByName2(String name);

CurdTest:功能测试

  @Test
    public void testQueryByName1(){
        List<Emp> list = empMapper.queryByName1("张");
        list.forEach(System.out::println);
    }

    @Test
    public void testQueryByName2(){
        List<Emp> list = empMapper.queryByName2("张");
        list.forEach(System.out::println);
    }
预编译SQL

预编译:不是Mybatis的概念,而是JDBC的概念。

  • 不使用预编译:RDBMS先编译SQL(解析SQL语句,确定SQL的执行方案);再执行SQL语句,得到结果

  • 使用了预编译:先把SQL语句进行解析确定执行方案;然后设置参数值执行SQL

好处1-预编译执行SQL性能更高

好处2-可以防止SQL注入漏洞

#{}${}的区别【面试题】
  • #{}:底层使用的是预编译方式。

    更安全,因为可以防止SQL注入漏洞

    执行SQL的性能更高

  • ${}:没有使用预编译,是直接拼接SQL字符串

    不安全,可能存在SQL注入漏洞

    执行SQL的性能不如预编译

三. Mybatis的方法参数与结果集

1.SQL里取方法参数的值

如果方法只有一个参数:

  • 如果参数是简单值(8种基本数据类型及包装类、String),SQL语句里取参数值是:#{参数名}

  • 如果参数是JavaBean对象,SQL语句里取JavaBean的属性值:#{属性名}

如果方法有多个参数,SQL语句里取参数值:

  • 从SpringBoot2版本开始:#{形参名}

  • 在SpringBoot2以前版本:【了解】

    首先,给方法参数起名称,添加注解:@Param("名称")

    然后,在SQL语句里使用:#{名称} 获取对应参数值

/**
     * 需求:根据姓名、性别、入职时间范围 搜索员工信息
     * SQL:select * from emp where name like ? and gender = ? and entrydate between ? and ?
     * 如果方法有多个参数,SQL语句里取参数值:#{参数名称}。从SpringBoot2开始提供的功能
     */
@Select("select * from emp where name like concat('%',#{name}, '%') and gender = #{gender} and entrydate between #{begin} and #{end}")
List<Emp> queryEmpList(String name,
                       Integer gender,
                       LocalDate begin,
                       LocalDate end);

@Select("select * from emp where name like concat('%',#{a}, '%') and gender = #{b} " +
        "and entrydate between #{c} and #{d}")
List<Emp> queryEmpList2(@Param("a") String name,
                        @Param("b") Integer gender,
                        @Param("c") LocalDate begin,
                        @Param("d") LocalDate end);

2.查询结果集的封装

Mybatis会自动帮我们把查询的结果集封装成实体类对象,前提条件是:

  • 要么 JavaBean的属性名,和 表的字段名完全相同。

    比如:字段名是gender,Emp类里的属性名也叫gender

  • 要么 JavaBean的属性名,和 表的字段名按照 下划线与驼峰映射 是一致的。

    比如:字段名是dept_id,Emp类里属性名是deptId

    前提:开启下划线与驼峰的命名转换,修改application.properties配置文件,添加参数

    mybatis.configuration.map-underscore-to-camel-case=true

如果JavaBean的属性名和字段名完全不匹配,就需要处理这种情况

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Employee {
    private Integer id;
    /*对应的字段名是username*/
    private String uname;
    /*对应的字段名是password*/
    private String pword;
    private String name;
    private Integer gender;
    private String image;
    private Integer job;
    private LocalDate entrydate;
    private Integer deptId;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
}
方案一:SQL语句里给字段起别名
/**
 * JavaBean属性名 与  表字段名 完全不匹配:
 * SQL语句里给字段起别名,别名和JavaBean属性名相同
 */
@Select("select id, username as uname, password as pword,name,gender,image,job," +
        "entrydate,dept_id,create_time, update_time from emp")
List<Employee> queryEmployeeList2();
方案二:使用@Results@Result手动映射

只需要把不同的字段配置一下,如果字段和属性名匹配,就不需要做配置

/**
 * JavaBean属性名 与  表字段名 完全不匹配:
 * 我们使用@Results和@Result注解,手动设置一下,哪个字段对应哪个属性
 *      注解1:@Results,用于配置当前查询里所有字段的映射关系
 *      注解2:@Result,用于配置某一个字段与属性的对应关系
 *          property:写的是JavaBean的属性名
 *          column:写的是表里的字段名
 */
@Select("select * from emp")
@Results({
        @Result(property = "uname", column = "username"),
        @Result(property = "pword", column = "password")
})
List<Employee> queryEmployeeList3();

四.Mybatis的XML映射文件

1.介绍

Mybatis的SQL语句,可以使用注解直接配置到Mapper接口里的方法上,也可以定义到XML文件里

  • 如果SQL语句写到接口里的方法上:注解方式,适合于简单SQL或者固定不变的SQL

  • 如果SQL语句写到XML文件里:xml方式,更适合于复杂SQL或者动态变化的SQL

注意:XML方式和注解方式可以同时使用,但是要注意

  • 一个方法的SQL语句,要么用注解方式配置,要么用XML方式配置,不能重复配置

2.用法

XML文件的要求:

  1. XML文件的位置:要和Mapper同一包下,按照maven规范,要放到resources里边的同名文件夹下

  2. XML文件的名称:要和Mapper接口的名称相同

XML内容的要求:

  • 根标签<mapper namespace="Mapper接口的全限定类名">:表示当前XML是给哪个Mapper接口配置语句的

  • 在mapper标签里边,配置SQL语句:

    • select标签:配置select语句,SQL语句写到标签里边。需要配置id属性和resultType属性

      • id属性:配置方法名。表示当前SQL语句是给哪个方法配置的

      • resultType属性:告诉Mybatis要把查询结果中的每一行数据,封装成什么对象

    • insert标签:配置insert语句,SQL语句写到标签里边。需要配置id属性

      • id属性:配置方法名。表示当前SQL语句是给哪个方法配置的

    • update标签:配置update语句,SQL语句写到标签里边。需要配置id属性

      • id属性:配置方法名。表示当前SQL语句是给哪个方法配置的

    • delete标签:配置delete语句,SQL语句写到标签里边。需要配置id属性

      • id属性:配置方法名。表示当前SQL语句是给哪个方法配置的

3.示例

Mapper接口

/**
 * 使用XML方式配置SQL语句
 * XML文件的位置:Mapper接口在什么包,XML文件就必须在同包下。
 *      在resources目录下右键,创建Directory文件夹,以/为分隔符,千万不要以.为分隔符。
 *      比如:com/itheima/mapper
 * XML文件的名称:Mapper接口叫什么名字,XML文件也叫什么名字
 *
 */
List<Emp> queryEmpListXml(String name,Integer gender,LocalDate begin,LocalDate end);

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">
<!--
mapper标签:根标签
    namespace:要写Mapper接口的全限定类名。表示当前xml文件,是给哪个Mapper接口配置的
mapper的子标签:
    select标签:配置select语句,SQL语句写到标签里边
    insert标签:配置insert语句,SQL语句写到标签里边
    update标签:配置update语句,SQL语句写到标签里边
    delete标签:配置delete语句,SQL语句写到标签里边
    以上标签都有的属性:
        id:写方法名。表示当前语句是给哪个方法配置的
        resultType:select标签专用的属性
            用于告诉Mybatis,SQL查询语句的结果,要封装成什么对象
            写JavaBean的全限定类名,不需要写List、Set等等
-->
<mapper namespace="com.itheima.mapper.EmpMapper">
    <select id="queryEmpListXml" resultType="com.itheima.pojo.Emp">
        select * from emp
         where name like concat('%',#{name}, '%')
           and gender = #{gender}
           and entrydate between #{begin} and #{end}
    </select>
</mapper>

功能测试

@Test
public void testQueryEmpListXml(){
    LocalDate begin = LocalDate.of(2010, 1, 1);
    LocalDate end = LocalDate.of(2015, 12, 31);
    List<Emp> emps = empMapper.queryEmpListXml("张", 1, begin, end);
    for (Emp emp : emps) {
        System.out.println("emp = " + emp);
    }
}

4.给idea配置代码模板

配置方式:File | Settings | Editor | Live Templates

<?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">
<mapper namespace="$namespace$">
    $END$
</mapper>

五、Mybatis的动态SQL【重点】

1. 动态SQL介绍

当进行多条件搜索时,搜索条件通常是不确定的,导致SQL语句的条件也是不确定的:需要根据条件,来确定要拼接哪些查询条件。这样的SQL语句,就是所谓的动态SQL

Mybatis提供了一些xml的标签,用于实现动态SQL语句:

  • if标签:用于判断

    • where标签:用于代替where关键字

    • set标签:用于代替set关键字

  • foreach标签:用于循环遍历

  • sql标签和include标签:用于抽取重用sql片段

2. if标签和where标签

if标签:用于进行判断。如果判断为true,标签里的sql才会生效

<if test="判断条件">
    如果判断为true,这里的内容才会生效
</if>

where标签:用于代替where关键字,它可以帮我们处理多余的and和or,还有处理我们的空集合,不是null

演示:

Mapper接口

     /**
     * 动态SQL:根据条件查询员工。根据name和gender动态查询
     */
    List<Emp> searchEmp1(String name, Integer gender);

XML映射

<!--
    if标签:用于判断
      语法:
        <if test="判断条件表达式">
            如果判断为true,这里的内容将会生效
        </if>
      判断条件表达式:其实使用的是OGNL的表达式语法:
        名称,取对应参数的值。#{}是怎么取参数值的,这里也怎么取参数值
        判断运算:>, <, >=, <=, ==, !=
        逻辑运算:&&, ||, ! 或者 and or not
        调用参数的属性或者方法
    where标签:用于代替where关键字
        还会帮我们处理掉SQL语句里多余的and关键字
        使用了where标签之后,建议给所有的条件前边都加上and
    -->
    <select id="searchEmp1" resultType="com.itheima.pojo.Emp">
        select * from emp
        <where>
            <!-- 如果参数name值非空 并且不是空串,就添加上name的条件-->
            <if test="name!=null and name.length()>0">
                and name like concat('%',#{name}, '%')
            </if>
            <!-- 如果参数gender非空,就添加上gender的条件 -->
            <if test="gender!=null">
                and gender = #{gender}
            </if>
        </where>
    </select>

3. set标签

set标签:用于代替update语句里的set关键字,可以帮我们处理多余的逗号

Mapper

void update(Emp emp);

XML映射

<!--
set标签:用于代替update语句里的set关键字
    可以帮我们处理掉多余的,逗号
    把所有要修改的字段sql片段,都写到set标签里边
-->
<update id="update">
    update emp
    <set>
        <if test="username!=null and username.length()>0">username=#{username},</if>
        <if test="password!=null and password.length()>0">password= #{password},</if>
        <if test="name!=null and name.length()>0">name= #{name},</if>
        <if test="gender!=null">gender= #{gender},</if>
        <if test="image!=null and image.length()>0">image= #{image},</if>
        <if test="entrydate!=null">entrydate= #{entrydate},</if>
        <if test="deptId!=null">dept_id= #{deptId},</if>
        <if test="updateTime!=null">update_time= #{updateTime}</if>
    </set>
    where id = #{id}
</update>

4. foreach标签

foreach标签:用于循环遍历,比如我们的批量删除,多个数据

Mapper

void batchDelete(List<Integer> ids);

XML映射

<!--
foreach标签:
    collection:被循环的集合或数组
    item:定义一个变量名,通过这个变量名可以获取集合或数组里的每个值
    separator:拼接每个值时候,使用的分隔符
    open:拼接结果的前缀部分
    close:拼接结果的后缀部分
假如:ids值是 1,2,3
循环拼接的结果是:
    delete from emp where id in (1,2,3)
    (1,2,3)
for(Integer id:ids){}
-->
<delete id="batchDelete">
    delete from emp where
    <foreach collection="ids" open="id in(" item="id" separator="," close=")">
        #{id}
    </foreach>
</delete>

5. sql标签和include标签

sql标签:定义一个sql片段

include标签:引用一个sql片段

用法 :如果多条SQL语句里,有某些片段是完全相同的,可以使用sql标签抽取出去,需要使用时用include引用即可

<!--定义一个SQL片段-->
<sql id="selectEmp">select * from emp</sql>

<!-- 引用一个SQL片段 -->
<select id="queryEmpListXml" resultType="com.itheima.pojo.Emp">
    <!--利用include标签,引用:select * from emp-->
    <include refid="selectEmp"></include>
    where name like concat('%',#{name}, '%')
    and gender = #{gender}
    and entrydate between #{begin} and #{end}
</select>

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

mac解决brew install报错“fatal: not in a git directory“

在macbook上使用brew安装软件时&#xff0c;可能会遇到问题&#xff0c;报错如下&#xff1a; fatal: not in a git directory Error: Command failed with exit 128: git 使用brew -v&#xff0c;仔细看&#xff0c;可以发现有两个fatal(致命错误)提示: 解决方案&#xff1a;…

下载chromedrive,使用自动化

1、先看一下自己浏览器的版本 2、访问 https://googlechromelabs.github.io/chrome-for-testing/

Nginx、LVS、HAProxy工作原理和负载均衡架构

当前大多数的互联网系统都使用了服务器集群技术&#xff0c;集群是将相同服务部署在多台服务器上构成一个集群整体对外提供服务&#xff0c;这些集群可以是 Web 应用服务器集群&#xff0c;也可以是数据库服务器集群&#xff0c;还可以是分布式缓存服务器集群等等。 在实际应用…

ChatGPT提问技巧——对抗性提示

ChatGPT提问技巧——对抗性提示 对抗性提示是一种允许模型生成能够抵御某些类型的攻击或偏差的文本的技术。这种技术可用于训练更健壮、更能抵御某些类型的攻击或偏差的模型。 要在 ChatGPT 中使用对抗性提示&#xff0c;应为模型提供一个提示&#xff0c;该提示的设计应使模…

微信小程序之tabBar

1、tabBar 如果小程序是一个多 tab 应用&#xff08;客户端窗口的底部或顶部有 tab 栏可以切换页面&#xff09;&#xff0c;可以通过 tabBar 配置项指定 tab 栏的表现&#xff0c;以及 tab 切换时显示的对应页面。 属性类型必填默认值描述colorHexColor是tab 上的文字默认颜色…

Web框架开发-Django的视图层

一、视图函数 一个视图函数,简称视图,是一个简单的Python 函数,它接受Web请求并且返回Web响应。响应可以是一张网页的HTML内容,一个重定向,一个404错误,一个XML文档,或者一张图片. . . 是任何东西都可以。无论视图本身包含什么逻辑,都要返回响应。代码写在哪里也无所谓…

【QT】TCP简易聊天框

我们首先复习一下TCP通信的流程 基于linuxTCP客户端和服务器 QT下的TCP处理流程 服务器先启动&#xff08;处于监听状态&#xff09; 各函数的意义和使用 QTcpServer Class *QTcpServer*类提供了一个基于TCP的服务器。这个类可以接受传入的TCP连接。您可以指定端口或让QTcpS…

解决无法登录到 ArcGIS Server Administrator

目录 问题复现原因分析解决办法 问题复现 今天在访问arcgisserver后台准备设置arcgis api for js请求路径时&#xff0c;登录之后出现500错误。Services Directoryhttp://xxx.xxx.xxx.xxx:6080/arcgis/admin/system/handlers/rest/servicesdirectory 原因分析 我实在两台虚拟机…

信号与系统学习笔记——信号的分类

目录 一、确定与随机 二、连续与离散 三、周期与非周期 判断是否为周期函数 离散信号的周期 结论 四、能量与功率 定义 结论 五、因果与反因果 六、阶跃函数 定义 性质 七、冲激函数 定义 重要关系 作用 一、确定与随机 确定信号&#xff1a;可以确定时间函数…

提升运营效率,探索运营中台架构的力量

随着数字化转型的加速推进&#xff0c;企业需要更高效地管理和运营各项业务&#xff0c;而运营中台架构作为一种新型的业务架构设计理念&#xff0c;正在逐渐受到关注和应用。本篇博客将深入探讨运营中台架构的概念、优势和实践&#xff0c;帮助企业了解如何通过构建运营中台实…

CVPR2023 | 3D Data Augmentation for Driving Scenes on Camera

3D Data Augmentation for Driving Scenes on Camera 摄像机驾驶场景的 3D 数据增强 摘要翻译 驾驶场景极其多样和复杂&#xff0c;仅靠人力不可能收集到所有情况。虽然数据扩增是丰富训练数据的有效技术&#xff0c;但自动驾驶应用中现有的摄像头数据扩增方法仅限于二维图像…

[蓝桥杯]-最大的通过数-CPP-二分查找、前缀和

目录 一、题目描述&#xff1a; 二、整体思路&#xff1a; 三、代码&#xff1a; 一、题目描述&#xff1a; 二、整体思路&#xff1a; 首先要知道不是他们同时选择序号一样的关卡通关&#xff0c;而是两人同时进行两个入口闯关。就是说两条通道存在相同关卡编号的的关卡被通…

PlantUML Integration 编写短信服务类图

PlantUML Integration 写一个类图&#xff0c;主要功能为 1、编写一个serviceSms短信服务类&#xff1b; 2、需要用到短信的地方统一调用基建层的服务即可&#xff1b; 3、可以随意切换、增加短信厂商&#xff0c;不需要更改场景代码&#xff0c;只需要更改application.yml 里面…

SQLiteC/C++接口详细介绍之sqlite3类(七)

上一篇&#xff1a;SQLiteC/C接口详细介绍之sqlite3类&#xff08;六&#xff09; 下一篇&#xff1a; SQLiteC/C接口详细介绍之sqlite3类&#xff08;八&#xff09;&#xff08;未发表&#xff09; 22.sqlite3_create_collation、sqlite3_create_collation16和sqlite3_creat…

JavaEE--小Demo

目录 下载包 配置 修改文件 pom.xml application.properties 创建文件 HelloApi.java GreetingController.java Greeting.java DemoApplication.java 运行包 运行命令 mvn package cd target dir java -jar demo-0.0.1-SNAPSHOT.jar 浏览器测试结果 下载包 …

网络安全专题第一篇:网络安全的来源

目录 一.网络安全的由来。 二.网络安全漏洞在哪里 三.网络安全规范操作 1.从业务入手 2.从安全体系入手 3.从管理入手 四.可能遇到的网络攻击 1.DDOS 2.勒索攻击 3.单包攻击 4.员工删库跑路 5.熊猫烧香 五.应对方法 1.清洗 2.提高服务器的承受能力 3.防火墙 4…

证券公司如何应对大数据调度系统的高负载挑战

​在金融行业&#xff0c;数据处理和任务调度是日常运营的重要组成部分。随着业务量的激增&#xff0c;日益增长的任务量和复杂的资源管理需求&#xff0c;要求该系统不仅要稳如磐石&#xff0c;还需灵活高效。 本文将探讨某证券公司在应对这些挑战时所采用的策略&#xff0c;并…

tomcat的webapp文件中发布web应用

一、Web服务器 1.什么是Web 概述&#xff1a; web(World Wide Web)即全球广域网&#xff0c;也称为万维网&#xff0c;它是一种基于超文本和HTTP的、全球性的、动态交百的、跨平台的分布式图形信息系统。是建立在internet上的一种网络服务&#xff0c;为浏览者在Intern…

笔记80:在 Ubuntu 中安装显卡驱动

一、关于显卡的两个基本概念 -- 显卡驱动 / 显卡BIOS &#xff08;1&#xff09;什么是BIOS BIOS的作用&#xff1a;BIOS是电脑上电开机时加载进内存的第一个程序&#xff0c;CPU会执行他进行系统自检&#xff0c;然后通过其中的指令加载操作系统&#xff1b;例如主板BIOS&am…

react 项目如何暴露 webpack配置文件

首先创建一个项目&#xff1a; // 全局安装 create-react-app 脚手架 npm install create-react-app -g// 创建项目 create-react-app demo 创建完成后&#xff0c;进到项目根目录&#xff0c;执行以下命令&#xff1a; npm run eject 出现以下命令&#xff1a; 选择yes即可…
最新文章