【SpringBoot】最基础的项目架构(SpringBoot+Mybatis-plus+lombok+knife4j+hutool)

汝之观览,吾之幸也! 从本文开始讲下项目中用到的一些框架和技术,最基本的框架使用的是SpringBoot(2.5.10)+Mybatis-plus(3.5.3.2)+lombok(1.18.28)+knife4j(3.0.3)+hutool(5.8.21),可以做到代码自动生成,满足最基本的增删查改。

一、新建SpringBoot项目

使用Idea工具直接创建项目
在这里插入图片描述

输入项目名称等
在这里插入图片描述

生成web项目
在这里插入图片描述

二、配置pom

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.10</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.mitool</groupId><artifactId>springboot</artifactId><version>0.0.1-SNAPSHOT</version><name>springboot</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><mybatis-plus.version>3.5.3.2</mybatis-plus.version><freemarker.version>2.3.29</freemarker.version><lombok.version>1.18.28</lombok.version><knife4j.version>3.0.3</knife4j.version><hutool.version>5.8.21</hutool.version><pagehelper.version>1.4.7</pagehelper.version><ali.cola.version>4.3.2</ali.cola.version><org.mapstruct.version>1.4.2.Final</org.mapstruct.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- mysql 链接--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><!-- mybatis-plus --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>${mybatis-plus.version}</version></dependency><!-- Mybatis-plus 代码生成器 依赖配置 --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>${mybatis-plus.version}</version><exclusions><exclusion><groupId>com.baomidou</groupId><artifactId>mybatis-plus-extension</artifactId></exclusion></exclusions></dependency><!--freemarker依赖--><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>${freemarker.version}</version></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version><scope>provided</scope></dependency><!-- knife4j --><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>${knife4j.version}</version></dependency><!-- hutool --><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool.version}</version></dependency><!-- pagehelper --><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>${pagehelper.version}</version></dependency><!-- 阿里cola --><dependency><groupId>com.alibaba.cola</groupId><artifactId>cola-component-dto</artifactId><version>${ali.cola.version}</version></dependency><dependency><groupId>org.mapstruct</groupId><artifactId>mapstruct</artifactId><version>${org.mapstruct.version}</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><annotationProcessorPaths><path><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></path><path><groupId>org.mapstruct</groupId><artifactId>mapstruct-processor</artifactId><version>${org.mapstruct.version}</version></path></annotationProcessorPaths></configuration></plugin></plugins></build></project>

三、配置application.properties

1、配置application.properties

配置application.properties文件,文件中包含数据库配置、knife4j配置

# 应用名称
spring.application.name=spring-demo
# 开发环境设置
spring.profiles.active=dev
# 应用路径
server.servlet.context-path=/springboot
# 编码字符集
server.servlet.encoding.charset=utf-8
# swagger
knife4j.enable=true
knife4j.production=false
knife4j.basic.enable=false

2、配置application-dev.properties

配置数据库,
localhost:数据库IP
db_source:数据库名称
username:用户名
password:密码

# 端口
server.port=9900
spring.datasource.url=jdbc:mysql://localhost:3306/db_source?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver# SSO
zsc.open.token.check=false

四、新建代码生成工具类 CodeGeneratorUtil

