添加 常用校验方法,校验常见数据格式

目录

  • 一、前置说明
    • 1、总体目录
    • 2、相关回顾
    • 3、本节目标
  • 二、操作步骤
    • 1、项目目录
    • 2、代码实现
    • 3、测试代码
    • 4、日志输出
  • 三、后置说明
    • 1、要点小结
    • 2、下节准备

一、前置说明

1、总体目录

  • 《 pyparamvalidate 参数校验器,从编码到发布全过程》

2、相关回顾

  • 基于 Validator 类实现 ParamValidator,用于校验函数参数
  • 优化 ParamValidator,让编辑器Pycharm智能提示校验方法

3、本节目标

  • 添加常用校验方法,校验常见数据格式

二、操作步骤

1、项目目录

  • atme : @me 用于存放临时的代码片断或其它内容。
  • pyparamvalidate : 新建一个与项目名称同名的package,为了方便发布至 pypi
  • core : 用于存放核心代码。
  • tests : 用于存放测试代码。
  • utils : 用于存放一些工具类或方法。

2、代码实现

pyparamvalidate/core/validator.py

import functools
import inspect
import os
from typing import TypeVar


def _error_prompt(value, exception_msg=None, rule_des=None, field=None):
    default = f'"{value}" is invalid.'
    prompt = exception_msg or rule_des
    prompt = f'{default} due to: {prompt}' if prompt else default
    prompt = f'{field} error: {prompt}' if field else prompt
    return prompt


def raise_exception(func):
    @functools.wraps(func)
    def wrapper(self, *args, **kwargs):
        bound_args = inspect.signature(func).bind(self, *args, **kwargs).arguments

        exception_msg = kwargs.get('exception_msg', None) or bound_args.get('exception_msg', None)
        error_prompt = _error_prompt(self.value, exception_msg, self._rule_des, self._field)

        result = func(self, *args, **kwargs)
        if not result:
            raise ValueError(error_prompt)

        return self

    return wrapper


class RaiseExceptionMeta(type):
    def __new__(cls, name, bases, dct):
        for key, value in dct.items():
            if isinstance(value, staticmethod):
                dct[key] = staticmethod(raise_exception(value.__func__))

            if isinstance(value, classmethod):
                dct[key] = classmethod(raise_exception(value.__func__))

            if inspect.isfunction(value) and not key.startswith("__"):
                dct[key] = raise_exception(value)

        return super().__new__(cls, name, bases, dct)


'''
- TypeVar 是 Python 中用于声明类型变量的工具
- 声明一个类型变量,命名为 'Self', 意思为表示类的实例类型
- bound 参数指定泛型类型变量的上界,即限制 'Self' 必须是 'Validator' 类型或其子类型
'''
Self = TypeVar('Self', bound='Validator')


