【Spring】Spring 整合 Junit、MyBatis

一、 Spring 整合 Junit

<?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>org.qiu</groupId><artifactId>spring-015-junit</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.23</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><!-- Spring6 的支持 junit4 还有 junit5 --><version>5.3.23</version></dependency><!--使用Junit则将下面改为Junit5版本即可--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency></dependencies></project>
package org.qiu.spring.bean;import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;/*** @author 秋玄* @version 1.0* @email qiu_2022@aliyun.com* @project Spring* @package org.qiu.spring.bean* @date 2022-11-30-21:55* @since 1.0*/
@Component
public class User {@Value("张三")private String name;@Overridepublic String toString() {return "User{" +"name='" + name + '\'' +'}';}public String getName() {return name;}public void setName(String name) {this.name = name;}public User() {}public User(String name) {this.name = name;}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><context:component-scan base-package="org.qiu.spring.bean"/>
</beans>
package org.qiu.spring.test;import org.junit.Test;
import org.junit.runner.RunWith;
import org.qiu.spring.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;/*** @author 秋玄* @version 1.0* @email qiu_2022@aliyun.com* @project Spring* @package org.qiu.spring.test* @date 2022-11-30-21:56* @since 1.0*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring.xml")
public class JunitTest {@Autowiredprivate User user;@Testpublic void testUser(){System.out.println(user.getName());}
}

运行效果:  

Spring提供的方便主要是这几个注解:

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:spring.xml")

在单元测试类上使用这两个注解之后,在单元测试类中的属性上可以使用@Autowired。比较方便

在JUnit5当中,可以使用Spring提供的以下两个注解,标注到单元测试类上,这样在类当中就可以使用@Autowired注解了

@ExtendWith(SpringExtension.class)

@ContextConfiguration("classpath:spring.xml")

二、Spring 集成 MyBatis

1、实验步骤 

  • 第一步:准备数据库表

    • 使用t_act表(账户表)

  • 第二步:IDEA中创建一个模块,并引入依赖

    • spring-context

    • spring-jdbc

    • mysql驱动

    • mybatis

    • mybatis-spring:mybatis提供的与spring框架集成的依赖

    • 德鲁伊连接池

    • junit

  • 第三步:基于三层架构实现,所以提前创建好所有的包

    • com.qiu.bank.mapper

    • com.qiu.bank.service

    • com.qiu.bank.service.impl

    • com.qiu.bank.pojo

  • 第四步:编写pojo

    • Account,属性私有化,提供公开的setter getter和toString。

  • 第五步:编写mapper接口

    • AccountMapper接口,定义方法

  • 第六步:编写mapper配置文件

    • 在配置文件中配置命名空间,以及每一个方法对应的sql。

  • 第七步:编写service接口和service接口实现类

    • AccountService

    • AccountServiceImpl

  • 第八步:编写jdbc.properties配置文件

    • 数据库连接池相关信息

  • 第九步:编写mybatis-config.xml配置文件

    • 该文件可以没有,大部分的配置可以转移到spring配置文件中。

    • 如果遇到mybatis相关的系统级配置,还是需要这个文件。

  • 第十步:编写spring.xml配置文件

    • 组件扫描

    • 引入外部的属性文件

    • 数据源

    • SqlSessionFactoryBean配置

    • 注入mybatis核心配置文件路径

      • 指定别名包

      • 注入数据源

    • Mapper扫描配置器

      • 指定扫描的包

    • 事务管理器DataSourceTransactionManager

      • 注入数据源

    • 启用事务注解

      • 注入事务管理器

  • 第十一步:编写测试程序,并添加事务,进行测试

2、具体实现 

<?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>org.qiu</groupId><artifactId>spring-016-sm</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><!--spring-context--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.23</version></dependency><!--spring-jdbc--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.23</version></dependency><!--mysql驱动--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.30</version></dependency><!--mybatis--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.10</version></dependency><!--mybatis-spring:mybatis提供的与spring框架集成的依赖--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.3</version></dependency><!--德鲁伊连接池--><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.15</version></dependency><!--junit--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency></dependencies></project>
package org.qiu.spring.pojo;/*** @author 秋玄* @version 1.0* @email qiu_2022@aliyun.com* @project Spring* @package org.qiu.spring.pojo* @date 2022-12-01-09:16* @since 1.0*/
public class Account {private String actno;private Double balance;public Account() {}public Account(String actno, Double balance) {this.actno = actno;this.balance = balance;}@Overridepublic String toString() {return "Account{" +"actno='" + actno + '\'' +", balance=" + balance +'}';}public String getActno() {return actno;}public void setActno(String actno) {this.actno = actno;}public Double getBalance() {return balance;}public void setBalance(Double balance) {this.balance = balance;}
}
package org.qiu.spring.mapper;import org.qiu.spring.pojo.Account;import java.util.List;/*** 实现类不需要写,由 mybatis 通过动态代理实现即可* @author 秋玄* @version 1.0* @email qiu_2022@aliyun.com* @project Spring* @package org.qiu.spring.mapper* @date 2022-12-01-09:17* @since 1.0*/
public interface AccountMapper {int insert(Account account);int delete(String atcno);int update(Account account);Account selectByActno(String actno);List<Account> selectAll();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.qiu.spring.mapper"><insert id="insert">insert into t_act values (#{actno},#{balance})</insert><delete id="delete">delete from t_act where actno = #{actno}</delete><update id="update">update t_act set balance = #{balance} where actno = #{actno}</update><select id="selectByActno" resultType="Account">select * from t_act where actno = #{actno}</select><select id="selectAll" resultType="Account">select * from t_act</select>
</mapper>
package org.qiu.spring.service;import org.qiu.spring.pojo.Account;import java.util.List;/*** @author 秋玄* @version 1.0* @email qiu_2022@aliyun.com* @project Spring* @package org.qiu.spring.service* @date 2022-12-01-09:30* @since 1.0*/
public interface AccountService {int save(Account account);int deleteByActno(String actno);int modify(Account account);Account getByActno(String actno);List<Account> getAll();void transfer(String fromAccount,String toAccount,Double money);
}
package org.qiu.spring.service.impl;import org.qiu.spring.mapper.AccountMapper;
import org.qiu.spring.pojo.Account;
import org.qiu.spring.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;/*** @author 秋玄* @version 1.0* @email qiu_2022@aliyun.com* @project Spring* @package org.qiu.spring.service.impl* @date 2022-12-01-09:33* @since 1.0*/
@Service("accountService")
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountMapper accountMapper;@Overridepublic int save(Account account) {return accountMapper.insert(account);}@Overridepublic int deleteByActno(String actno) {return accountMapper.delete(actno);}@Overridepublic int modify(Account account) {return accountMapper.update(account);}@Overridepublic Account getByActno(String actno) {return accountMapper.selectByActno(actno);}@Overridepublic List<Account> getAll() {return accountMapper.selectAll();}@Overridepublic void transfer(String fromAccount, String toAccount, Double money) {Account from = accountMapper.selectByActno(fromAccount);if (from.getBalance() < money) {throw new RuntimeException("余额不足");}Account to = accountMapper.selectByActno(toAccount);from.setBalance(from.getBalance() - money);to.setBalance(to.getBalance() + money);int count = accountMapper.update(from);count += accountMapper.update(to);if (count != 2){throw new RuntimeException("转账失败");}}
}
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mvc
jdbc.username=root
jdbc.password=mysql
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!--打印 mybatis 日志信息--><settings><setting name="logImpl" value="STDOUT_LOGGING"/></settings>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!--组件扫描--><context:component-scan base-package="org.qiu.spring"/><!--引入外部属性文件--><context:property-placeholder location="jdbc.properties"/><!--数据源--><bean id="dataSuorce" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driver}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><!--SqlSessionFactoryBean--><bean class="org.mybatis.spring.SqlSessionFactoryBean"><!--注入数据源--><property name="dataSource" ref="dataSuorce"/><!--指定 mybatis 核心配置文件--><property name="configLocation" value="mybatis-config.xml"/><!--指定别名包--><property name="typeAliasesPackage" value="org.qiu.spring.pojo"/></bean><!--Mapper扫描配置器,扫描Mapper接口,生成代理类--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="org.qiu.spring.mapper"/></bean><!--事务管理器--><bean id="txManaget" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSuorce"/></bean><!--启动事务注解--><tx:annotation-driven transaction-manager="txManaget"/></beans>

