当前位置:网站首页>Internship: unfamiliar annotations involved in the project code and their functions

Internship: unfamiliar annotations involved in the project code and their functions

2022-07-06 01:24:00 ahyo

It is suggested that internship friends can record their internship process —— What have you learned every day What did you do , Write more in the process of learning demo.

Lombok in @EqualsAndHashCode Use of annotations :
Main test cases It is a subclass that inherits the parent class The two object properties of the instantiated subclass are set to the same value utilize equals Compare , But the result is true, Every instantiated object has a hashcode, This is the basis for comparison .

public class demo {
    
    public static void main(String[] args) {
    
        son y1=new son();
        y1.setAge(10);
        y1.setPrice(1000000);
        y1.setName("asa");

        son y2=new son();
        y2.setAge(10);
        y2.setPrice(1000000);
        y2.setName("sdd");

        System.out.println(" Object comparison "+y1.equals(y2));

    }
}

@EqualsAndHashCode(callSuper = true), It is generated with its own attributes and attributes inherited from the parent class hashcode;

@EqualsAndHashCode(callSuper = false), Is to use only their own attributes to generate hashcode;

@Data amount to @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode this 5 A collection of notes , and @EqualsAndHashCode The default is false.
So the corresponding solution —— Often add comments at the beginning of a class @Data perhaps @EqualsAndHashCode(callSuper=true)

@EqualsAndHashCode Mainly automatic model Class equals Methods and HashCode Method
It is worth mentioning that ——Model It's just for data transmission , It doesn't address services .ModelAndView But it can be used for business addressing , Is to set the corresponding static file to be requested , The static file here refers to something like jsp The file of

ValueOperations It's easy to operate value for example String Tool class The object of operation is redis database

A class with @Service annotation , Will be automatically registered to Spring Containers , No need to be in applicationContext.xml Defined in the configuration file bean 了 , Similar ones include @Component、@Repository、@Controller. This is why the class header is added @Service The following attributes or methods are direct @Resource perhaps @Autowired

about @Autowired The understanding of the I know a little better before :
1、 Generally, an interface class has only one implementation class Whether it is assembled by type or name, there is no problem
2、 If an interface class has multiple implementation classes Then the attribute name should be consistent with the component name , The component name can be specified at the time of declaration , such as @Service(“”), The attribute name is inconsistent with the component name , coordination @Qualifier The annotation specifies the component name .

Then there is what was involved before api Common comments
@TableField This kind of annotation involves the establishment of entity classes in database tables

原网站

版权声明
本文为[ahyo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060119061510.html