class Validator(metaclass=RaiseExceptionMeta):
    def __init__(self, value, field=None, rule_des=None):
        self.value = value
        self._field = field
        self._rule_des = rule_des

    def is_string(self, exception_msg=None) -> Self:
        """
        将返回类型注解定义为 Self, 支持编辑器如 pycharm 智能提示链式调用方法,如:Validator(input).is_string().is_not_empty()

        - 从 Python 3.5 版本开始支持类型注解
            - 在 Python 3.5 中引入了 PEP 484(Python Enhancement Proposal 484),其中包括了类型注解的概念,并引入了 typing 模块,用于支持类型提示和静态类型检查;
            - 类型注解允许开发者在函数参数、返回值和变量上添加类型信息,但是在运行时,Python 解释器不会检查这些注解是否正确;
            - 它们主要用于提供给静态类型检查器或代码编辑器进行,以提供更好的代码提示和错误检测;
            - Python 运行时并不强制执行这些注解,Python 依然是一门动态类型的语言。

        - 本方法中:
            - 返回值类型为 bool 类型,用于与装饰器函数 raise_exception 配合使用,校验 self.value 是否通过;
            - 为了支持编辑器如 pycharm 智能识别链式调用方法,将返回类型注解定义为 Self, 如:Validator(input).is_string().is_not_empty();
            - Self, 即 'Validator', 由 Self = TypeVar('Self', bound='Validator') 定义;
            - 如果返回类型不为 Self, 编辑器如 pycharm 在 Validator(input).is_string() 之后,不会智能提示 is_not_empty()
        """
        return isinstance(self.value, str)

    def is_int(self, exception_msg=None):
        return isinstance(self.value, int)

    def is_positive(self, exception_msg=None):
        return self.value > 0

    def is_float(self, exception_msg=None):
        return isinstance(self.value, float)

    def is_list(self, exception_msg=None):
        return isinstance(self.value, list)

    def is_dict(self, exception_msg=None):
        return isinstance(self.value, dict)

    def is_set(self, exception_msg=None):
        return isinstance(self.value, set)

    def is_tuple(self, exception_msg=None):
        return isinstance(self.value, tuple)

    def is_not_none(self, exception_msg=None):
        return self.value is not None

    def is_not_empty(self, exception_msg=None):
        return bool(self.value)

    def is_allowed_value(self, allowed_values, exception_msg=None):
        return self.value in allowed_values

    def is_specific_value(self, specific_value, exception_msg=None):
        return self.value == specific_value

    def max_length(self, max_length, exception_msg=None):
        return len(self.value) <= max_length

    def min_length(self, min_length, exception_msg=None):
        return len(self.value) >= min_length

    def is_substring(self, super_string, exception_msg=None):
        return self.value in super_string

    def is_subset(self, superset, exception_msg=None):
        return self.value.issubset(superset)

    def is_sublist(self, superlist, exception_msg=None):
        return set(self.value).issubset(set(superlist))

    def contains_substring(self, substring, exception_msg=None):
        return substring in self.value

    def contains_subset(self, subset, exception_msg=None):
        return subset.issubset(self.value)

    def contains_sublist(self, sublist, exception_msg=None):
        return set(sublist).issubset(set(self.value))

    def is_file(self, exception_msg=None):
        return os.path.isfile(self.value)

    def is_dir(self, exception_msg=None):
        return os.path.isdir(self.value)

    def is_file_suffix(self, file_suffix, exception_msg=None):
        return self.value.endswith(file_suffix)

    def is_method(self, exception_msg=None):
        return callable(self.value)

3、测试代码

pyparamvalidate/tests/test_validator.py


import os

import pytest

from pyparamvalidate.core.validator import Validator


def test_is_string():
    assert Validator("test").is_string(exception_msg='value must be string')

    with pytest.raises(ValueError) as exc_info:
        Validator(123).is_string(exception_msg='value must be string')
    assert "value must be string" in str(exc_info.value)


def test_is_int():
    assert Validator(42).is_int(exception_msg='value must be integer')

    with pytest.raises(ValueError) as exc_info:
        Validator("test").is_int(exception_msg='value must be integer')
    assert "value must be integer" in str(exc_info.value)


def test_is_positive():
    assert Validator(42).is_positive(exception_msg='value must be positive')

    with pytest.raises(ValueError) as exc_info:
        Validator(-1).is_positive(exception_msg='value must be positive')
    assert "value must be positive" in str(exc_info.value)


def test_is_float():
    assert Validator(3.14).is_float(exception_msg='value must be float')

    with pytest.raises(ValueError) as exc_info:
        Validator("test").is_float(exception_msg='value must be float')
    assert "value must be float" in str(exc_info.value)


def test_is_list():
    assert Validator([1, 2, 3]).is_list(exception_msg='value must be list')

    with pytest.raises(ValueError) as exc_info:
        Validator("test").is_list(exception_msg='value must be list')
    assert "value must be list" in str(exc_info.value)


def test_is_dict():
    assert Validator({"key": "value"}).is_dict(exception_msg='value must be dict')

    with pytest.raises(ValueError) as exc_info:
        Validator([1, 2, 3]).is_dict(exception_msg='value must be dict')
    assert "value must be dict" in str(exc_info.value)


def test_is_set():
    assert Validator({1, 2, 3}).is_set(exception_msg='value must be set')

    with pytest.raises(ValueError) as exc_info:
        Validator([1, 2, 3]).is_set(exception_msg='value must be set')
    assert "value must be set" in str(exc_info.value)


def test_is_tuple():
    assert Validator((1, 2, 3)).is_tuple(exception_msg='value must be tuple')

    with pytest.raises(ValueError) as exc_info:
        Validator([1, 2, 3]).is_tuple(exception_msg='value must be tuple')
    assert "value must be tuple" in str(exc_info.value)


