Spring Cloud - 代码生成器

news2024/9/20 5:41:43

1、代码生成器概述

        Spring Cloud 并没有提供类似于 Spring Data 中的“代码生成器”,因为它主要提供的是分布式系统中服务发现和配置管理的一套解决方案。如果你想要为你的微服务应用生成样板代码,你可能需要考虑使用其他工具或者方案,例如 Spring Roo 或者 MyBatis Generator。

        Spring Roo 是一个为 Spring 应用快速开发的工具,它提供了一套命令行接口和可视化界面来生成项目的各个组件,包括域对象、控制器、视图等。但是它的更新频率不高,并且不再活跃维护。

        MyBatis Generator 是一个 MyBatis 的代码生成器,它可以生成对应数据库表的实体类、Mapper接口和Mapper XML文件。虽然它不是专门为 Spring Cloud 设计,但它可以为你的微服务应用生成基础的数据访问层代码。

2、Mybatis Generator

2.1 基本概念

        MyBatis Generator是MyBatis的代码生成器,顾名思义,使用MyBatis Generator可以很方便的将一个数据库表(或多个表)生成可用于访问该表的MyBatis代码。

        MyBatis Generator能够简化大部分简单CRUD(创建、检索、更新、删除)的数据库操作。

2.2 建立公共库

        1、建议建立一个公共库,用与所有项目的代码的生成

<?xml version="1.0"?>
<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>
	<parent>
		<groupId>org.cloud</groupId>
		<artifactId>microserver</artifactId>
		<version>1.0.1</version>
	</parent>
	<artifactId>common</artifactId>
	<name>common</name>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-maven-plugin -->
		<dependency>
		    <groupId>org.mybatis.generator</groupId>
		    <artifactId>mybatis-generator-maven-plugin</artifactId>
		    <version>1.4.2</version>
		</dependency>
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
		</dependency>
		<!-- 补充mybatis缺少的JDBC-Type如postGis中的geometry类型
		https://mvnrepository.com/artifact/net.postgis/postgis-jdbc -->
		<dependency>
			<groupId>net.postgis</groupId>
			<artifactId>postgis-jdbc</artifactId>
			<version>2.5.1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
		<dependency>
		    <groupId>org.mybatis.spring.boot</groupId>
		    <artifactId>mybatis-spring-boot-starter</artifactId>
		    <version>3.0.3</version>
		</dependency>

		<dependency>
		    <groupId>com.github.pagehelper</groupId>
		    <artifactId>pagehelper-spring-boot-starter</artifactId>
		    <version>1.4.7</version>
		</dependency>
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

	</dependencies>
</project>

        2、公共库与建立独立项目步骤类似,只是需要将pom.xml中生成war包改成生成jar包,然后在子项目中引用,

        

2.3 引入Mybatis插件

        主要是在公共库中引入mybatis插件

<dependency>
	<groupId>org.mybatis.generator</groupId>
	<artifactId>mybatis-generator-maven-plugin</artifactId>
	<version>1.4.2</version>
</dependency>

 3、编写代码

3.1 代码备注生成代码

        生成MybatisCommentGenerator插件代码,主要用于生成备注,可根据自我需要进行修改

package org.cloud.utils;


import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.MergeConstants;
import org.mybatis.generator.config.PropertyRegistry;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Set;
 
public class MybatisCommentGenerator implements CommentGenerator {
    private Properties properties;
    private Properties systemPro;
    private boolean suppressDate;
    private boolean suppressAllComments;
    private String nowTime;
 
    public MybatisCommentGenerator() {
        super();
        properties = new Properties();
        systemPro = System.getProperties();
        suppressDate = false;
        suppressAllComments = false;
        nowTime = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
    }
 
 
    /**
     * 类的注释
     * @param innerClass
     * @param introspectedTable
     * @param markAsDoNotDelete
     */
    @Override
    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
        if (suppressAllComments) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        innerClass.addJavaDocLine("/**");
        sb.append(" * ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        innerClass.addJavaDocLine(sb.toString().replace("\n", " "));
        sb.setLength(0);
        sb.append(" * @author ");
        sb.append(systemPro.getProperty("user.name"));
        sb.append(" ");
        sb.append(nowTime);
        innerClass.addJavaDocLine(" */");
    }
 