由于使用了事务,所以需要给service添加事务注解  

@Transactional
@Service("accountService")
public class AccountServiceImpl implements AccountService {\\ ......
}

import org.junit.Test;
import org.qiu.spring.service.AccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @author 秋玄* @version 1.0* @email qiu_2022@aliyun.com* @project Spring* @package PACKAGE_NAME* @date 2022-12-01-10:04* @since 1.0*/
public class SMTest {@Testpublic void testSM(){ApplicationContext app = new ClassPathXmlApplicationContext("spring.xml");AccountService service = app.getBean("accountService", AccountService.class);try {service.transfer("act001","act002",10000.0);System.out.println("转账成功");} catch (Exception e){e.printStackTrace();}}}

运行效果:  

Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
十二月 01, 2022 10:16:27 上午 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl info
信息: {dataSource-1} inited
Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@15a04efb] will be managed by Spring
==>  Preparing: select * from t_act where actno = ?
==> Parameters: act001(String)
<==    Columns: actno, balance
<==        Row: act001, 40000.0
<==      Total: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb] from current transaction
==>  Preparing: select * from t_act where actno = ?
==> Parameters: act002(String)
<==    Columns: actno, balance
<==        Row: act002, 10000.0
<==      Total: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb] from current transaction
==>  Preparing: update t_act set balance = ? where actno = ?
==> Parameters: 30000.0(Double), act001(String)
<==    Updates: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb] from current transaction
==>  Preparing: update t_act set balance = ? where actno = ?
==> Parameters: 20000.0(Double), act002(String)
<==    Updates: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2f666ebb]
转账成功

