Java基础
record关键字
- 该关键字有点像lambok的@data方法,但是它创建出来的数据对象没有set方法,也就是说它的数据是一旦创建就不可改了。
- 同时record关键字定义的类不可以被继承
这里创建了一个EmoloyeeRecord,里面有字段:name及employeeNumber
public record EmployeeRecord (String name, int employeeNumber){}
Dpendency Injection & Inversion of Control 依赖注入和控制反转概念解释
what is dependency 什么是依赖
比如图中class A 使用了 class B的方法,也就class A 依赖于 class B。也就是在class A中,它需实力例化或赋值类B。
Inversion of control :
Objects do not create other objects on which they rely on their work. Instead, they get the objects that they need from outside source(for example, an xml configuration file) 控制反转认为这种依赖关系应该转过来
举例子:现在有一个user对象,user对象需要访问数据库,那么就需要创建一个数据库对象来访问数据库,正常来说。但是在控制反转中,我们会有一个更高层次的框架或者比的东西来实例化数据库对象,并把该数据库对象作为参数传递给user对象初始化。这可以让我们更关注堆代码进行进一步抽象而不是具体实现。
Dependency Injection 就是为了实现IOC控制反转:
Dependency Injection generally means passing a dependent object as a parameter to a method, rather than having the method create the dependent object. What it means in practice the method does not have a direct dependency on a particular implementation; any implementaton that meets the requirements can be passed as a parameter.
Spring bean:
an instance of a class managed by the Spring container. the Spring container decides when to create this instance and when to kill this instance, how to set, how to initialize...
spiring container:
- part of core of the Spring Framework
- Responsible for managing all the beans
- Peforms dependency injection : making sure these instances are at the right place at the right time for application
SpringbootWeb快速入门
API开发
请求报文常用注解
- @RestController
- @RequestMapping
- @Pathvariable
- @RequestBody
数据访问
JdbcTemplate
Spring Data JPA
- @entity