def test_is_not_none():
    assert Validator("test").is_not_none(exception_msg='value must not be None')

    with pytest.raises(ValueError) as exc_info:
        Validator(None).is_not_none(exception_msg='value must not be None')
    assert "value must not be None" in str(exc_info.value)


def test_is_not_empty():
    assert Validator("test").is_not_empty(exception_msg='value must not be empty')

    with pytest.raises(ValueError) as exc_info:
        Validator("").is_not_empty(exception_msg='value must not be empty')
        assert "value must not be empty" in str(exc_info.value)


def test_is_allowed_value():
    assert Validator(3).is_allowed_value(allowed_values=[1, 2, 3, 4, 5],
                                         exception_msg='value must be in allowed_values')

    with pytest.raises(ValueError) as exc_info:
        Validator(6).is_allowed_value(allowed_values=[1, 2, 3, 4, 5],
                                      exception_msg='value must be in allowed_values')
    assert "value must be in allowed_values" in str(exc_info.value)


def test_is_specific_value():
    assert Validator(3).is_specific_value(specific_value=3,
                                          exception_msg='value must be in allowed_values')

    with pytest.raises(ValueError) as exc_info:
        Validator(6).is_specific_value(specific_value=3,
                                       exception_msg='value must be in allowed_values')
    assert "value must be in allowed_values" in str(exc_info.value)


def test_max_length():
    assert Validator("test").max_length(max_length=5,
                                        exception_msg='value length must be less than or equal to 5')

    with pytest.raises(ValueError) as exc_info:
        Validator("test").max_length(max_length=3,
                                     exception_msg='value length must be less than or equal to 3')
    assert "value length must be less than or equal to 3" in str(exc_info.value)


def test_min_length():
    assert Validator("test").min_length(min_length=3,
                                        exception_msg='value length must be greater than or equal to 3')

    with pytest.raises(ValueError) as exc_info:
        Validator("test").min_length(min_length=5,
                                     exception_msg='value length must be greater than or equal to 5')
    assert "value length must be greater than or equal to 5" in str(exc_info.value)


def test_is_substring():
    assert Validator("st").is_substring(super_string="test",
                                        exception_msg='sub_string must be a substring of super_string')

    with pytest.raises(ValueError) as exc_info:
        Validator("abc").is_substring(super_string="test",
                                      exception_msg='sub_string must be a substring of super_string')
    assert "sub_string must be a substring of super_string" in str(exc_info.value)


def test_is_subset():
    assert Validator({1, 2}).is_subset(superset={1, 2, 3, 4},
                                       exception_msg='subset must be a subset of superset')

    with pytest.raises(ValueError) as exc_info:
        Validator({5, 6}).is_subset(superset={1, 2, 3, 4},
                                    exception_msg='subset must be a subset of superset')
    assert "subset must be a subset of superset" in str(exc_info.value)


def test_is_sublist():
    assert Validator([1, 2]).is_sublist(superlist=[1, 2, 3, 4],
                                        exception_msg='sublist must be a sublist of superlist')

    with pytest.raises(ValueError) as exc_info:
        Validator([5, 6]).is_sublist(superlist=[1, 2, 3, 4],
                                     exception_msg='sublist must be a sublist of superlist')
    assert "sublist must be a sublist of superlist" in str(exc_info.value)


def test_contains_substring():
    assert Validator("test").contains_substring(substring="es",
                                                exception_msg='superstring must contain substring')

    with pytest.raises(ValueError) as exc_info:
        Validator("test").contains_substring(substring="abc",
                                             exception_msg='superstring must contain substring')
    assert "superstring must contain substring" in str(exc_info.value)


def test_contains_subset():
    assert Validator({1, 2, 3, 4}).contains_subset(subset={1, 2},
                                                   exception_msg='superset must contain subset')

    with pytest.raises(ValueError) as exc_info:
        Validator({1, 2, 3, 4}).contains_subset(subset={5, 6},
                                                exception_msg='superset must contain subset')
    assert "superset must contain subset" in str(exc_info.value)


def test_contains_sublist():
    assert Validator([1, 2, 3, 4]).contains_sublist(sublist=[1, 2],
                                                    exception_msg='superlist must contain sublist')

    with pytest.raises(ValueError) as exc_info:
        Validator([1, 2, 3, 4]).contains_sublist(sublist=[5, 6],
                                                 exception_msg='superlist must contain sublist')
    assert "superlist must contain sublist" in str(exc_info.value)


