详解Mybatis之动态sql问题

news2024/10/7 4:33:45

编译软件:IntelliJ IDEA 2019.2.4 x64
操作系统:win10 x64 位 家庭版
Maven版本:apache-maven-3.6.3
Mybatis版本:3.5.6

文章目录

  • 一. 在sql映射文件中如何写注释?
  • 二. 什么是动态sql?
  • 三. 动态sql常用标签有哪些?
    • 3.1 if标签
    • 3.2 where标签
    • 3.3 trim标签
    • 3.4 set标签
    • 3.5 choose标签
    • 3.6 foreach标签
    • 3.7 sql标签


在这里插入图片描述


一. 在sql映射文件中如何写注释?

关于XXXMapper接口对应的映射文件里SQL中的注释

👉语法

①方式一

//mysql的注释	
-- 1=1

②方式二

//xml的注释
<!-- 1=1  -->

使用这两种注释方式各有什么不同呢?

👉请看如下测试

代码示例如下:

①使用第一种注释

<!--  根据查询条件查找对应的员工信息(条件不确定) 即采用动态的sql去查询  -->
    <select id="selectEmpByopr" resultType="employee">
        SELECT
            `id`,
            `last_name`,
            `email`,
            `salary`,
            `dept_id`
        FROM
            `tbl_employee`
        WHERE
            -- 1=1
            <if test="id !=null">
               and id=#{id}
            </if>
            <if test="lastName != null">
               and last_name=#{lastName}
            </if>
            <if test="email != null">
                and email=#{email}
            </if>
            <if test="salary != null">
                and last_name=#{salary}
            </if>
    </select>

在这里插入图片描述

②使用第二种注释

<!--  根据查询条件查找对应的员工信息(条件不确定) 即采用动态的sql去查询  -->
    <select id="selectEmpByopr" resultType="employee">
        SELECT
            `id`,
            `last_name`,
            `email`,
            `salary`,
            `dept_id`
        FROM
            `tbl_employee`
        WHERE
<!--             1=1-->
            <if test="id !=null">
               and id=#{id}
            </if>
            <if test="lastName != null">
               and last_name=#{lastName}
            </if>
            <if test="email != null">
                and email=#{email}
            </if>
            <if test="salary != null">
                and last_name=#{salary}
            </if>
    </select>

在这里插入图片描述

💡结论

通过以上二者运行测试结果对比,所以在需要使用注释时,推荐使用第二种注释方式


二. 什么是动态sql?

👉定义

  1. 动态sql指的是sql语句可动态化
  2. Mybatis的动态sql中支持OGNL表达式语言,OGNL(Object Graph Navigation
    Language)是对象图导航语言

❗注意

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1XJyWZlo-1690458988415)(C:\Users\king\AppData\Roaming\Typora\typora-user-images\1682994155884.png)]

👉用法案例

不指定查询条件,查询对应员工信息,即当你传入id,程序就根据id去查,传入什么条件,就去根据此条件去查(多个条件不确定)

代码示例如下

①在EmployeeMapper接口下书写相应的方法

//动态的sql方式,即不指定查询条件,查询对应员工信息
public List<Employee> selectEmpByopr(Employee employee);

②在EmployeeMapper接口相应的sql

<!--  根据查询条件查找对应的员工信息(条件不确定) 即采用动态的sql去查询  -->
    <select id="selectEmpByopr" resultType="employee">
        SELECT
            `id`,
            `last_name`,
            `email`,
            `salary`,
            `dept_id`
        FROM
            `tbl_employee`
        WHERE
            <if test="id !=null">
               and id=#{id}
            </if>
            <if test="lastName != null">
               and last_name=#{lastName}
            </if>
            <if test="email != null">
                and email=#{email}
            </if>
            <if test="salary != null">
                and last_name=#{salary}
            </if>
    </select>

③测试

