第十四章 : Spring Boot 整合spring-session,使用redis共享_springboot3 redis session-程序员宅基地

技术标签: spring boot  session共享  SpringBoot 高效的Java开发实践  分布式session  session redis  

第十四章 : Spring Boot 整合spring-session,使用redis共享

前沿

本文重点讲述:spring boot工程中使用spring-session机制进行安全认证,并且通过redis存储session,满足集群部署、分布式系统的session共享。

基于SPringBoot 2.3.2.RELEASE

背景

在传统单机web应用中,一般使用tomcat/jetty等web容器时,用户的session都是由容器管理。浏览器使用cookie中记录sessionId,容器根据sessionId判断用户是否存在会话session。这里的限制是,session存储在web容器中,被单台服务器容器管理。

但是网站主键演变,分布式应用和集群是趋势(提高性能)。此时用户的请求可能被负载分发至不同的服务器,此时传统的web容器管理用户会话session的方式即行不通。除非集群或者分布式web应用能够共享session,尽管tomcat等支持这样做。但是这样存在以下两点问题:

1、需要侵入web容器,提高问题的复杂
2、web容器之间共享session,集群机器之间势必要交互耦合

基于这些,必须提供新的可靠的集群分布式/集群session的解决方案,突破traditional-session单机限制(即web容器session方式,下面简称traditional-session),spring-session应用而生。

traditional-session和spring-session的区别

在这里插入图片描述

springboot-session 集成redis示例
  1. 添加依赖:在pom.xml文件中添加Spring Session Redis的依赖。
<dependency>  
    <groupId>org.springframework.session</groupId>  
    <artifactId>spring-session-data-redis</artifactId>  
</dependency>
<dependency>
            <groupId>io.lettuce</groupId>
            <artifactId>lettuce-core</artifactId>
</dependency>
        <!-- 对象池,使用redis时必须引入 -->
<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
</dependency>
  1. 配置Redis:在application.yaml文件中添加Redis的配置信息,包括Redis的地址、端口号、密码等。
server:
  port: 8080
  servlet:
    context-path: /
    # session超时时间 默认30分钟
    session:
      timeout: 30m
spring:
  session:
    store-type: redis
    redis:
      # 会话刷新模式
      flush-mode: immediate
      # 用于存储会话的键的命名空间
      namespace: "spring:session"
  redis:
    host: 192.168.92.105
    port: 6379
    password: foobared
    # 连接超时时间(记得添加单位,Duration)
    timeout: 10000ms
    # Redis默认情况下有16个分片,这里配置具体使用的分片
    # database: 0
    lettuce:
      pool:
        # 连接池最大连接数(使用负值表示没有限制) 默认 8
        max-active: 8
        # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1
        max-wait: -1ms
        # 连接池中的最大空闲连接 默认 8
        max-idle: 8
        # 连接池中的最小空闲连接 默认 0
        min-idle: 0
  1. 注解开启session功能:并使用@EnableRedisHttpSession注解开启session功能。同时,可以设置session的超时时间。

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
    
    @SpringBootApplication
    @EnableRedisHttpSession
    public class SpringbootDay09Application {
          
    
        public static void main(String[] args) {
          
            SpringApplication.run(SpringbootDay09Application.class, args);
        }
    
    }
    
  2. 创建Controller:在需要使用session的Controller中,注入HttpSession对象,并使用它来存储session数据。

    @RestController  
    public class SessionController {
            
        @Autowired  
        private HttpSession httpSession;  
        @GetMapping("/set")  
        public String set(String name, String value) {
            
            httpSession.setAttribute(name, value);  
            return "set " + name + "=" + value;  
        }  
        @GetMapping("/get")  
        public String get(String name) {
            
            return (String) httpSession.getAttribute(name);  
        }  
    }
    
  3. 测试:分别调用各应用接口,查看sessionId是否一致。同时,可以查看Redis缓存信息,缓存中的sessionId与接口返回信息一致。

    在这里插入图片描述

    在这里插入图片描述