def test_is_file_suffix():
    assert Validator("example.txt").is_file_suffix(file_suffix=".txt",
                                                   exception_msg='path must have the specified file suffix')

    with pytest.raises(ValueError) as exc_info:
        Validator("example.txt").is_file_suffix(file_suffix=".csv",
                                                exception_msg='path must have the specified file suffix')
    assert "path must have the specified file suffix" in str(exc_info.value)


def test_is_file():
    assert Validator(__file__).is_file(exception_msg='path must be an existing file')

    with pytest.raises(ValueError) as exc_info:
        Validator("path").is_file(
            exception_msg='path must be an existing file')
    assert "path must be an existing file" in str(exc_info.value)


def test_is_dir():
    assert Validator(os.path.dirname(__file__)).is_dir(
        exception_msg='path must be an existing directory')

    with pytest.raises(ValueError) as exc_info:
        Validator(__file__).is_dir(
            exception_msg='path must be an existing directory')
    assert "path must be an existing directory" in str(exc_info.value)


def test_is_method():
    assert Validator(print).is_method(exception_msg='value must be a callable method')

    with pytest.raises(ValueError) as exc_info:
        Validator("test").is_method(exception_msg='value must be a callable method')
    assert "value must be a callable method" in str(exc_info.value)

4、日志输出

执行 test 的日志如下,验证通过:


============================= test session starts =============================
collecting ... collected 24 items

test_validator.py::test_is_string PASSED                                 [  4%]
test_validator.py::test_is_int PASSED                                    [  8%]
test_validator.py::test_is_positive PASSED                               [ 12%]
test_validator.py::test_is_float PASSED                                  [ 16%]
test_validator.py::test_is_list PASSED                                   [ 20%]
test_validator.py::test_is_dict PASSED                                   [ 25%]
test_validator.py::test_is_set PASSED                                    [ 29%]
test_validator.py::test_is_tuple PASSED                                  [ 33%]
test_validator.py::test_is_not_none PASSED                               [ 37%]
test_validator.py::test_is_not_empty PASSED                              [ 41%]
test_validator.py::test_is_allowed_value PASSED                          [ 45%]
test_validator.py::test_is_specific_value PASSED                         [ 50%]
test_validator.py::test_max_length PASSED                                [ 54%]
test_validator.py::test_min_length PASSED                                [ 58%]
test_validator.py::test_is_substring PASSED                              [ 62%]
test_validator.py::test_is_subset PASSED                                 [ 66%]
test_validator.py::test_is_sublist PASSED                                [ 70%]
test_validator.py::test_contains_substring PASSED                        [ 75%]
test_validator.py::test_contains_subset PASSED                           [ 79%]
test_validator.py::test_contains_sublist PASSED                          [ 83%]
test_validator.py::test_is_file_suffix PASSED                            [ 87%]
test_validator.py::test_is_file PASSED                                   [ 91%]
test_validator.py::test_is_dir PASSED                                    [ 95%]
test_validator.py::test_is_method PASSED                                 [100%]

============================= 24 passed in 0.02s ==============================

三、后置说明

1、要点小结

  • is_string:检查参数是否为字符串。
  • is_int:检查参数是否为整数。
  • is_positive:检查参数是否为正数。
  • is_float:检查参数是否为浮点数。
  • is_list:检查参数是否为列表。
  • is_dict:检查参数是否为字典。
  • is_set:检查参数是否为集合。
  • is_tuple:检查参数是否为元组。
  • is_not_none:检查参数是否不为None。
  • is_not_empty:检查参数是否不为空(对于字符串、列表、字典、集合等)。
  • is_allowed_value:检查参数是否在指定的允许值范围内。
  • max_length:检查参数的长度是否不超过指定的最大值。
  • min_length:检查参数的长度是否不小于指定的最小值。
  • is_substring:检查参数是否为指定字符串的子串。
  • is_subset:检查参数是否为指定集合的子集。
  • is_sublist:检查参数是否为指定列表的子列表。
  • contains_substring:检查参数是否包含指定字符串。
  • contains_subset:检查参数是否包含指定集合。
  • contains_sublist:检查参数是否包含指定列表。
  • is_file:检查参数是否为有效的文件。
  • is_dir:检查参数是否为有效的目录。
  • is_file_suffix:检查参数是否以指定文件后缀结尾。
  • is_method:检查参数是否为可调用的方法(函数)。