package com.mitool.springboot.utils;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.InjectionConfig;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import lombok.extern.slf4j.Slf4j;import java.util.Arrays;
import java.util.Scanner;/*** <p>Title: CodeGeneratorUtil</p>* <p>Description:* 描述:mybatis-plus 自动生成代码工具类* </p>** @author Jimmy.Shen* @version v1.0.0* @since 2022-10-19 9:58*/
@Slf4j
public class CodeGeneratorUtil {/*** 表前缀*/private static final String[] PREFIX = new String[]{"illp_", "t_"};/*** 是否生成controller、service、serviceImpl、converter*/private static final boolean ONLY_UPDATE_COLUMNS = true;/*** 数据源配置*/private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig.Builder("jdbc:mysql://10.10.177.151:3309/smart_park?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true","root", "ztesoft");/*** 读取控制台内容*/public static String scanner(String tip) {Scanner scanner = new Scanner(System.in);log.info("### 请输入" + tip);if (scanner.hasNext()) {String ipt = scanner.next();if (StrUtil.isNotEmpty(ipt)) {return ipt;}}throw new MybatisPlusException("请输入正确的" + tip + "!");}public static void main(String[] args) {String projectPath = System.getProperty("user.dir");String outputDir = projectPath + "/springboot/src/main/java/";String[] scannerArr = scanner("作者名,包名,表名").split(",");String authorName = scannerArr[0];String packageName = scannerArr[1];String tableName = scannerArr[2];// 规定代码路径,如果代码在不同项目中可进行调整String controllerName =projectPath + "/springboot/src/main/java/com/mitool/springboot/controller/" + packageName;String serviceName =projectPath + "/springboot/src/main/java/com/mitool/springboot/service/" + packageName;String serviceImplName =projectPath + "/springboot/src/main/java/com/mitool/springboot/service/" + packageName + "/impl/";String entityName =projectPath + "/springboot/src/main/java/com/mitool/springboot/entity/dataobject/" + packageName;String mapperName =projectPath + "/springboot/src/main/java/com/mitool/springboot/mapper/" + packageName;String mapperXmlName =projectPath + "/springboot/src/main/resources/mybatis-mapper/" + packageName;String voName =projectPath + "/springboot/src/main/java/com/mitool/springboot/entity/vo/" + packageName;String converterName =projectPath + "/springboot/src/main/java/com/mitool/springboot/converter/" + packageName;FastAutoGenerator.create(DATA_SOURCE_CONFIG)// 全局配置.globalConfig(builder ->//作者名builder.author(authorName)// 开启 swagger 模式	默认值:false.enableSwagger()// 禁止打开输出目录	默认值:true.disableOpenDir()// 指定输出目录.outputDir(outputDir)).packageConfig(builder -> builder.moduleName(packageName)).injectionConfig(builder -> {updateColumn(entityName, mapperName, mapperXmlName, voName, builder);if (ONLY_UPDATE_COLUMNS) {updateTemplate(controllerName, serviceName, serviceImplName, converterName, builder);}})//具体的生成文件的策略配置.strategyConfig(builder -> {builder.addInclude(tableName.split("#"))// .enableSkipView().addTablePrefix(Arrays.asList(PREFIX)).entityBuilder().enableFileOverride().enableLombok()// // controller.controllerBuilder().enableRestStyle().formatFileName("%sController").enableFileOverride()// service.serviceBuilder().superServiceClass(IService.class).formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImpl").enableFileOverride()//开启生成mapper.mapperBuilder().enableBaseResultMap().enableBaseColumnList().superClass(BaseMapper.class).formatMapperFileName("%sMapper").formatXmlFileName("%sXml").enableFileOverride();})//模板配置,如果你没有自定义的一些模板配置,这里直接使用默认即可。.templateConfig(config -> config.entity("/templates/entity.java"))//模板引擎配置.templateEngine(new FreemarkerTemplateEngine()).execute();// 删除生成的自带的 baomidou代码FileUtil.del(projectPath + "/springboot/src/main/java/com/baomidou");}private static void updateColumn(String entityName, String mapperName, String mapperXmlName, String voName, InjectionConfig.Builder builder) {builder.customFile(consumer -> consumer.fileName("DO.java").filePath(entityName).enableFileOverride().templatePath("/templates/entity.java.ftl"));builder.customFile(consumer -> consumer.fileName("Mapper.java").filePath(mapperName).enableFileOverride().templatePath("/templates/mapper.java.ftl"));builder.customFile(consumer -> consumer.fileName("Mapper.xml").filePath(mapperXmlName).enableFileOverride().templatePath("/templates/mapper.xml.ftl"));builder.customFile(consumer -> consumer.fileName("VO.java").filePath(voName).enableFileOverride().templatePath("/templates/vo.java.ftl"));}private static void updateTemplate(String controllerName,String serviceName, String serviceImplName,String converterName, InjectionConfig.Builder builder) {builder.customFile(consumer -> consumer.fileName("Controller.java").filePath(controllerName).enableFileOverride().templatePath("/templates/controller.java.ftl"));builder.customFile(consumer -> consumer.fileName("Service.java").filePath(serviceName).enableFileOverride().templatePath("/templates/service.java.ftl"));builder.customFile(consumer -> consumer.fileName("ServiceImpl.java").filePath(serviceImplName).enableFileOverride().templatePath("/templates/serviceImpl.java.ftl"));builder.customFile(consumer -> consumer.fileName("AppConverter.java").filePath(converterName).enableFileOverride().templatePath("/templates/converter.java.ftl"));}}

五、模板(FreemarkerTemplate)

模板文件放在resource/templates下

1、controller.java.ftl

package com.mitool.springboot.controller.${package.ModuleName};import com.mitool.springboot.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.mitool.springboot.service.${package.ModuleName}.${table.serviceName};
import com.mitool.springboot.entity.dataobject.${package.ModuleName}.${entity}DO;
import com.mitool.springboot.entity.vo.${package.ModuleName}.${entity}VO;
import com.mitool.springboot.converter.${package.ModuleName}.${entity}AppConverter;
import com.alibaba.cola.dto.SingleResponse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
<#if superControllerClassPackage??>import ${superControllerClassPackage};
</#if>
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* ${table.comment!} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
*/
@Slf4j
@RestController
@RequestMapping("/api/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Api(value = "${table.comment!}", tags = "${table.comment!} 管理模块")
<#if superControllerClass??>public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>@Resourceprivate ${table.serviceName} service;@Resourceprivate ${entity}AppConverter converter;@ApiOperation(value = "${table.comment!}分页查询", notes = "${table.comment!}分页查询")@GetMapping("/page")public SingleResponse<?> page(@RequestParam Integer pageIndex, @RequestParam Integer pageSize) {PageHelper.startPage(pageIndex, pageSize);List<${entity}DO> list = service.list();return SingleResponse.of(PageUtil.pageInfoCopy(new PageInfo<>(list), ${entity}VO.class, converter::toValueObject));}@ApiOperation(value = "${table.comment!}列表查询", notes = "${table.comment!}列表查询")@GetMapping("/list")public SingleResponse<?> list() {List<${entity}DO> list = service.list();return SingleResponse.of(converter.toValueObject(list));}@ApiOperation(value = "${table.comment!}详情", notes = "${table.comment!}详情")@GetMapping("/detail")public SingleResponse<?> detail(@RequestParam Integer id) {return SingleResponse.of(converter.toValueObject(service.getById(id)));}@ApiOperation("新增")@PostMapping("/save")public SingleResponse<?> save(@RequestBody ${entity}VO param) {${entity}DO dataObject = converter.toDataObject(param);service.save(dataObject);return SingleResponse.buildSuccess();}@ApiOperation("更新")@PostMapping("/update")public SingleResponse<?> update(@RequestBody ${entity}VO param) {${entity}DO dataObject = converter.toDataObject(param);service.updateById(dataObject);return SingleResponse.buildSuccess();}@ApiOperation("删除")@PostMapping("/remove")public SingleResponse<?> remove(@RequestBody ${entity}VO param) {service.removeById(param.getId());return SingleResponse.buildSuccess();}
}

2、converter.java.ftl

package com.mitool.springboot.converter.${package.ModuleName};import com.mitool.springboot.entity.dataobject.${package.ModuleName}.${entity}DO;
import com.mitool.springboot.entity.vo.${package.ModuleName}.${entity}VO;import org.mapstruct.Mapper;import java.util.List;/*** <p>* ${table.comment!} app 模型转换服务* </p>** @author ${author}* @since ${date}*/
@Mapper(componentModel = "spring")
public interface ${entity}AppConverter {${entity}DO toDataObject(${entity}VO ${entity?uncap_first}VO);List<${entity}DO> toDataObject(List<${entity}VO> ${entity?uncap_first}VOList);${entity}VO toValueObject(${entity}DO ${entity?uncap_first}DO);List<${entity}VO> toValueObject(List<${entity}DO> ${entity?uncap_first}DOList);
}

3、entity.java.ftl

package com.mitool.springboot.entity.dataobject.${package.ModuleName};import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;import java.io.Serializable;
import java.time.LocalDateTime;/**
* <p>* Title:${entity}* </p>* <p>* Description:描述:${table.comment} 对象* </p>** @author ${author}* @version 1.0.0* @since ${date}
**/
@Data
@TableName("${table.name}")
public class ${entity}DO implements Serializable {private static final long serialVersionUID = 1L;
<#-- ----------  BEGIN 字段循环遍历  ---------->
<#list table.fields as field>/*** ${field.comment}*/<#if field.keyFlag><#assign keyPropertyName="${field.propertyName}"/>@TableId(value = "${field.name}", type = IdType.AUTO)</#if>private ${field.propertyType} ${field.propertyName};
</#list>
<#------------  END 字段循环遍历  ---------->
}

4、mapper.java.ftl

package com.mitool.springboot.mapper.${package.ModuleName};import com.mitool.springboot.entity.dataobject.${package.ModuleName}.${entity}DO;
import ${superMapperClassPackage};
<#if mapperAnnotationClass??>import ${mapperAnnotationClass.name};
</#if>
import org.apache.ibatis.annotations.Mapper;/**
* <p>* ${table.comment!} Mapper 接口* </p>** @author ${author}* @since ${date}*/
<#if mapperAnnotationClass??>
@${mapperAnnotationClass.simpleName}
</#if>
<#if kotlin>
interface ${table.mapperName} : ${superMapperClass}<${entity}DO>
<#else>
@Mapper
public interface ${table.mapperName} extends ${superMapperClass}<${entity}DO> {}
</#if>

5、mapper.xml.ftl

<?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.mitool.springboot.mapper.${package.ModuleName}.${table.mapperName}"><#if enableCache><!-- 开启二级缓存 --><cache type="${cacheClassName}"/></#if><!-- 通用查询映射结果 --><resultMap id="BaseResultMap"type="com.mitool.springboot.entity.dataobject.${package.ModuleName}.${entity}DO"><#list table.fields as field><#if field.keyFlag><#--生成主键排在第一位--><id column="${field.name}" property="${field.propertyName}"/></#if></#list><#list table.commonFields as field><#--生成公共字段 --><result column="${field.name}" property="${field.propertyName}"/></#list><#list table.fields as field><#if !field.keyFlag><#--生成普通字段 --><result column="${field.name}" property="${field.propertyName}" />
</#if>
</#list></resultMap><#if baseColumnList><!-- 通用查询结果列 --><sql id="Base_Column_List">
<#list table.commonFields as field>${field.columnName},
</#list>${table.fieldNames}</sql></#if>
</mapper>

6、service.java.ftl

package com.mitool.springboot.service.${package.ModuleName};import ${superServiceClassPackage};
import com.mitool.springboot.entity.dataobject.${package.ModuleName}.${entity}DO;/**
* <p>* ${table.comment!} 服务类* </p>
*
* @author ${author}
* @since ${date}
*/
<#if kotlin>
interface ${table.serviceName} : ${superServiceClass}<${entity}DO>
<#else>
public interface ${table.serviceName} extends ${superServiceClass}<${entity}DO> {}
</#if>

7、serviceImpl.java.ftl

package com.mitool.springboot.service.${package.ModuleName}.impl;import com.mitool.springboot.mapper.${package.ModuleName}.${table.mapperName};
import com.mitool.springboot.service.${package.ModuleName}.${table.serviceName};
import com.mitool.springboot.entity.dataobject.${package.ModuleName}.${entity}DO;
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;/**
* <p>* ${table.comment!} 服务实现类* </p>
*
* @author ${author}
* @since ${date}*/
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}DO>(), ${table.serviceName} {}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}DO> implements ${table.serviceName} {}
</#if>