spring-session特点与工作原理
特点

spring-session在无需绑定web容器的情况下提供对集群session的支持。并提供对以下情况的透明集成:

  1. HttpSession:容许替换web容器的HttpSession
  2. WebSocket:使用WebSocket通信时,提供Session的活跃
  3. WebSession:容许以应用中立的方式替换webflux的webSession
工作原理
spring-session分为以下核心模块:
  • SessionRepositoryFilter:Servlet规范中Filter的实现,用来切换HttpSession至Spring Session,包装

    HttpServletRequest和HttpServletResponse

  • HttpServerletRequestWrapperHttpServletResponseWrapperHttpSessionWrapper包装器:包装原有的HttpServletRequest、HttpServletResponse和Spring Session,实现切换Session和透明继承HttpSession的关键之所在

  • Session:Spring Session模块

  • SessionRepository:管理Spring Session的模块

  • HttpSessionStrategy:映射HttpRequest和HttpResponse到Session的策略

    在这里插入图片描述

  1. SessionRepositoryFilter

    SessionRepositoryFilter继承OncePerRequestFilter实现Filter

protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    
    // 设置SessionRepository至Request的属性中
        request.setAttribute(SESSION_REPOSITORY_ATTR, this.sessionRepository);
    // 包装原始HttpServletRequest至SessionRepositoryRequestWrapper
        SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper wrappedRequest = new SessionRepositoryFilter.SessionRepositoryRequestWrapper(request, response);
    // 包装原始HttpServletResponse响应至SessionRepositoryResponseWrapper
        SessionRepositoryFilter.SessionRepositoryResponseWrapper wrappedResponse = new SessionRepositoryFilter.SessionRepositoryResponseWrapper(wrappedRequest, response);

        try {
    
            filterChain.doFilter(wrappedRequest, wrappedResponse);
        } finally {
    
              // 提交session
            wrappedRequest.commitSession();
        }

    }

2、 SessionRepository

public interface SessionRepository<S extends Session> {
    
    S createSession();

    void save(S var1);

    S findById(String var1);

    void deleteById(String var1);
}

创建、保存、获取、删除Session的接口行为。根据Session的不同,分为很多种Session操作仓库。

在这里插入图片描述

当创建一个RedisSession,然后存储在Redis中时,RedisSession的存储细节如下:

spring:session:sessions:33fdd1b6-b496-4b33-9f7d-df96679d32fe
spring:session:sessions:expires:33fdd1b6-b496-4b33-9f7d-df96679d32fe
spring:session:expirations:1439245080000

Redis会为每个RedisSession存储三个k-v。

第一个:k-v用来存储Session的详细信息,包括Session的过期时间间隔、最近的访问时间、attributes等等。这个k的过期时间为Session的最大过期时间 + 5分钟。如果默认的最大过期时间为30分钟,则这个k的过期时间为35分钟
第二个:k-v用来表示Session在Redis中的过期,这个k-v不存储任何有用数据,只是表示Session过期而设置。这个k在Redis中的过期时间即为Session的过期时间间隔
第三个:k-v存储这个Session的id,是一个Set类型的Redis数据结构。这个k中的最后的1439245080000值是一个时间戳,根据这个Session过期时刻滚动至下一分钟而计算得出。

3、 Session

spring-session和tomcat中的Session的实现模式上有很大不同,tomcat中直接对HttpSession接口进行实现,而spring-session中则抽象出单独的Session层接口,让后再使用适配器模式将Session适配层Servlet规范中的HttpSession。spring-sesion中关于session的实现和适配整个UML类图如下:

在这里插入图片描述

MapSession的代码源码片段

public final class MapSession implements Session, Serializable {
    
    public static final int DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS = 1800;
    private String id;
    private final String originalId;
    private Map<String, Object> sessionAttrs;
    private Instant creationTime;
    private Instant lastAccessedTime;
    private Duration maxInactiveInterval;
    private static final long serialVersionUID = 7160779239673823561L;