注意:要将在 Validator 类中添加的方法,复制粘贴至 ParameterValidator 类中,方便 Pycharm 智能提示。

2、下节准备

  • 添加 自定义校验方法,让用户自定义校验规则

点击返回主目录

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

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

相关文章

Tomcat基础升华学习

01 What is Tomcat 1.1 Tomcat官网 官网 &#xff1a;https://tomcat.apache.org 1.2 Understand 为什么说Tomcat是Servlet之类技术的实现&#xff1f; 在我们的理解中&#xff0c;Tomcat可以称为Web容器或者Servlet容器 不妨通过手写一个Tomcat来推导一下 1.2.1 创建Tomc…

从Scroll怒喷社区用户事件,看L2龙头ZKFair的做事格局

这两天&#xff0c;随着美国SEC正式批准所有11只比特币现货ETF的消息公布&#xff0c;吸引了传统主流增量资金的入场&#xff0c;比特币多头一举将比特币干到了48000刀的位置&#xff0c;并随时向着前高发起了冲击。比特币的强势带动了其他加密资产的保障&#xff0c;整个加密市…

【计算机毕业设计】基于springboot的校园跑腿任务管理系统java+vue

校园跑腿管理系统又称“效率鸭”跑腿系统&#xff0c;是在学校进行现代化的信息管理和提供信息服务的基础&#xff0c;引导人们快速、准确地获取快递资源、预约洗浴并对外卖资源进行有效管理的保证。疫情当下&#xff0c;为了减少人员的聚集&#xff0c;因此&#xff0c;迫切需…

家用洗地机哪个品牌质量比较好?高配置洗地机推荐

近年来&#xff0c;科技飞速发展&#xff0c;推动了多个新兴行业的崛起&#xff0c;其中洗地机行业也在不断扩大。然而&#xff0c;随着市场的蓬勃发展&#xff0c;洗地机市场的产品质量参差不齐。在众多品牌中&#xff0c;真正致力于深入研究和创新的品牌相对较少。洗地机的问…

js封装根据年月日获取星座效果demo(整理)

//根据年月日获取星座 function getZodiacSign(dateString) {// 用法:const dateStr 2024-01-11;// const zodiacSign getZodiacSign(dateStr);const date new Date(dateString);const month date.getMonth() 1;const day date.getDate();if ((month 1 && day &…

32个图片素材库网站,有些直接免费商用!

划到最后“阅读原文”——领取工具包&#xff08;超过1000工具&#xff0c;免费素材网站分享和行业报告&#xff09; Hi&#xff0c;我是胡猛夫~&#xff0c;专注于分享各类价值网站、高效工具&#xff01; 更多内容&#xff0c;更多资源&#xff0c;欢迎交流&#xff01; 公 …

揭秘HTTP协议:深入了解互联网通信的核心!

文章目录 HTTPHTTP的消息结构HTTP 常用请求方法HTTP 状态码 HTTP HTTP 是超文本传输协议&#xff0c;HTTP是缩写&#xff0c;全称是 HyperText Transfer Protocol 超文本指的是 HTML、css、JavaScript和图片等&#xff0c;HTTP的出现就是为方便接收和发布超HTML页面&#xff0c…

多模态大模型

一、图文匹配 二、Stable-Diffusion(稳定扩散) 图片生成器 Stable-Diffusion(稳定扩散)组成模块: CrossAttention模块:将文本的语义信息与图像的语义信息进行Attention机制&#xff0c;增强输入文本Prompt对生成图片的控制。SelfAttention模块:SelfAttention模块的整体结构与C…

ES分词器

Analysis&#xff1a;文本分析是把全文本转换一系列单词的过程&#xff0c;也叫分词。Analysis是通过Analyzer(分词器)来实现的。 1.Analyzer组成 注意&#xff1a;在ES中默认使用标准分词器&#xff1a;StandardAnalyzer。特点是&#xff1a;中文是单字分词&#xff0c;英文是…

社区嵌入式服务设施建设为社区居家养老服务供给增加赋能

近年来&#xff0c;沈阳市浑南区委、区政府牢记在辽宁考察时的重要指示精神&#xff0c;认真践行以人民为中心的发展思想&#xff0c;聚集“一老一小”民生关切&#xff0c;统筹推进以社区为骨干结点的养老服务探索实践。围绕“品质养老”民生服务理念&#xff0c;针对社区老年…