8、vo.java.ftl

package com.mitool.springboot.entity.vo.${package.ModuleName};<#list table.importPackages as pkg><#if pkg?contains("baomidou")><#elseif pkg?contains("Serializable")><#else>
import ${pkg};</#if>
</#list>
import lombok.Data;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;/*** <p>* ${table.comment!} 请求模型* </p>** @author ${author}* @since ${date}*/
@ApiModel(value="${entity}对象", description="${table.comment!}")
@Data
public class ${entity}VO {<#-- ----------  BEGIN 字段循环遍历  ---------->
<#list table.fields as field><#if field.name != "is_delete"><#if field.keyFlag><#assign keyPropertyName="${field.propertyName}"/></#if><#if field.comment!?length gt 0>/*** ${field.comment}*/@ApiModelProperty(value = "${field.comment}")</#if>private ${field.propertyType} ${field.propertyName};</#if>
</#list>
<#------------  END 字段循环遍历  ---------->
}

六、用到的其他类 PageUtil

使用到了分页的工具类,放在utils目录下

package com.mitool.springboot.utils;import com.github.pagehelper.PageInfo;import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;/*** 分页工具类** @author Jimmy.Shen* @since 2021/11/26*/
public class PageUtil {/*** 通用pageInfo转换** @param sourcePageInfo 源数据* @param targetClass    目标类型* @param mapper         list转换方法* @param <T>            目标类型* @param <S>            源类型*/public static <T, S> PageInfo<T> pageInfoCopy(PageInfo<S> sourcePageInfo, Class<T> targetClass, Function<S, T> mapper) {PageInfo<T> respPageInfo = new PageInfo<>();respPageInfo.setPageNum(sourcePageInfo.getPageNum());respPageInfo.setPageSize(sourcePageInfo.getPageSize());respPageInfo.setSize(sourcePageInfo.getSize());respPageInfo.setStartRow(sourcePageInfo.getStartRow());respPageInfo.setEndRow(sourcePageInfo.getEndRow());respPageInfo.setPages(sourcePageInfo.getPages());respPageInfo.setPrePage(sourcePageInfo.getPrePage());respPageInfo.setNextPage(sourcePageInfo.getNextPage());respPageInfo.setIsFirstPage(sourcePageInfo.isIsFirstPage());respPageInfo.setIsLastPage(sourcePageInfo.isIsLastPage());respPageInfo.setHasPreviousPage(sourcePageInfo.isHasPreviousPage());respPageInfo.setHasNextPage(sourcePageInfo.isHasNextPage());respPageInfo.setNavigatePages(sourcePageInfo.getNavigatePages());respPageInfo.setNavigatepageNums(sourcePageInfo.getNavigatepageNums());respPageInfo.setNavigateFirstPage(sourcePageInfo.getNavigateFirstPage());respPageInfo.setNavigateLastPage(sourcePageInfo.getNavigateLastPage());respPageInfo.setTotal(sourcePageInfo.getTotal());List<T> pageList = sourcePageInfo.getList().stream().map(mapper).collect(Collectors.toList());respPageInfo.setList(pageList);return respPageInfo;}
}