    public MapSession() {
    
        this(generateId());
    }

    public MapSession(String id) {
    
        this.sessionAttrs = new HashMap();
        this.creationTime = Instant.now();
        this.lastAccessedTime = this.creationTime;
        this.maxInactiveInterval = Duration.ofSeconds(1800L);
        this.id = id;
        this.originalId = id;
    }

    public MapSession(Session session) {
    
        this.sessionAttrs = new HashMap();
        this.creationTime = Instant.now();
        this.lastAccessedTime = this.creationTime;
        this.maxInactiveInterval = Duration.ofSeconds(1800L);
        if (session == null) {
    
            throw new IllegalArgumentException("session cannot be null");
        } else {
    
            this.id = session.getId();
            this.originalId = this.id;
            this.sessionAttrs = new HashMap(session.getAttributeNames().size());
            Iterator var2 = session.getAttributeNames().iterator();

            while(var2.hasNext()) {
    
                String attrName = (String)var2.next();
                Object attrValue = session.getAttribute(attrName);
                if (attrValue != null) {
    
                    this.sessionAttrs.put(attrName, attrValue);
                }
            }

            this.lastAccessedTime = session.getLastAccessedTime();
            this.creationTime = session.getCreationTime();
            this.maxInactiveInterval = session.getMaxInactiveInterval();
        }
    }

    public void setLastAccessedTime(Instant lastAccessedTime) {
    
        this.lastAccessedTime = lastAccessedTime;
    }

    public Instant getCreationTime() {
    
        return this.creationTime;
    }

    public String getId() {
    
        return this.id;
    }

    public String getOriginalId() {
    
        return this.originalId;
    }

    public String changeSessionId() {
    
        String changedId = generateId();
        this.setId(changedId);
        return changedId;
    }

    public Instant getLastAccessedTime() {
    
        return this.lastAccessedTime;
    }

    public void setMaxInactiveInterval(Duration interval) {
    
        this.maxInactiveInterval = interval;
    }

    public Duration getMaxInactiveInterval() {
    
        return this.maxInactiveInterval;
    }

    public boolean isExpired() {
    
        return this.isExpired(Instant.now());
    }

    boolean isExpired(Instant now) {
    
        if (this.maxInactiveInterval.isNegative()) {
    
            return false;
        } else {
    
            return now.minus(this.maxInactiveInterval).compareTo(this.lastAccessedTime) >= 0;
        }
    }

    public <T> T getAttribute(String attributeName) {
    
        return this.sessionAttrs.get(attributeName);
    }

    public Set<String> getAttributeNames() {
    
        return new HashSet(this.sessionAttrs.keySet());
    }

    public void setAttribute(String attributeName, Object attributeValue) {
    
        if (attributeValue == null) {
    
            this.removeAttribute(attributeName);
        } else {
    
            this.sessionAttrs.put(attributeName, attributeValue);
        }

    }

    public void removeAttribute(String attributeName) {
    
        this.sessionAttrs.remove(attributeName);
    }

    public void setCreationTime(Instant creationTime) {
    
        this.creationTime = creationTime;
    }

    public void setId(String id) {
    
        this.id = id;
    }

    public boolean equals(Object obj) {
    
        return obj instanceof Session && this.id.equals(((Session)obj).getId());
    }

    public int hashCode() {
    
        return this.id.hashCode();
    }

    private static String generateId() {
    
        return UUID.randomUUID().toString();
    }
}