@Test
public void test01(){
    try {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //通过SqlSessionFactory对象调用openSession();
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //获取EmployeeMapper的代理对象
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

        //动态参数(无参会报错,没有第一个参数也会报错)
        Employee employee=new Employee();

        List<Employee> employees = employeeMapper.selectEmpByopr(employee);

        //遍历集合employees
        for (Employee employee1 : employees) {
            System.out.println(employee1);
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

}

❓但是这样会出现一个问题,即不传参会报错,没有第一个参数也会报错

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-H8BuZQxZ-1690458988415)(C:\Users\king\AppData\Roaming\Typora\typora-user-images\1682997746252.png)]

💡原因分析

不传参时,mybatis解析sql的过程中走到where的部分,无参,会进入where里,但不会执行里面的任意if判断,where后没有任何赋值表达式,此sql为非法sql,故报错。没有第一个参数时也会报类似的问题。

👉解决方案

①在第二步中的where里加上 1=1,作为条件恒等式(老版本的解决措施)

在这里插入图片描述

②使用where标签

代码示例如下:

<!--  根据查询条件查找对应的员工信息(条件不确定) 即采用动态的sql去查询  -->
    <select id="selectEmpByopr" resultType="employee">
        SELECT
            `id`,
            `last_name`,
            `email`,
            `salary`,
            `dept_id`
        FROM
            `tbl_employee`
         <where>
            <if test="id !=null">
               and id=#{id}
            </if>
            <if test="lastName != null">
               and last_name=#{lastName}
            </if>
            <if test="email != null">
                and email=#{email}
            </if>
            <if test="salary != null">
                and last_name=#{salary}
            </if>
         </where>
    </select>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GPGt0JYh-1690458988416)(C:\Users\king\AppData\Roaming\Typora\typora-user-images\1682999094227.png)]


三. 动态sql常用标签有哪些?

3.1 if标签

👉功能

用于完成简单的判断

示例代码如下:

 //如果属性id不为空,就将传入的参数id赋值给sql中的字段id
 <if test="id !=null">
      id=#{id}
 </if>

3.2 where标签

👉功能:

用于解决where关键字及where后第一个and或or的问题

示例代码如下:

<where>
   <if test="id !=null">
      and id=#{id}
   </if>
   <if test="lastName != null">
      and last_name=#{lastName}
   </if>
   <if test="email != null">
       and email=#{email}
   </if>
   <if test="salary != null">
       and last_name=#{salary}
   </if>
</where>

3.3 trim标签

👉功能

可以在条件判断完的SQL语句前后添加或者去掉指定的字符

👉属性

  • prefix添加前缀
  • prefixOverrides去掉前缀
  • suffix添加后缀
  • suffixOverrides去掉后缀

👉用法案例

不指定查询条件,查询对应员工信息(trim标签优化版)

代码示例如下:

①在EmployeeMapper接口定义相应的方法

//不指定查询条件,查询对应员工信息
public List<Employee> selectEmpByEmpTrim(Employee employee);

②在EmployeeMapper接口对应的映射文件中定义相应的sql

<!--  根据查询条件查找对应的员工信息(条件不确定) 动态的sql(trim标签优化版)  -->
<select id="selectEmpByEmpTrim" resultType="employee">
    SELECT
        `id`,
        `last_name`,
        `email`,
        `salary`,
        `dept_id`
    FROM
        `tbl_employee`
    <!--  给下面的sql语句加上前缀 where,去掉后缀and      -->
    <trim prefix="where" suffixOverrides="and">
        <if test="id !=null">
            id=#{id} and
        </if>
        <if test="lastName != null">
           last_name=#{lastName}  and
        </if>
        <if test="email != null">
            email=#{email}  and
        </if>
        <if test="salary != null">
            salary=#{salary}   and
        </if>
    </trim>
</select>

③测试