七、运行 CodeGeneratorUtil main方法

输入作者、包、表名生成文件,启动项目后可生成代码
在这里插入图片描述
生成的项目架构
在这里插入图片描述
使用swagger查看
在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

在R中安装TensorFlow、TensorFlow_Probability、numpy(R与Python系列第二篇)

目录 前言&#xff1a; 1-安装tensorflow库 Step1: 下载R包tensorflow Step2&#xff1a;安装TensorFlow库 Step3&#xff1a;导入R中 2-安装tensorflow_probability库 Step1&#xff1a;下载R包&#xff1a;tfprobability Step2&#xff1a;安装TensorFlow Probability …

力扣2. 两数相加

2. 两数相加 给你两个 非空 的链表&#xff0c;表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的&#xff0c;并且每个节点只能存储 一位 数字。 请你将两个数相加&#xff0c;并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外&#xff0c;这两个…

水稻叶病害数据集(目标检测,yolo使用)

1.数据集文件夹 train文件夹&#xff08;44229张&#xff09;&#xff0c;test文件夹&#xff08;4741张&#xff09;&#xff0c;valid文件夹&#xff08;6000张&#xff09; 2.train文件夹展示 labels展示 标签txt展示 data.yaml文件展示 对数据集感兴趣的可以关注最后一行…

