java spring and spring-boot study
zjblog / spring-study Goto Github PK
View Code? Open in Web Editor NEWjava spring and spring-boot study
java spring and spring-boot study
_通过execution函数定义切点表达式(定义切点的方法切入)
execution(<访问修饰符> <返回类型><方法名>(<参数>)<异常>)_
eg:
Comparable可排序的 若一个类实现了该接口意味着该类支持排序.如果有一个实现Comparable接口的类的对象的List或数组,则该List 或数组可以通过 Collections.sort或Arrays.sort进行排序.如Intege的集合(Integer String已经默认实现了Comparable接口)用于一个对象的不同实例去比较.Comparable接口只有一个方法 public int compareTo(T o);返回值<0 =0 >0
是比较器接口.如果要控制某个类的次序而此类本身不支持排序(即没有实现Comparable接口),我们可以建立一个“该类的比较器”来进行排序.这个“比较器”只需要实现Comparator接口即可.jdk8之后Comparator变成了函数式接口,书写起来更方便.
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 20; i++) {
list.add(i + new Random().nextInt(20));
}
System.out.println(list);
// 不需要提供额外比较器 因为Integer默认已经实现了Comparable接口
Collections.sort(list);
System.out.println(list);
List<Person> list1 = new ArrayList<>();
Person person = null;
for (int i = 0; i < 5; i++) {
person = new Person();
person.setName("" + i);
person.setAge(i + new Random().nextInt(20));
list.add(person);
}
System.out.println(list.toString());
// 因为person并没有实现Comparable接口 所以我们要定义一个比较器 jdk8中lambda的写法
Collections.sort(list1, (a, b) -> a.getAge() - b.getAge());
System.out.println(list.toString());
工厂模式包括:
在此项目的patterm包下有以上模式的例子,有更详细的介绍.
ps:画UML使用的工具是在线的,非常好用,试试看
RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径.相信大家都有一定的了解.
只有name返回String其它都是String[]
使用注解就要去读取注解,java中解读注解的接口是java.lang.reflect.AnnotatedElement.里面的方法可查看源码.
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
}
@Bean(destroyMethod = "shutdown")
public Executor taskExecutor() {
return Executors.newScheduledThreadPool(50);
} ```
使用的@Bean(destroyMethod="shutdown")是为了确保当Spring应用上下文关闭的时候任务执行者也被正确地关闭.
具体可参考本项目
Integer a = 11;
Integer b = 11;
Integer c = 300;
Integer d = 300;
System.out.println(a == b);
System.out.println(c == d);
你一定会想在Java 中,== 比较的是对象引用,而 equals 比较的是值.不同的对象有不同的引用,所以在进行比较的时候都应该返回 false.但奇怪的是,第一个是true第二个是false.原因应该出在包装类上,查看了下源码顺便重新认识下包装类.
Java 编译器把原始类型自动转换为封装类的过程称为自动装箱(autoboxing)这相当于调用 valueOf() 方法.查看valueOf()方法
/**
* Returns an {@code Integer} instance representing the specified
* {@code int} value. If a new {@code Integer} instance is not
* required, this method should generally be used in preference to
* the constructor {@link #Integer(int)}, as this method is likely
* to yield significantly better space and time performance by
* caching frequently requested values.
*
* This method will always cache values in the range -128 to 127,
* inclusive, and may cache other values outside of this range.
*
* @param i an {@code int} value.
* @return an {@code Integer} instance representing {@code i}.
* @since 1.5
*/
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
在创建新的 Integer 对象之前会先在 IntegerCache.cache 中查找,IntegerCache类来负责 Integer 的缓存.IntegerCache 是 Integer 类中一个私有的静态类,Javadoc说明这个类是用来实现缓存,并支持 -128 到 127 之间的自动装箱过程.最大值127 可以通过 JVM的启动参数 -XX:AutoBoxCacheMax=size 修改. 缓存通过一个 for 循环实现,从小到大的创建整数并存储在一个名为 cache 的整数数组中,这个缓存会在 Integer 类第一次被使用的时候被初始化出来,在自动装箱的时候就可以使用缓存中包含的实例对象,而不是创建一个新的实例.这种Integer 缓存策略仅在自动装箱的时候有用,使用构造器创建的Integer 对象不能被缓存.
Integer f = 10; // autoboxing
Integer g = new Integer("10");// Constructs
变量f可是使用缓存g是构造不能使用缓存,所以f==g 是false.
这种缓存行为不仅适用于Integer对象一下包装类也有缓存
格式:public @interface 注解名 {定义体}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.