    @Override
    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
        if (suppressAllComments) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        innerClass.addJavaDocLine("/**");
        sb.append(" * ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        sb.append(" ");
        sb.append(getDateString());
        innerClass.addJavaDocLine(sb.toString().replace("\n", " "));
        innerClass.addJavaDocLine(" */");
    }
 
    /**
     * 设置字段注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (suppressAllComments) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        field.addJavaDocLine("/**");
        sb.append(" * ");
        sb.append(introspectedColumn.getRemarks());
        field.addJavaDocLine(sb.toString().replace("\n", " "));
        field.addJavaDocLine(" */");
    }
 
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
        if (suppressAllComments) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        field.addJavaDocLine("/**");
        sb.append(" * ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        field.addJavaDocLine(sb.toString().replace("\n", " "));
        field.addJavaDocLine(" */");
    }
 
    /**
     * 设置setter方法注释
     */
    @Override
    public void addSetterComment(Method method, IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {
        if (suppressAllComments) {
            return;
        }
        method.addJavaDocLine("/**");
        StringBuilder sb = new StringBuilder();
        sb.append(" * ");
        sb.append(introspectedColumn.getRemarks());
        method.addJavaDocLine(sb.toString().replace("\n", " "));
        sb.setLength(0);
        sb.append(" * @author ");
        sb.append(systemPro.getProperty("user.name"));
        method.addJavaDocLine(sb.toString().replace("\n", " "));
        sb.setLength(0);
        if(suppressDate){
            sb.append(" * @date " + nowTime);
            method.addJavaDocLine(sb.toString().replace("\n", " "));
            sb.setLength(0);
        }
        Parameter parm = method.getParameters().get(0);
        sb.append(" * @param ");
        sb.append(parm.getName());
        sb.append(" ");
        sb.append(introspectedColumn.getRemarks());
        method.addJavaDocLine(sb.toString().replace("\n", " "));
        method.addJavaDocLine(" */");
    }
 
    /**
     * 设置getter方法注释
     */
    @Override
    public void addGetterComment(Method method, IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {
        if (suppressAllComments) {
            return;
        }
        method.addJavaDocLine("/**");
        StringBuilder sb = new StringBuilder();
        sb.append(" * ");
        sb.append(introspectedColumn.getRemarks());
        method.addJavaDocLine(sb.toString().replace("\n", " "));
        sb.setLength(0);
        sb.append(" * @author ");
        sb.append(systemPro.getProperty("user.name"));
        method.addJavaDocLine(sb.toString().replace("\n", " "));
        sb.setLength(0);
        if(suppressDate){
            sb.append(" * @date " + nowTime);
            method.addJavaDocLine(sb.toString().replace("\n", " "));
            sb.setLength(0);
        }
        sb.append(" * @return ");
        sb.append(introspectedColumn.getActualColumnName());
        sb.append(" ");
        sb.append(introspectedColumn.getRemarks());
        method.addJavaDocLine(sb.toString().replace("\n", " "));
        method.addJavaDocLine(" */");
    }
 
    @Override
    public void addJavaFileComment(CompilationUnit compilationUnit) {
        if (suppressAllComments) {
            return;
        }
        return;
    }
 
    @Override
    public void addComment(XmlElement xmlElement) {
        return;
    }
 
    @Override
    public void addRootComment(XmlElement rootElement) {
        return;
    }
 
    @Override
    public void addConfigurationProperties(Properties properties) {
        this.properties.putAll(properties);
        suppressDate = Boolean.valueOf(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE));
        suppressAllComments = Boolean.valueOf(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_ALL_COMMENTS));
    }
 
    protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete, String desc) {
        javaElement.addJavaDocLine(" * " + desc);
        StringBuilder sb = new StringBuilder();
        sb.append(" * ");
        sb.append(MergeConstants.NEW_ELEMENT_TAG);
        if (markAsDoNotDelete) {
            sb.append(" do_not_delete_during_merge");
        }
        String s = getDateString();
        if (s != null) {
            sb.append(' ');
            sb.append(s);
        }
        javaElement.addJavaDocLine(sb.toString());
    }
 
    protected String getDateString() {
        String result = null;
        if (!suppressDate) {
            result = nowTime;
        }
        return result;
    }
 
    @Override
    public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
        if (suppressAllComments) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        innerEnum.addJavaDocLine("/**");
        sb.append(" * ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        innerEnum.addJavaDocLine(sb.toString().replace("\n", " "));
        innerEnum.addJavaDocLine(" */");
    }
 
    @Override
    public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
        if (suppressAllComments) {
            return;
        }
        String methodName = method.getName();
        String descString = "";
        switch (methodName) {
		case "deleteByPrimaryKey":
			descString = "根据主键删除数据";
			break;
		case "insert":
			descString = "全值插入数据";
			break;
		case "insertSelective":
			descString = "非空插入数据";
			break;
		case "selectByExample":
			descString = "根据样例选择数据";
			break;
		case "selectByPrimaryKey":
			descString = "根据主键选择数据";
			break;
		case "updateByPrimaryKey":
			descString = "根据主键更新全部数据";
			break;
		case "updateByPrimaryKeySelective":
			descString = "根据主键更新部分数据";
			break;
		case "setOrderByClause":
			descString = "设置排序";
			break;
		case "getOrderByClause":
			descString = "获取排序";
			break;
		case "setDistinct":
			descString = "去除重复的结果";
			break;
		case "or":
			descString = "或者";
			break;
		case "createCriteria":
			descString = "创建查询条件";
			break;
		default:
			break;
		}
        method.addJavaDocLine("/**");
        addJavadocTag(method, false, descString);
        method.addJavaDocLine(" */");
    }


	@Override
	public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
		// TODO Auto-generated method stub
		String dateFormat = properties.getProperty("dateFormat", "yyyy-MM-dd");
        SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
 
        // 获取表注释
        String remarks = introspectedTable.getRemarks();
 
        topLevelClass.addJavaDocLine("/**");
        topLevelClass.addJavaDocLine(" * @Date:" + dateFormatter.format(new Date()));
        topLevelClass.addJavaDocLine(" * @Description:" + remarks);
        topLevelClass.addJavaDocLine(" */");
	}


	@Override
	public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable,
			Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable,
			IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable,
			Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable,
			IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable,
			Set<FullyQualifiedJavaType> imports) {
		// TODO Auto-generated method stub
		
	}
}