正则表达式 之 断言详解

正则表达式的先行断言和后行断言一共有 4 种形式&#xff1a; (?pattern) 零宽正向先行断言(zero-width positive lookahead assertion)(?!pattern) 零宽负向先行断言(zero-width negative lookahead assertion)(?<pattern) 零宽正向后行断言(zero-width positive lookb…

linux的文件系统,理解一切皆文件

1. 系统文件I/O 1.1 open #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); pathname: 要打开或创建的目标文件 flags: 打开文件时…

pytest自动化测试两种执行环境切换的解决方案

目录 一、痛点分析 方法一&#xff1a;Hook方法pytest_addoption注册命令行参数 1、Hook方法注解 2、使用方法 方法二&#xff1a;使用插件pytest-base-url进行命令行传参 一、痛点分析 在实际企业的项目中&#xff0c;自动化测试的代码往往需要在不同的环境中进行切换&am…

3环断链以及断链后的检测方法

3环断链以及断链后的方法 我们在3环注入代码很多时候会选择注入dll&#xff0c;因为纯粹的硬编码不方便写出大量功能&#xff0c;而且不容易维护所以很多时候我们会通过各种方式让我们的dll注入到目标地址空间中&#xff0c;其中有一些方式可以不需要我们自己对dll处理重定位而…

