随笔分类 - spring
摘要:引入jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> 声明验证策略 // 执行插入时的
阅读全文
摘要:springboot 中使用 1.静态定时任务 添加注解 @EnableScheduling 在使用需要定时任务的方法上添加 @Scheduled(cron = "0 0/1 * * * ?") 这里使用了cron表达式 @Scheduled 的参数 1、cron cron表达式 2、zone 设置
阅读全文
摘要:添加依赖 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.5</version> </dependency> <dependency> <g
阅读全文
摘要:循环依赖的Bean必须要是单例 依赖的双方不能全部都使用构造器注入对方(依赖方至少有一个不能使用构造器注入) 如果使用@Bean注入的bean有依赖的话 (至少有一个依赖不能使用方法参数注入) 尽量避免使用循环依赖
阅读全文
摘要:@ControllerAdvice @RestControllerAdvice //纯接口系统可以使用我的系统只有api接口 使用了RestControllerAdvice @RestControllerAdvice public class BaseExceptionHandler { priva
阅读全文
摘要:自定义AuthcInterceptor拦截器类 @Component @Order(value = 1) public class AuthcInterceptor implements HandlerInterceptor { @Override public boolean preHandle(
阅读全文
摘要:@EnableCaching //启动spring缓存注解 @Configuration public class RedisConfig { @Bean public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory
阅读全文
摘要:public static <T> T jsonToBean(String json,Class<T> tClass){ try { //可以转换单引号 mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,true); //键可以不用引号包
阅读全文
摘要:使用工具类处理调用 直接调用就不会走代理了 @Component public class SpringContextUtil implements ApplicationContextAware { // Spring应用上下文环境 private static ApplicationContex
阅读全文
摘要:引入 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <group
阅读全文
摘要:设置编码为utf-8 最好设置一下 我的刚开始没设置是正常的,换了台电脑就乱码了 Charset charset = StandardCharsets.UTF_8; @Bean public RestTemplate restTemplate(){ RestTemplate restTemplate
阅读全文
摘要:引入相关pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>
阅读全文
摘要:首先引入需要的pom <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring-boot-web-starter</artifactId> <version>1.4.1</version> </dependen
阅读全文
摘要:首先引入相关pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <group
阅读全文
摘要:首先需要引入pom 这里使用nacos注册中心 所以引入了nacos-client 使用zookeeper注册中心的话需要引入其相应的client <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-
阅读全文
摘要:使用idea新建springboot项目beetl-spring-boot-starter 首先添加pom依赖 packaging要设置为jar不能设置为pom<packaging>jar</packaging> <dependency> <groupId>org.springframework.b
阅读全文
摘要:实际项目跑起来无影响,但是看起来不太爽。 可以在dao类添加org.springframework.stereotype.Repository 注解 或者可以在service类中使用 javax.annotation.Resource(替换org.springframework.beans.fact
阅读全文
摘要:Spring MVC从3.0开始支持REST,而主要就是通过@PathVariable来处理请求参数和路径的映射。由于考虑到SEO的缘故,很多人喜欢把新闻的名称作为路径中的一部分去处理,这时候中文的名称就会遇到问题,没办法映射,这个是因为编码问题,只要到TOMCAT/conf下找到server.xm
阅读全文
摘要:在外键字段的get方法上加入@JsonIgnore
阅读全文