验证端口连通性的工具 telent nc

验证端口连通性的工具 telent nc 1、怎么验证端口连通性的工具2、telnet3、nc 1、怎么验证端口连通性的工具 telent nc这2个工具都可以验证端口连通性 2、telnet 命令格式 默认是验证tcp端口连通性 telnet ip port如果需要验证udp端口连通性 需要加上 -u telnet -u ip por…

经典算法-模拟退火算法求解旅行商问题TSP

经典算法-模拟退火算法求解旅行商问题TSP 旅行商问题&#xff08;Traveling Salesman Problem, TSP&#xff09;是组合优化中的经典问题。简单地说&#xff0c;一个旅行商需要访问N个城市&#xff0c;并返回到出发城市&#xff0c;问题是找到最短的可能路线&#xff0c;使得每…

1045 - Access denied for user ‘root @223.98.184.126‘ (using password: YES)

Mysql 1045错误 1 知识小课堂1.1 Mysql 1045错误1.2 mysql 常见的错误代码 2 问题呈现3 问题解决3.1 开始前的准备3.1.1 防火墙开端口3.1.2 宝塔管理控制 3.2 问题解决步骤 Navicat 连接数据库的时候报错&#xff0c;本文就是解决此问题。 1 知识小课堂 1.1 Mysql 1045错误 …

sectigo通配符dv证书400元买一年送1月实际签发13个月

Sectigo就是众多颁发数字证书的CA认证机构之一&#xff0c;旗下的DV通配符SSL证书作为一种加密通信工具&#xff0c;广泛应用于保护网站数据的安全。其中&#xff0c;SectigoDV通配符SSL证书是一种受欢迎的产品&#xff0c;它不仅能够提供强大的加密功能&#xff0c;还可以提高…

OpenGl L6坐标系统

一.标准化设备坐标 我们在L5谈到了对顶点着色器中的点进行变换&#xff0c;而变换的范围必须在 -1.0到1.0 之间&#xff0c;否者将不可见。只有将所有的点转换为标准化设备坐标后&#xff0c;才能全部传入光栅器&#xff0c;再转换为屏幕上的像素。 将坐标变换为标准化设备坐标…

【C语言小游戏】贪吃蛇

文章目录 1.引言2.运行图2.涉及知识3 Windows API3.1 控制台3.2 控制台屏幕坐标3.3 操作句柄3.4 控制台屏幕光标3.5 监视按键 4. 设计说明5. 完整代码 1.引言 使⽤C语⾔在Windows环境的控制台中模拟实现经典⼩游戏贪吃蛇 实现基本的功能&#xff1a; 贪吃蛇地图绘制蛇吃⻝物的…

基于SpringBoot的洗衣店管理系统

基于SpringBoot的洗衣店管理系统的设计与实现~ 开发语言&#xff1a;Java数据库&#xff1a;MySQL技术&#xff1a;SpringBootMyBatis工具&#xff1a;IDEA/Ecilpse、Navicat、Maven 系统展示 登录界面 可视化展示 用户界面 管理员界面 摘要 洗衣店管理系统基于Spring Boot框…

LeetCode 38 外观数列

题目描述 外观数列 给定一个正整数 n &#xff0c;输出外观数列的第 n 项。 「外观数列」是一个整数序列&#xff0c;从数字 1 开始&#xff0c;序列中的每一项都是对前一项的描述。 你可以将其视作是由递归公式定义的数字字符串序列&#xff1a; countAndSay(1) "1…

09Bean的生命周期/作用域不同管理方式不同/自己new的对象纳入Spring容器管理

Spring其实就是一个管理Bean对象的工厂。它负责对象的创建&#xff0c;对象的销毁等。 所谓的生命周期就是&#xff1a;对象从创建开始到最终销毁的整个过程。 Bean的生命周期之5步 ● 第一步&#xff1a;实例化Bean(无参构造方法执行) ● 第二步&#xff1a;Bean属性赋值(注…

Swin Transformer 学习笔记(附代码)

论文地址&#xff1a;https://arxiv.org/pdf/2103.14030.pdf 代码地址&#xff1a; GitHub - microsoft/Swin-Transformer: This is an official implementation for "Swin Transformer: Hierarchical Vision Transformer using Shifted Windows". 1.是什么&#x…
最新文章