@Test
    public void test02(){
        try {
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

            //通过SqlSessionFactory对象调用openSession();
            SqlSession sqlSession = sqlSessionFactory.openSession();

            //获取EmployeeMapper的代理对象
            EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

            //动态参数
            Employee employee=new Employee();
          /*  employee.setLastName("jack");
            employee.setSalary(5600.0);
*/
            List<Employee> employees = employeeMapper.selectEmpByEmpTrim(employee);

            //遍历集合employees
            for (Employee employee1 : employees) {
                System.out.println(employee1);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

在这里插入图片描述

在这里插入图片描述

trim标签运行流程详解

在这里插入图片描述

3.4 set标签

👉功能

主要用于解决set关键字及多出一个【,】问题

👉用法案例

修改员工的信息

代码示例如下:

①在EmployeeMapper接口中定义修改员工的信息的方法

//修改员工的信息
public void updateEmp(Employee employee);

②在EmployeeMapper接口对应的映射文件中书写相应的sql

问题版(会出现多一个【,】问题

<update id="updateEmp">
    update
        tbl_employee
    set
        <if test="lastName != null">
            last_name=#{lastName}  ,
        </if>
        <if test="email != null">
            email=#{email}  ,
        </if>
        <if test="salary != null">
            salary=#{salary} ,
        </if>
    where
        id=#{id}
</update> 

set标签解决问题版

<update id="updateEmp">
    update
        tbl_employee
    <set>
        <if test="lastName != null">
            last_name=#{lastName}  ,
        </if>
        <if test="email != null">
            email=#{email}  ,
        </if>
        <if test="salary != null">
            salary=#{salary} ,
        </if>
    </set>
    where
        id=#{id}
</update>

③测试

@Test
public void test03(){
    try {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //通过SqlSessionFactory对象调用openSession();
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //获取EmployeeMapper的代理对象
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

        //动态参数
        Employee employee=new Employee();
        employee.setId(1);
        employee.setLastName("tom");
        employee.setSalary(16800.0);
        employeeMapper.updateEmp(employee);

xml

    } catch (IOException e) {
        e.printStackTrace();
    }
}

使用问题版的sql进行测试

在这里插入图片描述

使用set标签解决问题版的sql进行测试

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tYwOzFHZ-1690458988420)(C:\Users\king\AppData\Roaming\Typora\typora-user-images\1683014982189.png)]

3.5 choose标签

👉功能

类似java中if-else【switch-case】结构

👉应用场景

应用于单个条件不确定的业务场景

👉用法案例

不指定查询条件,查询对应的员工信息(单个条件不确定的)

代码示例如下:

①在EmployeeMapper接口书写相应的方法

//不指定查询条件,查询对应员工信息(单个条件不确定的)
public List<Employee> selectEmpByOneOpr(int empId);

②在EmployeeMapper接口对应的映射文件中书写相应的sql

<!--  根据查询条件查找对应的员工信息(条件不确定) 动态的sql(trim标签优化版)  -->
<select id="selectEmpByOneOpr" resultType="employee">
    SELECT
        `id`,
        `last_name`,
        `email`,
        `salary`,
        `dept_id`
    FROM
        `tbl_employee`

    <where>
        <choose>
            <when test="id !=null">
                id=#{id}
            </when>
            <when test="lastName != null">
                last_name=#{lastName}
            </when>
            <when test="email != null">
                email=#{email}
            </when>
            <otherwise>
                salary=#{salary}
            </otherwise>
        </choose>
    </where>
    
</select>

③测试

@Test
public void test04(){
    try {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //通过SqlSessionFactory对象调用openSession();
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //获取EmployeeMapper的代理对象
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

        List<Employee> employees = employeeMapper.selectEmpByOneOpr(1);
        System.out.println(employees);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-e7bR0Hli-1690458988421)(C:\Users\king\AppData\Roaming\Typora\typora-user-images\1683016763843.png)]

3.6 foreach标签

👉功能

类似java中for循环

👉标签属性

  • collection要迭代的集合
  • item当前从集合中迭代出的元素
  • separator元素与元素之间的分隔符
  • open开始字符
  • close结束字符

👉应用场景

🚩 ①遍历迭代

用法案例

通过多个id获取员工的信息 【EmpIds:员工id的集合】

代码示例如下:

a.在EmployeeMapper接口定义相应的方法

/**
 * 通过多个id获取员工的信息 【EmpIds:员工id的集合】
 * @param EmpIds
 * @return
 */
public List<Employee> selectEmpByIds(@Param("ids") List<Integer> EmpIds);

b.在EmployeeMapper接口对应的映射文件中定义相应的sql

 <select id="selectEmpByIds" resultType="employee">
        SELECT
            `id`,
            `last_name`,
            `email`,
            `salary`,
            `dept_id`
        FROM
            `tbl_employee`
        <where>
            `id` in
            (
            <foreach collection="ids" item="id" separator=",">
                #{id}
            </foreach>
            )
        </where>
    </select>

c.测试

@Test
public void test04(){
    try {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //通过SqlSessionFactory对象调用openSession();
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //获取EmployeeMapper的代理对象
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

        List<Employee> employees = employeeMapper.selectEmpByOneOpr(1);
        System.out.println(employees);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

在这里插入图片描述

🚩②批量导入

用法案例

批量添加员工数据

代码示例如下:

a.在EmployeeMapper接口定义相应的方法

  //批量添加员工数据
    public void batchInsertEmp(@Param("emps") List<Employee> employees);

b.在EmployeeMapper接口对应的映射文件中定义相应的sql

// 批量添加员工数据,使用insert标签书写相应的sql
<insert id="batchInsertEmp">
    insert into
        tbl_employee(last_name,email,salary)
    values
        <foreach collection="emps" item="emp" separator=",">
            (#{emp.lastName},#{emp.email},#{emp.salary})
        </foreach>

</insert>

c.测试

@Test
public void test06(){
    try {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //通过SqlSessionFactory对象调用openSession();
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //获取EmployeeMapper的代理对象
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);

        //定义要添加的员工集合
       List<Employee> list=new ArrayList<>();
       list.add(new Employee("zhangsan","sdhjsd@qq.com",6700.0));
       list.add(new Employee("wangwu","dddhjsd@123.com",9700.0));

        employeeMapper.batchInsertEmp(list);
        sqlSession.commit();


    } catch (IOException e) {
        e.printStackTrace();
    }
}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TE2Af2O2-1690458988422)(C:\Users\king\AppData\Roaming\Typora\typora-user-images\1683030856816.png)]

在这里插入图片描述

3.7 sql标签

👉功能

提取可重用SQL片段

❗注意

该SQL片段可以是一个完整的sql语句,也可以是一个sql语句中的某个片段)

👉用法案例

使用sql标签对3.6小节中的应用场景1的案例里映射文件里的的”select xxx,xxxx,xxx from
xxxx”部分提取出来,作为一个可重用的sql片段,在select>标签内引入该sql片段

代码示例如下:

①使用sql标签抽取映射文件中”select xxx,xxxx,xxx from xxxx”部分片段作为可重用的sql片段

<!-- 抽取映射文件中”select xxx,xxxx,xxx from xxxx”部分片段作为可重用的sql片段   -->
<sql id="select_employee">
        SELECT
            `id`,
            `last_name`,
            `email`,
            `salary`,
            `dept_id`
        FROM
            `tbl_employee`
    </sql>

    <select id="selectEmpByIds" resultType="employee">
        <!--  将刚才抽取的sql片段select_employee引入进来  -->
        <include refid="select_employee"></include>
        <where>
            `id` in
            (
            <foreach collection="ids" item="id" separator=",">
                #{id}
            </foreach>
            )
        </where>
    </select>

②测试运行

在这里插入图片描述


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

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

相关文章

Vue项目如何生成树形目录结构

文章底部有个人公众号&#xff1a;热爱技术的小郑。主要分享开发知识、有兴趣的可以关注一手。 前言 项目的目录结构清晰、可以帮助我们更快理顺项目的整体构成。在写文档之类的时候也比较方便。生成树形目录的方式有多种&#xff0c;我这里简单介绍其中一种较为简单的实现 过…

CSP 2021入门级 第一轮 题目讲解

A: a进栈&#xff0c;直接出栈&#xff1b;b进栈&#xff0c;直接出栈&#xff1b;c进栈&#xff0c;直接出栈&#xff1b;d进栈&#xff0c;直接出栈&#xff1b;e进栈&#xff0c;直接出栈。 B&#xff1a;全进栈后全出栈。 C&#xff1a;a和b先进栈&#xff0c;然后直接出…

【雕爷学编程】MicroPython动手做(09)——零基础学MaixPy之人脸识别2

自己打包kfpkg&#xff0c;试着整了好几次&#xff0c;都是无法烧录&#xff0c;只好不做第七步了&#xff0c;直接把前面获得的人脸识别模型烧录了 烧录完成后&#xff0c;打开IDE串口&#xff0c;确认开发板Maixpy固件的版本&#xff0c;好像是前期的稳定版本V0.4.0 第九步&a…

idea中创建请求基本操作

文章目录 说明效果创建GET请求没有参数带有参数带有环境变量带有动态参数 说明 首先通过###三个井号键来分开每个请求体&#xff0c;然后请求url和header参数是紧紧挨着的&#xff0c;请求参数不管是POST的body传参还是GET的parameter传参&#xff0c;都是要换行的&#xff0c;…

Java版本spring cloud + spring boot 电子招标采购系统源码

营造全面规范安全的电子招投标环境&#xff0c;促进招投标市场健康可持续发展 传统采购模式面临的挑战 一、立项管理 1、招标立项申请 功能点&#xff1a;招标类项目立项申请入口&#xff0c;用户可以保存为草稿&#xff0c;提交。 2、非招标立项申请 功能点&#xff1a;非招标…

《MySQL》第十二篇 数据类型

目录 一. 整数类型二. 浮点类型三. 日期和时间类型四. 字符串类型五. 枚举值类型六. 二进制类型七. 小结 MySQL 支持多种数据类型&#xff0c;学习好数据类型&#xff0c;才能更好的学习 MySQL 表的设计&#xff0c;让表的设计更加合理。 一. 整数类型 类型大小SIGNED(有符号)…

网红项目AutoGPT源码内幕及综合案例实战(三)

AutoGPT on LangChain PromptGenerator等源码解析 本节阅读AutoGPT 的prompt_generator.py源代码,其中定义了一个PromptGenerator类和一个get_prompt函数,用于生成一个提示词信息。PromptGenerator类提供了添加约束、命令、资源和性能评估等内容的方法,_generate_numbered_l…

effective c++ 条款2

条款2 常量(const)替换宏(#define)指针常量类成员常量 枚举(enum)替换宏(#define)模板函数(template inline)替换宏函数 尽量用const,enum,inline替换#define 总结就是&#xff1a; 常量(const)替换宏(#define) // uppercase names are usually for macros #define ASPECT_R…

HTML基础 第一课

文章目录 什么是HTMLHTML规范标签的种类开闭合标签整合标签标签中的属性 我的第一个HTML 什么是HTML Hyper Text Markup Language 超文本标记语言 超文本:表示页面上的一切要素&#xff0c;正如Java中的万物皆对象一样&#xff0c;在网页中包含 普通的文本样式 结构 视频 音频…

c++ 面试错题整理

在C中&#xff0c;下列哪个语句用于定义一个字符串变量&#xff1f;&#xff08;D&#xff09; A. string myString; B. char myString[]; C. String myString; D. char* myString; 关于为什么不是A&#xff0c;我猜测可能是因为string本质上是一个类。 C中的引用与指针有什么…

element-ui 合并表格行

element-ui 合并表格行操作 需求描述 动态获取数据后&#xff0c;将ID相同的行&#xff0c;ID合并成一个。 官方方法 //rowIndex当前行号 columnIndex当前列号 由此可知道每一行渲染时都会调用当前方法&#xff0c;只不过在渲染过程中设置了它合并的行数和列数&#xff0c;…

【Java】Spring关于Bean的存和取、Spring的执行流程以及Bean的作用域和生命周期

Spring项目的创建普通的存和取存储Bean创建Bean将Bean注册到容器中 获取并使用Bean获取Spring上下文获取并使用 更简单的存和取存储Bean配置扫描路径添加注解类注解Bean的命名规则五大注解的区别方法注解Bean方法注解要配合类注解使用重命名 Bean有参数的方法 获取Bean属性注入…

uniapp:H5定位当前省市区街道信息

高德地图api&#xff0c;H5定位省市区街道信息。 由于uniapp的uni.getLocation在H5不能获取到省市区街道信息&#xff0c;所以这里使用高德的逆地理编码接口地址接口&#xff0c;通过传key和当前经纬度&#xff0c;获取到省市区街道数据。 这里需要注意的是&#xff1a;**高德…

微信小程序,仿微信,下拉显示小程序效果,非常丝滑

1. 视图层 使用到了微信小程序的movable-view&#xff08;可移动的视图容器&#xff09;和movable-view的可移动区域。 微信小程序文档 <!--wxml--> <view style"position: relative;" class"page-container"><view>二楼内容</vie…

C++ - 优先级队列(priority_queue)的介绍和模拟实现 - 反向迭代器的适配器实现

仿函数 所谓仿函数&#xff0c;其实它本身不是一个函数&#xff0c;而是一个类&#xff0c;在这个类当中重载了 operator() 这个操作符&#xff0c;那么在外部使用这个类的 operator() 这个成员函数的时候&#xff0c;使用的形式就像是在使用一个函数一样&#xff0c;仿函数&a…

Web3.0:已经开启的互联网革命!

1 痛点 2 web发展形态 只读、封闭式、协作式。 3 一个高度联系、全球统一的数字经济体 去中心化架构通过计算几余打破数据垄断&#xff0c;同时实现数字确权大量的功能依靠智能合约自动实现&#xff0c;运转效率大大提升DAO大量涌现&#xff0c;全球范围实现资源配置 4 特…

类加载机制,类加载顺序

类加载顺序 ①类加载从上往下执行&#xff0c;依次执行静态的初始化语句和初始化块&#xff0c;而且类加载优先于对象创建。&#xff08;静态初始化语句和初始化块只加载一次&#xff09; ②创建本类的对象时&#xff0c;从上往下执行一次非静态的初始化语句和初始化块&#…

ElementUI Select选择器如何根据value值显示对应的label

修改前效果如图所示&#xff0c;数据值状态应显示为可用&#xff0c;但实际上仅显示了状态码1&#xff0c;并没有显示器对应的状态信息。在排查了数据类型对应关系问题后&#xff0c;并没有产生实质性影响&#xff0c;只好对代码进行了如下修改。 修改前代码&#xff1a; <…

出海周报|Temu在美状告shein、ChatGPT安卓版上线、小红书回应闪退

工程机械产业“出海”成绩喜人&#xff0c;山东相关企业全国最多Temu在美状告shein&#xff0c;跨境电商战事升级TikTok将在美国推出电子商务计划&#xff0c;售卖中国商品高德即将上线国际图服务&#xff0c;初期即可覆盖全球超200个国家和地区ChatGPT安卓版正式上线&#xff…

【梯度下降应用于波士顿房价预测(岭回归)】

数据准备 首先&#xff0c;我们需要获取波士顿房价数据集&#xff0c;并对数据进行处理。我们从CMU统计学习数据集库中获取数据&#xff0c;并将其划分为训练集和测试集。 import pandas as pd import numpy as npdata_url "http://lib.stat.cmu.edu/datasets/boston&q…