3、Spring 配置文件的 import

spring 配置文件有多个,并且可以在 spring 的核心配置文件中使用 import 进行引入,我们可以将组件扫描单独定义到一个配置文件中,如下:  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--组件扫描--><context:component-scan base-package="com.qiu.bank"/></beans>

然后在核心配置文件中引入:  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--引入其他的spring配置文件--><import resource="common.xml"/></beans>

注意:在实际开发中,service单独配置到一个文件中,dao单独配置到一个文件中,然后在核心配置文件中引入,养成好习惯  

一  叶  知  秋,奥  妙  玄  心

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

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

相关文章

世上最全前端开发教程(HTMLCSS)

HTML介绍 HTML&#xff0c;全称为HyperText Markup Language&#xff0c;即超文本标记语言&#xff0c;是一种用来创建网页的标准标记语言。HTML使用一系列的标签&#xff08;Tags&#xff09;来定义网页的不同部分和它们的行为&#xff0c;比如段落、链接、图片等。 CSS介绍 …

Docker + Django跨域解决方案

什么是Django Django 是一个开源的高级 Python Web 框架&#xff0c;它鼓励快速开发并遵循可重用和可维护的实践。Django 是在 MTV&#xff08;模型-模板-视图&#xff09;模式的基础上设计的&#xff0c;这个模式类似于但不同于 MVC&#xff08;模型-视图-控制器&#xff09;模…

使用 MSYS2 Qt6 发布绿色版的SDR软件无线电应用

文章目录 概要整体架构流程技术名词解释技术细节在启动器中为子进程设置路径和环境。如何迅速找齐所有的DLL 小结附件 概要 新接触软件定义无线电&#xff08;SDR&#xff09;的朋友一般都会一股脑的安装一些现有的SDR平台。无论是GNURadio还是SDR、SDRSharp、SDRAngel&#x…

【WPF学习笔记(一)】WPF应用程序的组成及Window类介绍

WPF应用程序的组成及Window类介绍 WPF应用程序的组成及Window类介绍前言正文1、WPF介绍1.1 什么是WPF1.2 WPF的特点1.3 WPF的控件分类 2、XAML介绍2.1 XAML的定义2.2 XAML的特点2.3 XAML的命名空间 3、WPF应用程序组成3.1 App.config3.2 App.xaml3.3 App.xaml.cs3.4 MainWindow…

【配置】IT-Tools部署

github地址 docker运行如下&#xff0c;记得打卡端口 docker run -d --name it-tools --restart unless-stopped -p 9090:80 corentinth/it-tools:latestip:9090查看&#xff0c;很香大部分工具都有

【C++】CentOS环境搭建-安装CATCH2

【C】CentOS环境搭建-安装CATCH2 1.克隆Catch2仓库2. 进入Catch2目录3. 创建一个构建目录4. 使用CMake生成构建系统&#xff08;以及可能的编译&#xff09;5.安装Catch2&#xff08;可选&#xff0c;根据你的需求&#xff09; 1.克隆Catch2仓库 git clone https://github.com…

Secnet-智能路由系统 actpt_5g.data 信息泄露漏洞复现

0x01 产品简介 Secnet安网智能AC管理系统是广州安网通信技术有限公司&#xff08;简称“安网通信”&#xff09;的无线AP管理系统。 0x02 漏洞概述 Secnet-智能路由系统 actpt_5g.data 接口存在信息泄露漏洞&#xff0c;未经身份验证的远程攻击者可以利用此漏洞获取系统账户…

【Java难点】多线程-高级

悲观锁和乐观锁 悲观锁 synchronized关键字和Lock的实现类都是悲观锁。 它很悲观&#xff0c;认为自己在使用数据的时候一定有别的线程来修改数据&#xff0c;因此在获取数据的时候会一不做二不休的先加锁&#xff0c;确保数据不会被别的线程修改。 适合写操作多的场景&…

sipeed 的 MaixCam UART操作

