【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单独配置到一个文件中,然后在核心配置文件中引入,养成好习惯
一 叶 知 秋,奥 妙 玄 心
相关文章:

【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…...

【JVM基础篇】JVM入门介绍
JVM入门介绍 为什么学习JVM 岗位要求 解决工作中遇到的问题 性能调优 真实案例 导出超大文件,系统崩溃从数据库中查询超大量数据出错消费者消费来不及导致系统崩溃Mq消息队列接受消息导致的内存泄漏业务高峰期系统失去响应 初识JVM 什么是JVM? JV…...
《21天学通C++》(第二十一章)理解函数对象
什么是函数对象? 函数对象是一种特殊类型的类,它重载了函数调用操作符 operator(),使得类的实例可以像函数一样被调用。 什么是谓词? 谓词是指一个能够返回布尔值(true或false)的函数或函数对象 1.一元函数…...

2024.1.1 IntelliJ IDEA 使用记录
2024.1.1 IntelliJ IDEA 使用记录 下载设置文件编码maven 配置 插件可以中文语言包安装lombok 插件Smart Tomcat ( 根据需要安装)Smart Tomcat 配置 热部署(非必须的)解决Intellij IDEA运行报Command line is too long的问题 项目导入java 设置maven 配置…...

扩展van Emde Boas树以支持卫星数据:设计与实现
扩展van Emde Boas树以支持卫星数据:设计与实现 1. 引言2. vEB树的基本概念3. 支持卫星数据的vEB树设计3.1 数据结构的扩展3.2 操作的修改3.3 卫星数据的存储和检索 4. 详细设计和实现4.1 定义卫星数据结构体4.2 修改vEB树节点结构4.3 插入操作的伪代码4.4 C语言实现…...

玩游戏专用远程控制软件
玩游戏专用远程控制软件:实现远程游戏的新体验 随着网络技术的不断发展和创新,远程控制软件已经逐渐渗透到我们生活的方方面面,尤其是在游戏领域。玩游戏专用远程控制软件,作为这一趋势下的产物,为玩家提供了全新的游…...
机器人规划控制——工程化——心得日记-20240510
近一周一直在调试机器人过迷宫形路线,这种路线特点是障碍物之间距离较小且障碍物也比较多,基本机器人会一直发生干涉检测,请求全局路径,然后再控制机器人前进。 遇到一个特别有趣的问题,当然最后查出来原因也感觉比较…...
2024年成都市标杆场景项目申报条件对象、奖励和认定材料流程
一、申报条件 (一)申报主体需注册成立两年以上,具备独立法人资格,在成都有固定经营或者生产场地,上两年度主营业务收入年均1000万元以上或上两年度主营业务收入增长率年均10%以上; (二&#x…...

前端Vue uView 组件<u-search> 自定义右侧搜索按钮样式
前言 uView 文档的效果不是ui设计的样式 需要重新编辑 原效果 ui设计效果 解决方案 设置里说明的需要传一个样式对象 这个对象 需要写在 script 标签里面 这里需要遵循驼峰命名 比如font-size 改为 fontSize lineHeight和textAlign为水平锤子居中效果 searchStyle: {ba…...

【Linux网络编程】I/O多路转接之select
select 1.初识select2.了解select基本概念和接口介绍3.select服务器4.select特点及优缺点总结 点赞👍👍收藏🌟🌟关注💖💖 你的支持是对我最大的鼓励,我们一起努力吧!😃😃…...

三下乡社会实践投稿攻略在这里
在当今信息爆炸的时代,如何让自己的声音被更多人听到,成为许多人和企业所关心的问题。其中,向各大媒体网站投稿,成为了一种常见的宣传方式。但是,如何投稿各大媒体网站?新闻媒体发文策略又有哪些呢…...

银河麒麟桌面版开机后网络无法自动链接 麒麟系统开机没有连接ens33
1.每次虚拟机开机启动麒麟操作系统,都要输入账号,密码。 进入点击这个ens33 内网才连接 2. 如何开机就脸上呢? 2.1. 进入 cd /etc/sysconfig/network-scripts 2.2 修改参数 onbootyes 改为yes 2.3 重启即可 a. 直接重启机器查看是否正常&…...
vue+onlyOffice+java : 集成在线编辑word并保存
1.docker部署onlyOffice 1.1拉取最新版onlyOffice镜像 sudo docker pull onlyoffice/documentserver 1.2运行以下命令运行容器 其中 -v 后的第一部分是挂载自己的linux的哪个目录 # 启动docker容器,默认启动端口为80,可以进行修改 docker run -i -t …...

linux上用Jmter进行压测
在上一篇中安装好了Jmeter环境,在这一篇中将主要分享如何使用jmeter在linux中进行单机压测。 1.项目部署 在这里我们先简单部署一下测试环境,所用到的项目环境是个jar包,先在linux上home目录下新建app目录,然后通过rz命令将项目ja…...

【Java代码审计】代码审计的方法及常用工具
【Java代码审计】代码审计的方法及常用工具 代码审计的常用思路代码审计辅助工具代码编辑器测试工具反编译工具Java 代码静态扫描工具 代码审计的常用思路 1、接口排查(“正向追踪”):先找出从外部接口接收的参数,并跟踪其传递过…...

我国吻合器市场规模不断扩大 国产化率有所增长
我国吻合器市场规模不断扩大 国产化率有所增长 吻合器是替代手工切除或缝合的一种医疗器械,其工作原理与订书机十分相似,可利用钛钉对组织进行离断或吻合。经过多年发展,吻合器种类逐渐增多,根据手术方式不同,吻合器大…...

深度剖析Comate智能产品:科技巧思,实用至上
文章目录 Comate智能编码助手介绍Comate应用场景Comate语言与IDE支持 Comate安装步骤Comate智能编码使用体验代码推荐智能推荐生成单测注释解释注释生成智能问答 Comate实战演练总结 Comate智能编码助手介绍 市面上现在有很多智能代码助手,当时互联网头部大厂百度也…...

Centos 7.9 配置VNCServer实现远程vnc连接
文章目录 1、Centos安装图形界面1.1、安装X Windows System图形界面1.2、安装GNOME图形界面 2、VNC SERVER配置2.1、VNC SERVER安装2.2、VNC SERVER配置1)创建vnc配置文件2)修改配置文件内容3)完整配置文件参考 2.3、设置vnc密码2.4、配置防火…...
设计模式-08 - 模板方法模式 Template Method
设计模式-08 - 模板方法模式 Template Method 1.定义 模板方法模式是一种设计模式,它定义了一个操作的骨架,而由子类来决定如何实现该操作的某些步骤。它允许子类在不改变算法结构的情况下重定义算法的特定步骤。 模板方法模式适合用于以下情况&am…...
Android 适配阿拉伯语之vector图标镜像
Android 适配阿拉伯语之vector图标镜像 android:autoMirrored“true” 属性简单而直接的方法来自动处理 RTL 环境中图标的翻转。 使用 android:autoMirrored“true” 在 Vector Drawable 中是一种非常方便的方法,因为它允许你使用相同的 drawable 资源来适应不同的…...