3.2 生成代码

        用于代码的生成

package org.cloud.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

public class CodeGenUtils {
	static public void genCode() {
		try {
			List<String> warnings = new ArrayList<String>();
	        boolean overwrite = true;
	        File configFile = new File("src/main/resources/mybatis-generator.xml");
	        ConfigurationParser cp = new ConfigurationParser(warnings);
	        Configuration config = cp.parseConfiguration(configFile);
	        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
	        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
	        myBatisGenerator.generate(null);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}

3.3 新建配置文件

        在需要生成代码的文件中,新建配置mybatis-generator.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <!--数据库驱动-->
    <classPathEntry location="E:\javaProject\repos\org\postgresql\postgresql\42.6.2\postgresql-42.6.2.jar"/>
    
    <context id="DB2Tables" targetRuntime="MyBatis3">
    	<!-- <commentGenerator>
		     <property name="suppressAllComments" value="false"/>
		     <property name="suppressDate" value="false"/>
		     此处为 true 时,生成的 Model 包含对应表字段注释
		     <property name="addRemarkComments" value="true"/>
		     此处为 true 时,生成的 Mapper 接口将增加 @Mapper 注解,Spring ComponentScan 时可自动识别
		      <property name="addMapperAnnotation" value="false"/>
		 </commentGenerator> -->
    	<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
        <commentGenerator type="org.cloud.utils.MybatisCommentGenerator">
            <property name="suppressAllComments" value="false"/>
            <property name="suppressDate" value="false"/>
            <property name="addRemarkComments" value="true"/>
        </commentGenerator>
        
        <!--数据库链接地址账号密码-->
        <jdbcConnection driverClass="org.postgresql.Driver" connectionURL="jdbc:postgresql://192.168.0.21:5432/permission" 
        	userId="postgres" password="postgres">
        	<property name="nullCatalogMeansCurrent" value="true"/>
        	<property name="remarksReporting" value="true"></property>
        </jdbcConnection>
        
        <javaTypeResolver>
        	<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->  
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成Model类存放位置-->
        <javaModelGenerator targetPackage="org.permission.entity" targetProject="./src/main/java">
         	<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
            <property name="enableSubPackages" value="false"/>
            <!-- 是否针对string类型的字段在set的时候进行trim调用 -->  
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="mapper" targetProject="./src/main/resources">
        	<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        <!--生成Dao类存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="org.permission.mapper" targetProject="./src/main/java">
            <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>
        <!--生成对应表及类名-->
        <!--<table tableName="big_table" domainObjectName="BigTable" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>-->
        <table schema=""
        		tableName="organization"
        		enableCountByExample="true" 
        		enableUpdateByExample="false" 
        		enableDeleteByExample="false" 
        		enableSelectByExample="true"
        		selectByExampleQueryId="false">
        		<property name="useActualColumnNames" value="false"/>
                <columnOverride column="extension" property="extension" jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
                  typeHandler="tianchen.cloud.handler.JsonTypeHandler"/>
        </table>
        <table schema=""
        		tableName="user_info"
        		enableCountByExample="true" 
        		enableUpdateByExample="false" 
        		enableDeleteByExample="false" 
        		enableSelectByExample="true"
        		selectByExampleQueryId="false">
        		<property name="useActualColumnNames" value="false"/>
                <columnOverride column="extension" property="extension" jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
                  typeHandler="tianchen.cloud.handler.JsonTypeHandler"/>
        </table>
        <table schema=""
        		tableName="user_role"
        		enableCountByExample="true" 
        		enableUpdateByExample="false" 
        		enableDeleteByExample="false" 
        		enableSelectByExample="true"
        		selectByExampleQueryId="false">
        		<property name="useActualColumnNames" value="false"/>
                <columnOverride column="extension" property="extension" jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
                  typeHandler="tianchen.cloud.handler.JsonTypeHandler"/>
        </table>
        <table schema=""
        		tableName="role"
        		enableCountByExample="true" 
        		enableUpdateByExample="false" 
        		enableDeleteByExample="false" 
        		enableSelectByExample="true"
        		selectByExampleQueryId="false">
        		<property name="useActualColumnNames" value="false"/>
                <columnOverride column="extension" property="extension" jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
                  typeHandler="tianchen.cloud.handler.JsonTypeHandler"/>
        </table>
        <table schema=""
        		tableName="permission"
        		enableCountByExample="true" 
        		enableUpdateByExample="false" 
        		enableDeleteByExample="false" 
        		enableSelectByExample="true"
        		selectByExampleQueryId="false">
        		<property name="useActualColumnNames" value="false"/>
                <columnOverride column="extension" property="extension" jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
                  typeHandler="tianchen.cloud.handler.JsonTypeHandler"/>
        </table>
        <table schema=""
        		tableName="permission_menu"
        		enableCountByExample="true" 
        		enableUpdateByExample="false" 
        		enableDeleteByExample="false" 
        		enableSelectByExample="true"
        		selectByExampleQueryId="false">
        		<property name="useActualColumnNames" value="false"/>
                <columnOverride column="extension" property="extension" jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
                  typeHandler="tianchen.cloud.handler.JsonTypeHandler"/>
        </table>
        <table schema=""
        		tableName="menu"
        		enableCountByExample="true" 
        		enableUpdateByExample="false" 
        		enableDeleteByExample="false" 
        		enableSelectByExample="true"
        		selectByExampleQueryId="false">
        		<property name="useActualColumnNames" value="false"/>
                <columnOverride column="extension" property="extension" jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
                  typeHandler="tianchen.cloud.handler.JsonTypeHandler"/>
                  
        </table>
    </context>
</generatorConfiguration>

3.4 编写生成代码

public class Test {
	public static void main(String[] args) {
        try {
        	CodeGenUtils.genCode();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

4、生成效果

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

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

相关文章

基于SSM的志愿者服务平台

基于SSM的志愿者服务平台系统主要其系统包括不同的端组成&#xff0c;前端主要包括系统用户管理、新闻数据管理、变幻图管理、志愿者管理、培训视频管理、志愿者项目管理、服务时长管理、交流分享管理、志愿者表彰管理。前台主要包括网站首页、培训视频、志愿者项目、交流分享、…

【python中级】图像从笛卡尔坐标系转换为极坐标系

【python中级】图像从笛卡尔坐标系转换为极坐标系 1.背景2.生成二维图3.极坐标转换1.背景 笛卡尔坐标系就是我们常说的直角坐标系。 笛卡尔坐标系,也称为直角坐标系,是由法国数学家和哲学家勒内笛卡尔(Ren Descartes)发明的一种二维或三维坐标系统。它使用两个或三个相互垂…

李彦宏: 开源模型是智商税|马斯克: OpenAI 闭源不如叫 CloseAI

在 2024 年世界人工智能大会&#xff08;WAIC 2024&#xff09;上&#xff0c;百度创始人、董事长兼首席执行官李彦宏发表对开源模型的评价。 李彦宏认为&#xff1a;开源模型实际上是一种智商税&#xff0c;而闭源模型才是人工智能&#xff08;AI&#xff09;行业的未来。 马…

基于LangChain的RAG开发教程(二)

v1.0官方文档&#xff1a;https://python.langchain.com/v0.1/docs/get_started/introduction/ 最新文档&#xff1a;https://python.langchain.com/v0.2/docs/introduction/ LangChain是一个能够利用大语言模型&#xff08;LLM&#xff0c;Large Language Model&#xff09;能…

git恢复到之前提交的记录

项目搞崩了&#xff0c;还提交上去了怎么办&#xff1f; 那当然是恢复到之前的提交记录了&#xff0c;那怎么操作呢&#xff1f; 首先&#xff0c;到代码托管平台找到你想恢复的提交记录(在此以github为例) 获取 commit id 首先&#xff0c;通过如下图操作获取到commit id {% a…

Spring Cloud: OpenFeign 超时重试机制

超时重试是一种用于网络通信的常用策略&#xff0c;目的是在请求未能在规定时间内获得响应或响应超时的情况下&#xff0c;重新发送请求。具体来说&#xff0c;当发起请求后&#xff0c;如果在设定的时间内未能收到预期的响应&#xff0c;就会启动超时重试机制&#xff0c;重新…

徒手绘制 Android 通用进度条

拖动条&#xff08;FlexSeekBar&#xff09;&#xff0c;在Android的各个地方都非常常用&#xff0c;本文旨在自研一套通用的进度条&#xff0c;非常适合车载App使用 样式如下&#xff1a; 使用示例 <!--默认用法--> <com.max.android.ui.seekbar.FlexSeekBarandroi…

python获取文件列表按照文件修改时间进行排序,默认按照文件名时间戳排序

python获取文件列表按照文件修改时间进行排序,默认按照文件名时间戳排序 1、流程 1、获取文件绝对路径下的所有文件 2、通过os.path.getmtime获取每个文件的修改时间,并与文件组成元组,方便后续排序 3、默认按照时间戳降序,否则按照按修改时间排序文件列表(从最晚到最早)…

Linux忘记密码重置root密码、重置普通用户密码

重启看到选项按e reboot 或 init 62、移动到Linux开头的行在末尾添加 rw init/bin/bash3、按下Ctrlx引导启动 mount -o remount,rw /输入命令回车更改密码,输入新密码&#xff0c;别用小键盘&#xff0c;容易出错 passwd输入两次校验&#xff0c;出现updated successfully就…

几何建模基础-样条曲线和样条曲面介绍

1.概念介绍 1.1 样条曲线的来源 样条的英语单词spline来源于可变形的样条工具&#xff0c;那是一种在造船和工程制图时用来画出光滑形状的工具&#xff1a;富有弹性的均匀细木条/金属条/有机玻璃条&#xff0c;它围绕着按指定位置放置的重物或者压铁做弹性弯曲&#xff0c;以…

SAPUI5基础知识12 - 应用程序描述符(manifest.json)

1. 背景 在SAPUI5中&#xff0c;manifest.json是一个配置文件&#xff0c;它包含了应用程序的所有配置信息。这个文件是SAPUI5应用程序的核心&#xff0c;它定义了应用程序的元数据&#xff0c;包括应用程序的名称、描述、版本、模型、路由等信息。 manifest.json的主要功能和…

如何使用Vue3创建在线三维模型展示?

本文由ScriptEcho平台提供技术支持 项目地址&#xff1a;传送门 代码相关的技术博客 代码应用场景介绍 本段代码使用 RoughJS 库在 HTML5 Canvas 上创建了手绘风格的图像&#xff0c;展示了 RoughJS 库的强大功能&#xff0c;可用于创建具有有机手绘外观的图形。 代码基本…

2024已过半,还没试过在vue3中使用ioc容器吗?

Vue3 已经非常强大和灵活了&#xff0c;为什么还要引入 IOC 容器呢&#xff1f;IOC 容器离不开 Class&#xff0c;那么我们就从 Class 谈起 Class的应用场景 一提起 Class&#xff0c;大家一定会想到这是 Vue 官方不再推荐的代码范式。其实&#xff0c;更确切的说&#xff0c…

基于Java+SpringMvc+Vue技术的实验室管理系统设计与实现

博主介绍&#xff1a;硕士研究生&#xff0c;专注于信息化技术领域开发与管理&#xff0c;会使用java、标准c/c等开发语言&#xff0c;以及毕业项目实战✌ 从事基于java BS架构、CS架构、c/c 编程工作近16年&#xff0c;拥有近12年的管理工作经验&#xff0c;拥有较丰富的技术架…

二次元转向SLG,B站游戏的破圈之困

文 | 螳螂观察 作者 | 夏至 2023年是B站游戏的滑铁卢&#xff0c;尽管这年B站的游戏营收还有40多亿&#xff0c;但相比去年大幅下降了20%&#xff0c;整整少了10亿&#xff0c;这是过去5年来的最大跌幅&#xff0c;也是陈睿接管B站游戏业务一年以来&#xff0c;在鼻子上碰的第…

[每周一更]-(第104期):Go中使用Makefile的经验

文章目录 1. 项目结构2. Makefile的基础知识什么是 Makefile 3. Go项目的Makefile示例4. 详细解释每个Makefile目标5. 使用Makefile执行常见任务 在Go项目中&#xff0c;使用Makefile可以简化和自动化常见的开发和部署任务&#xff0c;如编译、测试、格式化和清理。深入认识及实…

opencv 鱼眼图像的矫正(动态参数调整)

一&#xff1a;棋盘校准参数说明(内参) 棋盘校准的方法及代码很多&#xff0c;参见其他连接 1&#xff1a;内参矩阵 2&#xff1a;畸变系数 针对鱼眼相机此处是4个参数&#xff0c;在其校准代码中也可以知道&#xff0c;其通常的定义如下&#xff1a; data.camera_mat np.e…

Jenkins 强制杀job

有时候有的jenkins job运行时间太长&#xff0c;在jenkins界面点击x按钮进行abort&#xff0c;会失败&#xff1a; 这时候点击&#xff1a; “Click here to forcibly terminate running steps” 会进一步kill 任务&#xff0c;但是也还是有杀不掉的可能性。 终极武器是jenkin…

降Compose十八掌之『飞龙在天』| Layout

公众号「稀有猿诉」 原文链接 降Compose十八掌之『飞龙在天』| Layout 页面布局是GUI应用开发的核心&#xff0c;决定着一个UI具体如何实现。今天将延着路线图来练习『降Compose十八掌』的第二招式&#xff0c;学习一下如何使用Compose中的布局来构建页面。 基础骨架 基…

成长过程,摔倒不要紧,爬起来、改过、前进

无论何时何地&#xff0c;我们都有重头再来的能力&#xff0c;这份生生不息的力量来自天之灵根&#xff1b; 学习过程会有跌倒&#xff0c;这是很正常的节奏次序&#xff0c;不能掩盖自己的过失、自欺欺人&#xff0c;这不是过失&#xff0c;摔倒了就拍拍身上的灰尘&#xff…