发现问题 根据sipeed MaixCam官方文档 使用MaixVision会报错。 正确的接线 1&#xff0c;usb转ttl的RX和TX与sipeed MaixCam官方赠送的usb转接头反向连接&#xff0c;GND互相连接。 2&#xff0c;再用一根tpyc-c为其供电。 连接WiFi路由器 MaixCam液晶屏输入WiFi名称和密…

【Nginx】如何在 Nginx 中阻止来自特定国家的 IP 地址访问

文章目录 前言一、准备工作二、查看 Nginx 服务器都拥有哪些模块2.1 先查看本地nginx是否有ngx_http_geoip2模块2.2 安装nginx并配置ngx_http_geoip2模块2.2.1下载所需版本的nginx到服务器2.2.2 先安装所需依赖2.2.3 解压文件2.2.4 下载ngx_http_geoip2模块2.2.5 编译安装nginx…

视频批量剪辑指南:一键合并视频并添加背景音乐,高效便捷

在数字化时代&#xff0c;视频剪辑已经成为了一项常见且重要的技能。无论是制作家庭影片、工作展示还是社交媒体内容&#xff0c;掌握高效的视频剪辑技巧都能极大地提升我们的工作效率和创作质量。本文将为您介绍云炫AI智剪中高效的视频批量剪辑方法&#xff0c;让您能够一键合…

(Java)心得:LeetCode——15.三数之和

一、原题 给你一个整数数组 nums &#xff0c;判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i ! j、i ! k 且 j ! k &#xff0c;同时还满足 nums[i] nums[j] nums[k] 0 。请你返回所有和为 0 且不重复的三元组。 注意&#xff1a;答案中不可以包含重复的三元组。…

Java集合框架之LinkedHashSet详解

哈喽&#xff0c;各位小伙伴们&#xff0c;你们好呀&#xff0c;我是喵手。运营社区&#xff1a;C站/掘金/腾讯云&#xff1b;欢迎大家常来逛逛 今天我要给大家分享一些自己日常学习到的一些知识点&#xff0c;并以文字的形式跟大家一起交流&#xff0c;互相学习&#xff0c;一…

QX---mini51单片机学习---(6)独立键盘

目录 1键盘简绍 2按键的工作原理 3键盘类型 4独立键盘与矩阵键盘的特点 5本节相关原理图 6按键特性 7实践 1键盘简绍 2按键的工作原理 内部使用轻触按键&#xff0c;常态按下按键触点才闭合 3键盘类型 编码键盘与非编码键盘 4独立键盘与矩阵键盘的特点 5本节相关原理…

Python框架Django入门教程

Django 是一个使用 Python 编程语言开发的、免费且开源的 Web 应用框架。它遵循 "DRY&#xff08;Dont Repeat Yourself&#xff09;" 原则&#xff0c;旨在简化创建功能丰富的、高效率的 Web 网站。Django 提供了模型-视图-控制器&#xff08;MVC&#xff09;架构的…

Ubuntu安装库 版本问题,错误E: Unable to correct problems, you have held broken packages.

一、问题描述&#xff1a; Ubuntu系统指令安装 : sudo apt install -y build-essential提示&#xff1a; Reading package lists... Done Building dependency tree... Done Reading state information... Done Some packages could not be installed. This may mean that y…

Prompt|Kimi高阶技巧,99%的人都不知道

大家好&#xff0c;我是无界生长。 今天分享一条咒语&#xff0c;轻松让Kimi帮你生成流程图&#xff0c;学会了的话&#xff0c;点赞收藏起来吧&#xff01; 效果展示 我们演示一下让kimi帮忙绘制 关注微信公众号“无界生长”的流程图&#xff0c;最终效果图如下所示 效果还不…

Java线程池:当核心线程数为 0 时,任务来了的执行流程

先说结论&#xff1a;创建一个临时线程直接执行 ThreadPoolExecutor.excute() public void execute(Runnable command) {if (command null)throw new NullPointerException();int c ctl.get();if (workerCountOf(c) < corePoolSize) {if (addWorker(command, true)) retu…

滑动窗口篇: 长度最小子数组|无重复字符最长字串

目录 1、滑动窗口算法 1.1 核心概念 1.2 基本步骤 1.3 应用场景 1.4 优势 2. leetcode 209 长度最小子数组 暴力解题思路&#xff1a; 滑动窗口思路&#xff1a; 3、无重复字符的最长子串 暴力解题思路&#xff1a; 滑动窗口思路&#xff1a; 1、滑动窗口算法 滑动…

while 习题

while 结构 习题 1.计算1到100所有整数和 2.提示用户输入一个小于100的整数&#xff0c;并计算从1到该数之间所有整数的和 3.求从1到100所有整数的偶数和、奇数和 echo -e \n 可以实现换行 4.用户输入密码&#xff0c;脚本判断密码是否正确&#xff0c;正确密码为123456&am…