redis(10):spring+redis+mysql缓存实现

news2024/11/16 22:29:24

1 新建spring项目 

 

2 修改pom.xml

<?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.example</groupId>
    <artifactId>spring-redis-mysql</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <mybatis.version>3.5.2</mybatis.version>
        <mybatis-spring.version>2.0.2</mybatis-spring.version>
        <spring.version>4.3.24.RELEASE</spring.version>
        <druid.version>1.0.18</druid.version>
        <mysql.version>8.0.17</mysql.version>
        <fastjson.version>1.2.59</fastjson.version>
        <!-- 注意只能使用2.0以下的版本 -->
        <log4j.version>1.2.17</log4j.version>
        <jedis.version>3.1.0</jedis.version>
        <lombok.verison>1.18.10</lombok.verison>
    </properties>

    <dependencies>
        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <!-- mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatis-spring.version}</version>
        </dependency>
        <!-- 导入spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- mysql数据库驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- json -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <!-- log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>${jedis.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.verison}</version>
            <scope>provided</scope>
        </dependency>


    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.7.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

3 新建User类

package com.example.demo.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {
    /**
     * 用户编号
     */
    private Integer id;

    /**
     * 用户姓名
     */
    private String name;

    /**
     * 用户地址
     */
    private String address;

    /**
     * 出生时间
     */
    private Date birth;

    /**
     * 是否删除1删除0未删除
     */
    private Integer flag;

    private static final long serialVersionUID = 1L;
}

4 新建UserMapper

package com.example.demo.mapper;

import com.example.demo.domain.User;

import java.util.List;

public interface UserMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    List<User> queryAllUser();
}

