![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
代码小技巧
多么温暖的阳光啊
这个作者很懒,什么都没留下…
展开
-
【代码小技巧】加载classpath下的文件资源
加载classpath下的文件资源 方式1: Class.getResourceAsStream(name) 指定要加载的资源路径与当前类所在包的路径一致, 如果这个name是以 '/'开头的,那么就会从classpath的根路径下开始查找 private void loadResource() { try (InputStream inputStream = this.getClass().getResourceAsStream("/" + FILE_NAME);) { String stri原创 2021-04-01 15:05:31 · 712 阅读 · 0 评论 -
Spring小细节
1. spring bean 三种初始化方法顺序,优先到后 @PostConstruct InitializingBean(afterPropertiesSet) @Bean(initMethod) MyBean 类 import javax.annotation.PostConstruct; import org.springframework.beans.factory.InitializingBean; public class MyBean implements InitializingB原创 2020-10-09 18:30:50 · 100 阅读 · 0 评论 -
Jackson使用——JsonUtil
JsonUtil import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import co.原创 2020-10-09 17:13:45 · 421 阅读 · 0 评论 -
负载均衡的简单实现
负载均衡接口类 /** * 负载均衡 * */ public interface LoadBalancing { String selectOne(List<String> serverList); String selectOneWithWeight(List<String> serverList, List<Integer> weightList); } 随机(Random)法 /** * 随机(Random)法 * */ public c.原创 2020-05-28 17:23:02 · 229 阅读 · 0 评论 -
【代码小技巧】枚举类
小技巧 枚举类很实用的,这里只是用一个示例来记录一下枚举类的基本使用方式,没什么技术含量,直接开始~ 枚举类 public enum Fruit { APPLE("apple", "苹果"), PEAR("pear", "梨"), PEACH("peach", "桃子"), STRAWBERRY("strawberry", "草莓"), ORANGE("orange", "橙子"); ...原创 2020-03-20 11:10:56 · 80 阅读 · 0 评论 -
【代码小技巧】Switch开关
小技巧 有时候程序里的一个功能在某个场景下需要,另一个场景下就不需要,这时候就可以使用一个开关,在部署的时候,通过更改配置文件开关参数值,来控制这个功能的启用或停用。 当开关较多时,可以将所有的开关可以放在一个开关类,统一管理。 配置文件 mail.switch=true zk.notify.switch=true Switch开关类 @Component public class Switch...原创 2020-03-20 10:42:39 · 238 阅读 · 0 评论