RedisSession的代码源码片段


    final class RedisSession implements Session {
    
        private final MapSession cached;
        private final Map<String, Object> delta = new HashMap();
        private boolean isNew;
        private String originalSessionId;

        RedisSession(MapSession cached, boolean isNew) {
    
            this.cached = cached;
            this.isNew = isNew;
            this.originalSessionId = cached.getId();
            if (this.isNew) {
    
                this.delta.put("creationTime", cached.getCreationTime().toEpochMilli());
                this.delta.put("maxInactiveInterval", (int)cached.getMaxInactiveInterval().getSeconds());
                this.delta.put("lastAccessedTime", cached.getLastAccessedTime().toEpochMilli());
            }

            if (this.isNew || RedisSessionRepository.this.saveMode == SaveMode.ALWAYS) {
    
                this.getAttributeNames().forEach((attributeName) -> {
    
                    this.delta.put(RedisSessionRepository.getAttributeKey(attributeName), cached.getAttribute(attributeName));
                });
            }

        }

        public String getId() {
    
            return this.cached.getId();
        }

        public String changeSessionId() {
    
            return this.cached.changeSessionId();
        }

        public <T> T getAttribute(String attributeName) {
    
            T attributeValue = this.cached.getAttribute(attributeName);
            if (attributeValue != null && RedisSessionRepository.this.saveMode.equals(SaveMode.ON_GET_ATTRIBUTE)) {
    
                this.delta.put(RedisSessionRepository.getAttributeKey(attributeName), attributeValue);
            }

            return attributeValue;
        }

        public Set<String> getAttributeNames() {
    
            return this.cached.getAttributeNames();
        }

        public void setAttribute(String attributeName, Object attributeValue) {
    
            this.cached.setAttribute(attributeName, attributeValue);
            this.delta.put(RedisSessionRepository.getAttributeKey(attributeName), attributeValue);
            this.flushIfRequired();
        }

        public void removeAttribute(String attributeName) {
    
            this.setAttribute(attributeName, (Object)null);
        }

        public Instant getCreationTime() {
    
            return this.cached.getCreationTime();
        }

        public void setLastAccessedTime(Instant lastAccessedTime) {
    
            this.cached.setLastAccessedTime(lastAccessedTime);
            this.delta.put("lastAccessedTime", this.getLastAccessedTime().toEpochMilli());
            this.flushIfRequired();
        }

        public Instant getLastAccessedTime() {
    
            return this.cached.getLastAccessedTime();
        }

        public void setMaxInactiveInterval(Duration interval) {
    
            this.cached.setMaxInactiveInterval(interval);
            this.delta.put("maxInactiveInterval", (int)this.getMaxInactiveInterval().getSeconds());
            this.flushIfRequired();
        }

        public Duration getMaxInactiveInterval() {
    
            return this.cached.getMaxInactiveInterval();
        }

        public boolean isExpired() {
    
            return this.cached.isExpired();
        }

        private void flushIfRequired() {
    
            if (RedisSessionRepository.this.flushMode == FlushMode.IMMEDIATE) {
    
                this.save();
            }

        }

        private boolean hasChangedSessionId() {
    
            return !this.getId().equals(this.originalSessionId);
        }

        private void save() {
    
            this.saveChangeSessionId();
            this.saveDelta();
            if (this.isNew) {
    
                this.isNew = false;
            }

        }

        private void saveChangeSessionId() {
    
            if (this.hasChangedSessionId()) {
    
                if (!this.isNew) {
    
                    String originalSessionIdKey = RedisSessionRepository.this.getSessionKey(this.originalSessionId);
                    String sessionIdKey = RedisSessionRepository.this.getSessionKey(this.getId());
                    RedisSessionRepository.this.sessionRedisOperations.rename(originalSessionIdKey, sessionIdKey);
                }

                this.originalSessionId = this.getId();
            }

        }

        private void saveDelta() {
    
            if (!this.delta.isEmpty()) {
    
                String key = RedisSessionRepository.this.getSessionKey(this.getId());
                RedisSessionRepository.this.sessionRedisOperations.opsForHash().putAll(key, new HashMap(this.delta));
                RedisSessionRepository.this.sessionRedisOperations.expireAt(key, Date.from(Instant.ofEpochMilli(this.getLastAccessedTime().toEpochMilli()).plusSeconds(this.getMaxInactiveInterval().getSeconds())));
                this.delta.clear();
            }
        }
    }
}