装饰模式(Decorator Pattern)重构java邮件发奖系统实战
前言 现在我们有个如下的需求,设计一个邮件发奖的小系统, 需求 1.数据验证 → 2. 敏感信息加密 → 3. 日志记录 → 4. 实际发送邮件 装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其…...
HTML 语义化
目录 HTML 语义化HTML5 新特性HTML 语义化的好处语义化标签的使用场景最佳实践 HTML 语义化 HTML5 新特性 标准答案: 语义化标签: <header>:页头<nav>:导航<main>:主要内容<article>&#x…...

7.4.分块查找
一.分块查找的算法思想: 1.实例: 以上述图片的顺序表为例, 该顺序表的数据元素从整体来看是乱序的,但如果把这些数据元素分成一块一块的小区间, 第一个区间[0,1]索引上的数据元素都是小于等于10的, 第二…...

简易版抽奖活动的设计技术方案
1.前言 本技术方案旨在设计一套完整且可靠的抽奖活动逻辑,确保抽奖活动能够公平、公正、公开地进行,同时满足高并发访问、数据安全存储与高效处理等需求,为用户提供流畅的抽奖体验,助力业务顺利开展。本方案将涵盖抽奖活动的整体架构设计、核心流程逻辑、关键功能实现以及…...

安宝特方案丨XRSOP人员作业标准化管理平台:AR智慧点检验收套件
在选煤厂、化工厂、钢铁厂等过程生产型企业,其生产设备的运行效率和非计划停机对工业制造效益有较大影响。 随着企业自动化和智能化建设的推进,需提前预防假检、错检、漏检,推动智慧生产运维系统数据的流动和现场赋能应用。同时,…...

【SQL学习笔记1】增删改查+多表连接全解析(内附SQL免费在线练习工具)
可以使用Sqliteviz这个网站免费编写sql语句,它能够让用户直接在浏览器内练习SQL的语法,不需要安装任何软件。 链接如下: sqliteviz 注意: 在转写SQL语法时,关键字之间有一个特定的顺序,这个顺序会影响到…...
爬虫基础学习day2
# 爬虫设计领域 工商:企查查、天眼查短视频:抖音、快手、西瓜 ---> 飞瓜电商:京东、淘宝、聚美优品、亚马逊 ---> 分析店铺经营决策标题、排名航空:抓取所有航空公司价格 ---> 去哪儿自媒体:采集自媒体数据进…...
Rapidio门铃消息FIFO溢出机制
关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系,以下是深入解析: 门铃FIFO溢出的本质 在RapidIO系统中,门铃消息FIFO是硬件控制器内部的缓冲区,用于临时存储接收到的门铃消息(Doorbell Message)。…...
Typeerror: cannot read properties of undefined (reading ‘XXX‘)
最近需要在离线机器上运行软件,所以得把软件用docker打包起来,大部分功能都没问题,出了一个奇怪的事情。同样的代码,在本机上用vscode可以运行起来,但是打包之后在docker里出现了问题。使用的是dialog组件,…...
深入浅出WebGL:在浏览器中解锁3D世界的魔法钥匙
WebGL:在浏览器中解锁3D世界的魔法钥匙 引言:网页的边界正在消失 在数字化浪潮的推动下,网页早已不再是静态信息的展示窗口。如今,我们可以在浏览器中体验逼真的3D游戏、交互式数据可视化、虚拟实验室,甚至沉浸式的V…...