5 生成UserMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.UserMapper">
    <resultMap id="BaseResultMap" type="com.example.demo.domain.User">
        <!--@mbg.generated-->
        <!--@Table sys_user-->
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="address" jdbcType="VARCHAR" property="address" />
        <result column="birth" jdbcType="TIMESTAMP" property="birth" />
        <result column="flag" jdbcType="INTEGER" property="flag" />
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id, `name`, address, birth, flag
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List" />
        from sys_user
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        <!--@mbg.generated-->
        delete from sys_user
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.example.demo.domain.User" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into sys_user (`name`, address, birth,
        flag)
        values (#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{birth,jdbcType=TIMESTAMP},
        #{flag,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.example.demo.domain.User" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into sys_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">
                `name`,
            </if>
            <if test="address != null">
                address,
            </if>
            <if test="birth != null">
                birth,
            </if>
            <if test="flag != null">
                flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                #{address,jdbcType=VARCHAR},
            </if>
            <if test="birth != null">
                #{birth,jdbcType=TIMESTAMP},
            </if>
            <if test="flag != null">
                #{flag,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.example.demo.domain.User">
        <!--@mbg.generated-->
        update sys_user
        <set>
            <if test="name != null">
                `name` = #{name,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                address = #{address,jdbcType=VARCHAR},
            </if>
            <if test="birth != null">
                birth = #{birth,jdbcType=TIMESTAMP},
            </if>
            <if test="flag != null">
                flag = #{flag,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.example.demo.domain.User">
        <!--@mbg.generated-->
        update sys_user
        set `name` = #{name,jdbcType=VARCHAR},
        address = #{address,jdbcType=VARCHAR},
        birth = #{birth,jdbcType=TIMESTAMP},
        flag = #{flag,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <select id="queryAllUser"  resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List" />
        from sys_user
    </select>
</mapper>

6 生成UserService

package com.example.demo.service;

import com.example.demo.domain.User;

import java.util.List;

public interface UserService{

    int deleteByPrimaryKey(Integer id);

    User insert(User user);


    User selectByPrimaryKey(Integer id);


    User updateByPrimaryKey(User user);

    List<User> queryAllUser();

}

7 生成UserServiceImpl

package com.example.demo.service.impl;


import com.example.demo.domain.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public int deleteByPrimaryKey(Integer id) {
        return this.userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public User insert(User user) {
        this.userMapper.insert(user);
        return user;
    }

    @Override
    public User selectByPrimaryKey(Integer id) {
        return this.userMapper.selectByPrimaryKey(id);
    }

    @Override
    public User updateByPrimaryKey(User user) {
        int index = this.userMapper.updateByPrimaryKey(user);
        return user;
    }

    @Override
    public List<User> queryAllUser() {
        return this.userMapper.queryAllUser();
    }
}

8 创建application-redis.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--声明配置-->
    <bean id="poolConfig" class="org.apache.commons.pool2.impl.GenericObjectPoolConfig">
        <property name="maxTotal" value="100"></property>
        <property name="maxIdle" value="80"></property>
        <property name="minIdle" value="20"></property>
        <property name="maxWaitMillis" value="2000"></property>
        <property name="testOnBorrow" value="true"></property>
    </bean>


    <!--jedispool-->
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <!--因为JedisPool没有属性  所以只能使用构造器的注入方式-->
        <constructor-arg name="poolConfig" ref="poolConfig"></constructor-arg>
        <constructor-arg name="host" value="192.168.222.131"></constructor-arg>
        <constructor-arg name="port" value="6379"></constructor-arg>
        <constructor-arg name="timeout" value="2000"></constructor-arg>
        <constructor-arg name="password" value="123456"></constructor-arg>
    </bean>



</beans>

9 创建application-dao.xml

<?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:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- 引入db.properties -->
    <context:property-placeholder
            location="classpath*:db.properties" system-properties-mode="FALLBACK" />

    <!-- 声明dataSource -->
    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <!-- 注入连接属性 -->
        <property name="driverClassName" value="${driverClassName}"></property>
        <property name="url" value="${url}"></property>
        <property name="username" value="${username}"></property>
        <property name="password" value="${password}"></property>
    </bean>
    <!-- 声明sessionFactory 并注入mybatis.cfg.xml -->
    <bean id="sqlSessionFactory"
          class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据源 -->
        <property name="dataSource" ref="dataSource"></property>
        <!-- 注入mapper.xml -->
        <property name="mapperLocations">
            <array>
                <value>classpath:mapper/*Mapper.xml</value>
            </array>
        </property>
    </bean>

    <!-- 扫描mapper接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 注入mapper接口所在的包 注意多个包的情况的配置 -->
        <property name="basePackage">
            <value>
                com.example.demo.mapper
            </value>
        </property>
        <!-- 注入sqlSessionFactory -->
        <property name="sqlSessionFactoryBeanName"
                  value="sqlSessionFactory"></property>
    </bean>
</beans>

10 创建application-service.xml

<?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:aop="http://www.springframework.org/schema/aop"
       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 http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:component-scan base-package="com.example.demo.service.impl"></context:component-scan>

    <!-- 1,声明事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!-- 启动注解事务 -->
    <!-- <tx:annotation-driven/> -->
    <!-- 2,声明事务的传播特性 也就是通知 -->
    <tx:advice id="advise" transaction-manager="transactionManager">
        <tx:attributes>
            <!-- 以add开头的方法名需要事务 -->
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="insert*" propagation="REQUIRED"/>
            <tx:method name="save*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="change*" propagation="REQUIRED"/>
            <tx:method name="reset*" propagation="REQUIRED"/>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="load*" read-only="true"/>
            <tx:method name="*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    <!-- 3进行AOP织入 -->
    <aop:config>
        <!-- 声明切面 -->
        <aop:pointcut expression="execution(* com.example.demo.service.impl.*.*(..))" id="pc"/>
        <!-- 织入 -->
        <aop:advisor advice-ref="advise" pointcut-ref="pc"/>
    </aop:config>
</beans>

11 创建CacheUserAspect

package com.example.demo.cache;

import com.alibaba.fastjson.JSON;
import com.example.demo.domain.User;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.io.Serializable;

@Component
@Aspect
@EnableAspectJAutoProxy
public class CacheUserAspect {


    private Log log= LogFactory.getLog(CacheUserAspect.class);

    public static final String POINTCUT_ADD="execution(* com.example.demo.service.impl.UserServiceImpl.insert(..))";
    public static final String POINTCUT_UPDATE="execution(* com.example.demo.service.impl.UserServiceImpl.updateByPrimaryKey(..))";
    public static final String POINTCUT_DELETE="execution(* com.example.demo.service.impl.UserServiceImpl.deleteByPrimaryKey(..))";
    public static final String POINTCUT_GETONE="execution(* com.example.demo.service.impl.UserServiceImpl.selectByPrimaryKey(..))";

    //redis里面的前缀
    public static final String PROFIX="user:";

    //注入JedisPool
    @Autowired
    private JedisPool jedisPool;



    @Around(value = CacheUserAspect.POINTCUT_ADD)
    public Object cacheAddUser(ProceedingJoinPoint pjp) throws Throwable {
        //插入数据库
        User user = (User) pjp.proceed();
        Jedis jedis = jedisPool.getResource();

        //把user转成json串
        String json= JSON.toJSONString(user);
        jedis.set(PROFIX+user.getId(),json);
        log.info(PROFIX+user.getId()+"数据已存入到Redis");
        jedis.close();
        return user;
    }

    @Around(value = CacheUserAspect.POINTCUT_UPDATE)
    public Object cacheUpdateUser(ProceedingJoinPoint pjp) throws Throwable {
        //修改数据库
        User user = (User) pjp.proceed();
        Jedis jedis = jedisPool.getResource();
        //把user转成json串
        String json= JSON.toJSONString(user);
        jedis.set(PROFIX+user.getId(),json);
        log.info(PROFIX+user.getId()+"数据已更新到Redis");
        jedis.close();
        return user;
    }

    @Around(value = CacheUserAspect.POINTCUT_DELETE)
    public Object cacheDeleteUser(ProceedingJoinPoint pjp) throws Throwable {
        //删除数据库
        Serializable id = (Serializable) pjp.getArgs()[0];
        log.info(PROFIX+id+"数据库数据已删除");
        Jedis jedis = jedisPool.getResource();
        if(jedis.exists(PROFIX+id)){
            jedis.del(PROFIX+id);
            log.info(PROFIX+id+"数据已从Redis删除");
        }
        jedis.close();
        return id;
    }

    @Around(value = CacheUserAspect.POINTCUT_GETONE)
    public Object cacheGetOneUser(ProceedingJoinPoint pjp) throws Throwable {
        Serializable id = (Serializable) pjp.getArgs()[0];
        if(null==id){
            return null;
        }
        Jedis jedis = jedisPool.getResource();
        String json = jedis.get(PROFIX + id);
        if(null!=json){
            User user=JSON.parseObject(json,User.class);
            log.info(PROFIX+id+"已从redis里机查询到数据");
            jedis.close();
            return user;
        }else{
            log.info(PROFIX+id+"缓存里面没有数据,要从数据库里面查询");
            User user= (User) pjp.proceed();
            if(null!=user){
                jedis.set(PROFIX+user.getId(),JSON.toJSONString(user));
                log.info(PROFIX+id+"数据已存入redis");
            }
            jedis.close();
            return  user;
        }
    }



}

12 创建application-cache.xml

<?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 http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.example.demo.cache"></context:component-scan>

</beans>

13 创建applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


    <import resource="classpath*:application-dao.xml"></import>
    <import resource="classpath*:application-service.xml"></import>
    <import resource="classpath*:application-redis.xml"></import>
    <import resource="classpath*:application-cache.xml"></import>


</beans>

14 TestApp测试类

package com.example.demo.test;

import com.example.demo.domain.User;
import com.example.demo.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;
import java.util.List;

public class TestApp {
    public static void main(String[] args) {
        ApplicationContext context=new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        UserService userService = context.getBean(UserService.class);


        List<User> users = userService.queryAllUser();
        for (User user : users) {
            System.out.println(user);
        }
        User user=new User();
        user.setName("xiaoqiang");
        user.setAddress("bj");
        user.setBirth(new Date());
        user.setFlag(0);
        userService.insert(user);

//        User user = userService.selectByPrimaryKey(113);
//        System.out.println(user);
//        user.setName("xiaoming");
//        user.setAddress("wh");
//        userService.updateByPrimaryKey(user);

        
//        userService.deleteByPrimaryKey(112);

        System.out.println("操作成功");

    }
}

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

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

相关文章

IOC学习笔记(上篇)

IOC学习笔记&#xff08;上篇&#xff09; 目录 IOC容器的职责Ioc容器的实现传统IoC容器的实现依赖查找VS依赖注入构造器注入VS Setter注入面试题 1. 什么是IOC&#xff1f;2. 依赖查找和依赖注入的区别3. Spring作为IOC容器有什么优势 学习视频地址&#xff1a;https://ti…

10分钟搭建链路追踪平台

随着项目越来越多&#xff0c;相互调用越来越复杂&#xff0c;搭建一个可视化的链路追踪平台显得尤为重要&#xff0c;今天给大家介绍的是zipkin&#xff0c;一个轻量级的零侵入的链路追踪平台&#xff0c;看我怎么10分钟给大家搭建出来。 1&#xff0c;介绍 zipkin官网&…

Spring6——入门

文章目录 入门环境要求构建模块程序开发引入依赖创建java类创建配置文件创建测试类运行测试程序 程序分析启用Log4j2日志框架Log4j2日志概述引入Log4j2依赖加入日志配置文件测试使用日志 入门 环境要求 JDK&#xff1a;Java17&#xff08;Spring6要求JDK最低版本是Java17&…

简述centos7如何安装和配置nginx

Nginx&#xff08;发音为"engine x"&#xff09;是一个开源的高性能的 Web 服务器和反向代理服务器。它具有以下特点&#xff1a; 高性能&#xff1a;Nginx 采用事件驱动的异步架构&#xff0c;能够处理大量并发连接而不会占用过多的系统资源。它能够轻松应对高并发访…

1156. 单字符重复子串的最大长度;1497. 检查数组对是否可以被 k 整除;1510. 石子游戏 IV

1156. 单字符重复子串的最大长度 核心思想&#xff1a;利用滑动窗口text[i:j)&#xff0c;不断滑动&#xff0c;滑动窗口中装的是重复的单字符。枚举好窗口&#xff0c;然后看窗口装的字符等于多少个&#xff0c;如果个数小于总个数&#xff0c;说明我们至少可以使它增加1&…

7.25 作业

1.做一个登录界面 #include "widget.h"Widget::Widget(QWidget *parent): QWidget(parent) {this->setFixedSize(800,600);this->setWindowOpacity(0.9);this->setWindowTitle("登录");this->setWindowIcon(QIcon("E:\\hqyj\\Qt\\icon_h…

SystemVerilog 第2章:数据类型

在 Verilog中,初学者经常分不清reg和wire两者的区别。应该使用它们中哪一个来驱动端口?连接不同模块时又该如何做? Systemverilog对经典的reg数据类型进行了改进,使得它除了作为一个变量以外,还可以被连续赋值、门单元和模块所驱动。为了与寄存器类型相区别,这种改进的数据类…

Java连锁门诊医院HIS信息管理系统源码

Java连锁门诊医院HIS信息管理系统源码&#xff1a;SaaS运维平台多医院多机构多门诊入驻强大的电子病历完整开发文档 一、系统概述 ❉采用主流成熟技术&#xff0c;软件结构简洁、代码规范易阅读&#xff0c;SaaS应用&#xff0c;全浏览器访问前后端分离&#xff0c;多服务协同…

RocketMQ第一课-快速实战以及集群架构搭建

一、RocketMQ产品特点 1、RocketMQ介绍 ​ RocketMQ是阿里巴巴开源的一个消息中间件&#xff0c;在阿里内部历经了双十一等很多高并发场景的考验&#xff0c;能够处理亿万级别的消息。2016年开源后捐赠给Apache&#xff0c;现在是Apache的一个顶级项目。 ​ 早期阿里使用Act…

【如何训练一个中译英翻译器】LSTM机器翻译模型部署(三)

系列文章 【如何训练一个中译英翻译器】LSTM机器翻译seq2seq字符编码&#xff08;一&#xff09; 【如何训练一个中译英翻译器】LSTM机器翻译模型训练与保存&#xff08;二&#xff09; 【如何训练一个中译英翻译器】LSTM机器翻译模型部署&#xff08;三&#xff09; 目录 系列…

通过两种实现方式理解CANoe TC8 demo是如何判断接收的以太网报文里的字段的

假设有一个测试用例,需求是:编写一个测试用例,发送一条icmpv4 echo request报文给DUT,identifier字段设置为10。判断DUT能够回复icmpv4 echo reply报文,且identifier字段值为10。 实现:在canoe的simulation setup界面插入一个test节点,ip地址为:192.168.0.1,mac地址为…

Tensorflow学习

一、处理数据的结构 案例代码如下: import tensorflow.compat.v1 as tf tf.disable_v2_behavior() import numpy as np# create data x_data np.random.rand(100).astype(np.float32) y_data x_data*0.1 0.3# 创建结构(一维结构) Weights tf.Variable(tf.random.uniform(…

数据结构-顺序表各项功能的实现

文章目录 前言一、"SeqList.h"部分二、"SeqList.c"部分1.初始化2.销毁3.扩容及打印4.尾插及尾删5.头插及头删6.顺序表查找7.顺序表在pos位插入x8.顺序表删除low位置的数 三、"text.c"部分结语 前言 线性表是n个具有相同属性的有限数列&#xff0…

基于VUE3+Layui从头搭建通用后台管理系统(前端篇)五:后台主页功能实现上

一、本章内容 本章实现后台主页框架实现、菜单的动态加载及生产、tab组件与菜单绑定、菜单与路由绑定等,工具栏按钮等界面及对应功能实现。 1. 详细课程地址: 待发布 2. 源码下载地址: 待发布 二、界面预览

(六)springboot实战——springboot的启动流程分析

前言 本节内容我们主要介绍一下springboot的启动流程&#xff0c;它内部是如何实现启动加载的&#xff0c;启动过程中都做了哪些工作&#xff0c;这是我们比较关注的问题。 正文 SpringBootApplication启动类注解的解读 - SpringBootConfiguration&#xff1a;等同于Configu…

WPF实战学习笔记09-创建工作单元

创建工作单元 添加包 Microsoft.EntityFrameworkCore.AutoHistory A plugin for Microsoft.EntityFrameworkCore to support automatically recording data changes history. Microsoft.EntityFrameworkCore.UnitOfWork A plugin for Microsoft.EntityFrameworkCore to suppor…

【Docker 实用技巧】动态切换国内外源

目录 前言&#xff1a; 1、背景 2、ChatGPT 的方案 3、我的方案 3.1 本地构建 3.2 Github Action 构建 3.3 实际方案 前言&#xff1a; Docker 是一个非常流行的开发和部署平台&#xff0c;它可以帮助开发者快速构建、部署和管理应用程序。在使用 Docker 的过程中&…

聊聊STM32 ADC的话题

STM32 微控制器系列提供了多个模拟数字转换器&#xff08;ADC&#xff09;模块&#xff0c;用于实现模拟信号的采集和转换为数字信号。ADC 在很多应用中都是非常重要的&#xff0c;例如传感器数据采集、电压测量等。 在 STM32 中&#xff0c;ADC 可以通过 STM32HAL 库提供的函…

Unity游戏源码分享-3d机器人推箱子游戏

Unity游戏源码分享-3d机器人推箱子游戏 一个非常意思的3D游戏 工程地址&#xff1a;https://download.csdn.net/download/Highning0007/88098014

leetcode5. 最长回文子串(Manacher - java)

Manacher回文算法 leetcode5. 最长回文子串Manacher 算法 manacher 算法 leetcode5. 最长回文子串 给你一个字符串 s&#xff0c;找到 s 中最长的回文子串。 如果字符串的反序与原始字符串相同&#xff0c;则该字符串称为回文字符串。 示例 1&#xff1a; 输入&#xff1a;s “…