在RedisSession中有两个非常重要的成员属性:

cached:实际上是一个MapSession实例,用于做本地缓存,每次在getAttribute时无需从Redis中获取,主要为了improve性能
delta:用于跟踪变化数据,做持久化

4、SessionRepositoryRequestWrapper

对于开发人员获取HttpSession的api

HttpServletRequest request = ...;
HttpSession session = request.getSession(true);

在spring session中request的实际类型SessionRepositoryRequestWrapper。调用SessionRepositoryRequestWrapper的getSession方法会触发创建spring session,而非web容器的HttpSession。

SessionRepositoryRequestWrapper用来包装原始的HttpServletRequest实现HttpSession切换至Spring Session。是透明Spring Session透明集成HttpSession的关键。

SessionRepositoryRequestWrapper继承HttpServletRequestWrapper,在构造方法中将原有的HttpServletRequest通过调用super完成对HttpServletRequestWrapper中持有的HttpServletRequest初始化赋值,然后重写和session相关的方法。这样就保证SessionRepositoryRequestWrapper的其他方法调用都是使用原有的HttpServletRequest的数据,只有session相关的是重写的逻辑。

private final class SessionRepositoryRequestWrapper extends HttpServletRequestWrapper {
    
        private final HttpServletResponse response;
        private S requestedSession;
        private boolean requestedSessionCached;
        private String requestedSessionId;
        private Boolean requestedSessionIdValid;
        private boolean requestedSessionInvalidated;

        private SessionRepositoryRequestWrapper(HttpServletRequest request, HttpServletResponse response) {
    
            super(request);
            this.response = response;
        }

        private void commitSession() {
    
            SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper.HttpSessionWrapper wrappedSession = this.getCurrentSession();
            if (wrappedSession == null) {
    
                if (this.isInvalidateClientSession()) {
    
                    SessionRepositoryFilter.this.httpSessionIdResolver.expireSession(this, this.response);
                }
            } else {
    
                S session = wrappedSession.getSession();
                this.clearRequestedSessionCache();
                SessionRepositoryFilter.this.sessionRepository.save(session);
                String sessionId = session.getId();
                if (!this.isRequestedSessionIdValid() || !sessionId.equals(this.getRequestedSessionId())) {
    
                    SessionRepositoryFilter.this.httpSessionIdResolver.setSessionId(this, this.response, sessionId);
                }
            }

        }

        private SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper.HttpSessionWrapper getCurrentSession() {
    
            return (SessionRepositoryFilter.SessionRepositoryRequestWrapper.HttpSessionWrapper)this.getAttribute(SessionRepositoryFilter.CURRENT_SESSION_ATTR);
        }

        private void setCurrentSession(SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper.HttpSessionWrapper currentSession) {
    
            if (currentSession == null) {
    
                this.removeAttribute(SessionRepositoryFilter.CURRENT_SESSION_ATTR);
            } else {
    
                this.setAttribute(SessionRepositoryFilter.CURRENT_SESSION_ATTR, currentSession);
            }

        }

        public String changeSessionId() {
    
            HttpSession session = this.getSession(false);
            if (session == null) {
    
                throw new IllegalStateException("Cannot change session ID. There is no session associated with this request.");
            } else {
    
                return this.getCurrentSession().getSession().changeSessionId();
            }
        }

        public boolean isRequestedSessionIdValid() {
    
            if (this.requestedSessionIdValid == null) {
    
                S requestedSession = this.getRequestedSession();
                if (requestedSession != null) {
    
                    requestedSession.setLastAccessedTime(Instant.now());
                }

                return this.isRequestedSessionIdValid(requestedSession);
            } else {
    
                return this.requestedSessionIdValid;
            }
        }

