springboot常用依赖及Utils2022年10月亲测都可以使用(实时更新)

目录

redis启动器

常用依赖,新手基本上都够用

thymeleaf

springsecurity

log4j

jsp解析依赖

swagger2依赖

加上两个Config

SwaggerConfig

knife4j依赖

MvcConfig

Shiro依赖

SpringSecurity依赖

MD5Util

StringUtils 和 DigestUtils 依赖

MybatisPlus和Mysql依赖

MySQL依赖

JWT依赖与Util

VUE基本格式

Servlet常用依赖

Mybatis

测试服务junit依赖


fastjson依赖



    com.alibaba
    fastjson
    1.2.66

redis启动器


       org.springframework.boot
       spring-boot-starter-data-redis

常用依赖,新手基本上都够用

thymeleaf

 ​

         
             org.thymeleaf.extras
             thymeleaf-extras-java8time
         
         
             org.thymeleaf
             thymeleaf-spring5
         
         
         

springsecurity

         
             org.springframework.security
             spring-security-web
         
         

log4j

        
            log4j
            log4j
            1.2.17
        
log4j.rootLogger = info,stdout

log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionPattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n

log4j.logger.com.sqlserver = DEBUG
log4j.logger.java.sql = DEBUG
log4j.logger.java.sql.Connection = DEBUG
log4j.logger.java.sql.Statement = DEBUG
log4j.logger.java.sql.PreparedStatement = DEBUG
log4j.logger.java.sql.ResultSet = DEBUG
log4j.logger.com.pacific.rspworkflow.dal.dao = DEBUG

jsp解析依赖

 ​
 ​
         
             org.apache.tomcat.embed
             tomcat-embed-jasper
         
 ​
         
             javax.servlet
             jstl
             1.2
         
 WebMvcConfigurer

swagger2依赖

 
    io.springfox
    springfox-swagger2
    2.9.2
 
 
    io.springfox
    springfox-swagger-ui
    2.9.2
 

在application配置文件中还需要添加这一行

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

加上两个Config

WebMvcConfigurer

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

    /**
     * 发现如果继承了WebMvcConfigurationSupport,则在yml中配置的相关内容会失效。 需要重新指定静态资源
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }

}

SwaggerConfig

 ​
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import springfox.documentation.builders.ApiInfoBuilder;
 import springfox.documentation.builders.PathSelectors;
 import springfox.documentation.builders.RequestHandlerSelectors;
 import springfox.documentation.service.ApiInfo;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 @Configuration
 @EnableSwagger2
 public class SwaggerConfig {
     @Bean
     public Docket createRestApi() {
         return new Docket(DocumentationType.SWAGGER_2)
                 .apiInfo(apiInfo())
                 .select()
                 .apis(RequestHandlerSelectors.basePackage("com.example"))
                 .paths(PathSelectors.any())
                 .build();
     }
     private ApiInfo apiInfo() {
         return new ApiInfoBuilder()
                 .title("")
                 .description("")
                 .termsOfServiceUrl("")
                 .contact("")
                 .version("1.0")
                 .build();
     }
 }

knife4j依赖

   
             com.github.xiaoymin
             knife4j-spring-boot-starter
             3.0.2
         
 ​

MvcConfig

 ​
 public class MvcConfig implements WebMvcConfigurer {
     /**
      * 静态资源访问路径映射
      */
     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
         registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
         registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
     }
     }
 ​

依赖:

 
         org.springframework.boot
         spring-boot-starter-web
 
 
         org.springframework.boot
         spring-boot-starter-aop
 
 
         org.springframework.boot
         spring-boot-configuration-processor
         true
 
 ​

Shiro依赖

		 
            org.apache.shiro
            shiro-spring
            1.7.1
        

SpringSecurity依赖

         
             org.springframework.boot
             spring-boot-starter-security
         

       

MD5Util


import java.security.MessageDigest;

public class MD5Util {

	public static String byteArrayToHexString(byte b[]) {
		StringBuffer resultSb = new StringBuffer();
		for (int i = 0; i < b.length; i++){
			resultSb.append(byteToHexString(b[i]));
		}
		return resultSb.toString();
	}

	private static String byteToHexString(byte b) {
		int n = b;
		if (n < 0) {
			n += 256;
		}
		int d1 = n / 16;
		int d2 = n % 16;
		return hexDigits[d1] + hexDigits[d2];
	}

	public static String MD5Encode(String origin, String charsetname) {
		String resultString = null;
		try {
			resultString = new String(origin);
			MessageDigest md = MessageDigest.getInstance("MD5");
			if (charsetname == null || "".equals(charsetname)) {
				resultString = byteArrayToHexString(md.digest(resultString.getBytes()));
			} else {
				resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname)));
			}
		} catch (Exception exception) {
		}
		return resultString;
	}

	private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
			"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };

}



StringUtils 和 DigestUtils 依赖

  
        
            commons-lang
            commons-lang
            2.6
        
        
            commons-codec
            commons-codec
            1.15
        

MybatisPlus和Mysql依赖

     
             com.baomidou
             mybatis-plus-boot-starter
             3.4.0
         
         
             mysql
             mysql-connector-java
         
 spring.datasource.url=jdbc:mysql://localhost:3306/blog?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=GMT
 spring.datasource.username=root
 spring.datasource.password=010213
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

MySQL依赖

    
         mysql
         mysql-connector-java
     

JWT依赖与Util

   
         io.jsonwebtoken
         jjwt
         0.9.1
     
 ​
 import io.jsonwebtoken.Jwt;
 import io.jsonwebtoken.JwtBuilder;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.SignatureAlgorithm;
 ​
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 ​
 public class JWTUtils {
 ​
     private static final String jwtToken = "123456Mszlu!@#$$";
 ​
     public static String createToken(Long userId){
         Map claims = new HashMap<>();
         claims.put("userId",userId);
         JwtBuilder jwtBuilder = Jwts.builder()
                 .signWith(SignatureAlgorithm.HS256, jwtToken) // 签发算法,秘钥为jwtToken
                 .setClaims(claims) // body数据,要唯一,自行设置
                 .setIssuedAt(new Date()) // 设置签发时间
                 .setExpiration(new Date(System.currentTimeMillis() + 24 * 60 * 60 * 60 * 1000));// 一天的有效时间
         String token = jwtBuilder.compact();
         return token;
     }
 ​
     public static Map checkToken(String token){
         try {
             Jwt parse = Jwts.parser().setSigningKey(jwtToken).parse(token);
             return (Map) parse.getBody();
         }catch (Exception e){
             e.printStackTrace();
         }
         return null;
 ​
     }
 ​
 }
 ​

VUE基本格式

 
 
 
     
     Title
 
 
 
 ​  
         

Servlet常用依赖


      javax.servlet
      javax.servlet-api
      3.1.0
    
    
    
      javax.servlet.jsp
      javax.servlet.jsp-api
      2.3.3
 

Mybatis

        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.0
        

application.properies配置:

mybatis.type-aliases-package=com.gao.security.bean
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

测试服务junit依赖

        
            junit
            junit
            4.12
            test
        

你可能感兴趣的:(技术栈学习,spring,boot,java,spring,后端,maven)