栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot常用依赖小全2022年1月亲测都可以使用(实时更新)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot常用依赖小全2022年1月亲测都可以使用(实时更新)

常用依赖,新手基本上都够用 thymeleaf
 ​
         
             org.thymeleaf.extras
             thymeleaf-extras-java8time
         
         
             org.thymeleaf
             thymeleaf-spring5
         
         
         

springsecurity
         
             org.springframework.security
             spring-security-web
         
         

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
 
 ​
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
         
         
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
 
 
 
 ​
 
 
 
 
 
 
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/719231.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号