The Cherno——OpenGL

The Cherno——OpenGL 1. 欢迎来到OpenGL OpenGL是一种跨平台的图形接口&#xff08;API&#xff09;&#xff0c;就是一大堆我们能够调用的函数去做一些与图像相关的事情。特殊的是&#xff0c;OpenGL允许我们访问GPU&#xff08;Graphics Processing Unit 图像处理单元&…

java八股文面试[多线程]——AQS 详细介绍

线程同步除了Synchronized Volatile ReentranLock 之外&#xff0c;还有其他一些用来进行同步的机制。 AQS 简单介绍 AQS 的全称为&#xff08;AbstractQueuedSynchronizer&#xff09;&#xff0c;这个类在 java.util.concurrent.locks 包下面。 AQS 是一个用来构建锁和同步器…

Jmeter接口测试+压力测试

接口测试 Jmeter-http接口脚本 一般分五个步骤:&#xff08;1&#xff09;添加线程组 &#xff08;2&#xff09;添加http请求 &#xff08;3&#xff09;在http请求中写入接入url、路径、请求方式和参数 &#xff08;4&#xff09;添加查看结果树 &#xff08;5&#xff09;…

volatile 关键字 与 CPU cache line 的效率问题

分析&回答 Cache Line可以简单的理解为CPU Cache中的最小缓存单位。目前主流的CPU Cache的Cache Line大小都是64Bytes。假设我们有一个512字节的一级缓存&#xff0c;那么按照64B的缓存单位大小来算&#xff0c;这个一级缓存所能存放的缓存个数就是512/64 8个。具体参见下…

Grafana之魔法:揭秘数据可视化的艺术

在数据驱动的时代&#xff0c;如何有效地呈现和理解数据成为了每个组织和个人的核心任务。Grafana作为一个领先的开源数据可视化工具&#xff0c;为我们提供了强大的功能和灵活性。本文将深入探讨Grafana的魔法&#xff0c;以及它如何帮助我们更好地理解数据。 Grafana简介 G…