        private boolean isRequestedSessionIdValid(S session) {
    
            if (this.requestedSessionIdValid == null) {
    
                this.requestedSessionIdValid = session != null;
            }

            return this.requestedSessionIdValid;
        }

        private boolean isInvalidateClientSession() {
    
            return this.getCurrentSession() == null && this.requestedSessionInvalidated;
        }

        public SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper.HttpSessionWrapper getSession(boolean create) {
    
            SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper.HttpSessionWrapper currentSession = this.getCurrentSession();
            if (currentSession != null) {
    
                return currentSession;
            } else {
    
                S requestedSession = this.getRequestedSession();
                if (requestedSession != null) {
    
                    if (this.getAttribute(SessionRepositoryFilter.INVALID_SESSION_ID_ATTR) == null) {
    
                        requestedSession.setLastAccessedTime(Instant.now());
                        this.requestedSessionIdValid = true;
                        currentSession = new SessionRepositoryFilter.SessionRepositoryRequestWrapper.HttpSessionWrapper(requestedSession, this.getServletContext());
                        currentSession.markNotNew();
                        this.setCurrentSession(currentSession);
                        return currentSession;
                    }
                } else {
    
                    if (SessionRepositoryFilter.SESSION_LOGGER.isDebugEnabled()) {
    
                        SessionRepositoryFilter.SESSION_LOGGER.debug("No session found by id: Caching result for getSession(false) for this HttpServletRequest.");
                    }

                    this.setAttribute(SessionRepositoryFilter.INVALID_SESSION_ID_ATTR, "true");
                }

                if (!create) {
    
                    return null;
                } else {
    
                    if (SessionRepositoryFilter.SESSION_LOGGER.isDebugEnabled()) {
    
                        SessionRepositoryFilter.SESSION_LOGGER.debug("A new session was created. To help you troubleshoot where the session was created we provided a StackTrace (this is not an error). You can prevent this from appearing by disabling DEBUG logging for " + SessionRepositoryFilter.SESSION_LOGGER_NAME, new RuntimeException("For debugging purposes only (not an error)"));
                    }

                    S session = SessionRepositoryFilter.this.sessionRepository.createSession();
                    session.setLastAccessedTime(Instant.now());
                    currentSession = new SessionRepositoryFilter.SessionRepositoryRequestWrapper.HttpSessionWrapper(session, this.getServletContext());
                    this.setCurrentSession(currentSession);
                    return currentSession;
                }
            }
        }

        public SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper.HttpSessionWrapper getSession() {
    
            return this.getSession(true);
        }

        public String getRequestedSessionId() {
    
            if (this.requestedSessionId == null) {
    
                this.getRequestedSession();
            }

            return this.requestedSessionId;
        }

        public RequestDispatcher getRequestDispatcher(String path) {
    
            RequestDispatcher requestDispatcher = super.getRequestDispatcher(path);
            return new SessionRepositoryFilter.SessionRepositoryRequestWrapper.SessionCommittingRequestDispatcher(requestDispatcher);
        }

        private S getRequestedSession() {
    
            if (!this.requestedSessionCached) {
    
                List<String> sessionIds = SessionRepositoryFilter.this.httpSessionIdResolver.resolveSessionIds(this);
                Iterator var2 = sessionIds.iterator();

                while(var2.hasNext()) {
    
                    String sessionId = (String)var2.next();
                    if (this.requestedSessionId == null) {
    
                        this.requestedSessionId = sessionId;
                    }

                    S session = SessionRepositoryFilter.this.sessionRepository.findById(sessionId);
                    if (session != null) {
    
                        this.requestedSession = session;
                        this.requestedSessionId = sessionId;
                        break;
                    }
                }

                this.requestedSessionCached = true;
            }

            return this.requestedSession;
        }

        private void clearRequestedSessionCache() {
    
            this.requestedSessionCached = false;
            this.requestedSession = null;
            this.requestedSessionId = null;
        }

        

5、 SessionRepositoryResponseWrapper

private final class SessionRepositoryResponseWrapper extends OnCommittedResponseWrapper {
    
