设计原则
- 多用组合少用继承。
- 找出应用中可能需要变化之处,把他们独立出来,不要和那些不需要变化的代码混合在一起。
- 针对接口编程,而不是针对实现编程。
- 为了交互对象之间的松耦合设计而努力。
- 类应该对扩展开放,对修改关闭。
- 要依赖抽象,不要依赖具体类。
- 最少知识原则:只和你的密友谈话。(相当于类间交互适当封装,减少耦合,只让必要部分交互)
Timeout using @Transactional annotation
To set request timeout on database queries or calls by using Spring’s @Transactional annotation. We may set the timeout attribute that it has. It has a default value of -1, which is the same as having no timeout at all.
Let’s say we have set this timeout to 50 seconds. An exception will be raised if the annotated method takes longer than this amount of time to execute. This approach is quite handy for time-consuming database searches or long-running SQL queries.
1. Wrapper Classes
1.1 What are Wrapper classes
Wrapper classes are classes in object-oriented programming that are used to wrap or encapsulate primitive data types so that they can be treated as objects. In Java, for example, there are several wrapper classes such as Integer, Double, and Boolean that correspond to the primitive data types int, double, and boolean, respectively.
Wrapper classes provide a way to represent primitive data types as objects, which allows them to be used in situations where objects are required, such as in collections or as method arguments. They also provide additional functionality, such as methods for converting between the wrapped value and other data types.