        private final SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper request;

        SessionRepositoryResponseWrapper(SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper request, HttpServletResponse response) {
    
            super(response);
            if (request == null) {
    
                throw new IllegalArgumentException("request cannot be null");
            } else {
    
                this.request = request;
            }
        }

        protected void onResponseCommitted() {
    
            this.request.commitSession();
        }
    }



5、 SessionRepositoryResponseWrapper 

```java
private final class SessionRepositoryResponseWrapper extends OnCommittedResponseWrapper {
        private final SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper request;

        SessionRepositoryResponseWrapper(SessionRepositoryFilter<S>.SessionRepositoryRequestWrapper request, HttpServletResponse response) {
            super(response);
            if (request == null) {
                throw new IllegalArgumentException("request cannot be null");
            } else {
                this.request = request;
            }
        }

        protected void onResponseCommitted() {
            this.request.commitSession();
        }
    }

从注释上可以看出包装响应时为了:确保如果响应被提交session能够被保存。
在这里插入图片描述

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/RodJohnsonDoctor/article/details/134850198

智能推荐

攻防世界_难度8_happy_puzzle_攻防世界困难模式攻略图文-程序员宅基地

文章浏览阅读645次。这个肯定是末尾的IDAT了,因为IDAT必须要满了才会开始一下个IDAT,这个明显就是末尾的IDAT了。,对应下面的create_head()代码。,对应下面的create_tail()代码。不要考虑爆破,我已经试了一下,太多情况了。题目来源:UNCTF。_攻防世界困难模式攻略图文

达梦数据库的导出(备份)、导入_达梦数据库导入导出-程序员宅基地

文章浏览阅读2.9k次,点赞3次,收藏10次。偶尔会用到,记录、分享。1. 数据库导出1.1 切换到dmdba用户su - dmdba1.2 进入达梦数据库安装路径的bin目录,执行导库操作  导出语句:./dexp cwy_init/[email protected]:5236 file=cwy_init.dmp log=cwy_init_exp.log 注释:   cwy_init/init_123..._达梦数据库导入导出

js引入kindeditor富文本编辑器的使用_kindeditor.js-程序员宅基地

文章浏览阅读1.9k次。1. 在官网上下载KindEditor文件,可以删掉不需要要到的jsp,asp,asp.net和php文件夹。接着把文件夹放到项目文件目录下。2. 修改html文件,在页面引入js文件:<script type="text/javascript" src="./kindeditor/kindeditor-all.js"></script><script type="text/javascript" src="./kindeditor/lang/zh-CN.js"_kindeditor.js

STM32学习过程记录11——基于STM32G431CBU6硬件SPI+DMA的高效WS2812B控制方法-程序员宅基地

文章浏览阅读2.3k次,点赞6次,收藏14次。SPI的详情简介不必赘述。假设我们通过SPI发送0xAA,我们的数据线就会变为10101010,通过修改不同的内容,即可修改SPI中0和1的持续时间。比如0xF0即为前半周期为高电平,后半周期为低电平的状态。在SPI的通信模式中,CPHA配置会影响该实验,下图展示了不同采样位置的SPI时序图[1]。CPOL = 0,CPHA = 1:CLK空闲状态 = 低电平,数据在下降沿采样,并在上升沿移出CPOL = 0,CPHA = 0:CLK空闲状态 = 低电平,数据在上升沿采样,并在下降沿移出。_stm32g431cbu6

计算机网络-数据链路层_接收方收到链路层数据后,使用crc检验后,余数为0,说明链路层的传输时可靠传输-程序员宅基地

文章浏览阅读1.2k次,点赞2次,收藏8次。数据链路层习题自测问题1.数据链路(即逻辑链路)与链路(即物理链路)有何区别?“电路接通了”与”数据链路接通了”的区别何在?2.数据链路层中的链路控制包括哪些功能?试讨论数据链路层做成可靠的链路层有哪些优点和缺点。3.网络适配器的作用是什么?网络适配器工作在哪一层?4.数据链路层的三个基本问题(帧定界、透明传输和差错检测)为什么都必须加以解决?5.如果在数据链路层不进行帧定界,会发生什么问题?6.PPP协议的主要特点是什么?为什么PPP不使用帧的编号?PPP适用于什么情况?为什么PPP协议不_接收方收到链路层数据后,使用crc检验后,余数为0,说明链路层的传输时可靠传输

软件测试工程师移民加拿大_无证移民,未受过软件工程师的教育(第1部分)-程序员宅基地

文章浏览阅读587次。软件测试工程师移民加拿大 无证移民,未受过软件工程师的教育(第1部分) (Undocumented Immigrant With No Education to Software Engineer(Part 1))Before I start, I want you to please bear with me on the way I write, I have very little gen...

随便推点

Thinkpad X250 secure boot failed 启动失败问题解决_安装完系统提示secureboot failure-程序员宅基地

文章浏览阅读304次。Thinkpad X250笔记本电脑,装的是FreeBSD,进入BIOS修改虚拟化配置(其后可能是误设置了安全开机),保存退出后系统无法启动,显示:secure boot failed ,把自己惊出一身冷汗,因为这台笔记本刚好还没开始做备份.....根据错误提示,到bios里面去找相关配置,在Security里面找到了Secure Boot选项,发现果然被设置为Enabled,将其修改为Disabled ,再开机,终于正常启动了。_安装完系统提示secureboot failure

C++如何做字符串分割(5种方法)_c++ 字符串分割-程序员宅基地

文章浏览阅读10w+次,点赞93次,收藏352次。1、用strtok函数进行字符串分割原型: char *strtok(char *str, const char *delim);功能:分解字符串为一组字符串。参数说明:str为要分解的字符串,delim为分隔符字符串。返回值:从str开头开始的一个个被分割的串。当没有被分割的串时则返回NULL。其它:strtok函数线程不安全,可以使用strtok_r替代。示例://借助strtok实现split#include <string.h>#include <stdio.h&_c++ 字符串分割

2013第四届蓝桥杯 C/C++本科A组 真题答案解析_2013年第四届c a组蓝桥杯省赛真题解答-程序员宅基地

文章浏览阅读2.3k次。1 .高斯日记 大数学家高斯有个好习惯:无论如何都要记日记。他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?高斯出生于:1777年4月30日。在高斯发现的一个重要定理的日记_2013年第四届c a组蓝桥杯省赛真题解答

基于供需算法优化的核极限学习机(KELM)分类算法-程序员宅基地

文章浏览阅读851次,点赞17次,收藏22次。摘要:本文利用供需算法对核极限学习机(KELM)进行优化,并用于分类。

metasploitable2渗透测试_metasploitable2怎么进入-程序员宅基地

文章浏览阅读1.1k次。一、系统弱密码登录1、在kali上执行命令行telnet 192.168.26.1292、Login和password都输入msfadmin3、登录成功,进入系统4、测试如下:二、MySQL弱密码登录:1、在kali上执行mysql –h 192.168.26.129 –u root2、登录成功,进入MySQL系统3、测试效果:三、PostgreSQL弱密码登录1、在Kali上执行psql -h 192.168.26.129 –U post..._metasploitable2怎么进入

Python学习之路:从入门到精通的指南_python人工智能开发从入门到精通pdf-程序员宅基地

文章浏览阅读257次。本文将为初学者提供Python学习的详细指南,从Python的历史、基础语法和数据类型到面向对象编程、模块和库的使用。通过本文,您将能够掌握Python编程的核心概念,为今后的编程学习和实践打下坚实基础。_python人工智能开发从入门到精通pdf

推荐文章

热门文章

相关标签