Annotations Flashcards
(4 stereotype annotations:)
- General/generic annotation to make a Spring bean
@Component
(4 stereotype annotations:)
- DAO Classes that you want to make a Spring bean
@Repository
(4 stereotype annotations:)
- Service Classes that you want to make Spring Bean
@Service
(4 stereotype annotations:)
- Controller Classes that you want to make a Spring
@Controller
will abstract away the dependency injection that it does for you. So to us, it looks automatic and magical.
@Autowired
used To run a Spring Boot application
@SpringBootApplication
(spring MVC)
Preferred stereotype annotation for MVC Controllers. Makes the Class a bean, as well as allowing the class to use the annotations below and get noticed by the DispatcherServlet
@Controller
(Spring MVC)
- Specifies the path URI (endpoint) that will be delegated to this controller class or method. We also use it to specify particular HTTP verbs.
@GetMapping
@PostMapping
Etc.
@RequestMapping
(Spring MVC)
- sets up Cors filtering for us (so that we can get requests from the front end and send back responses)
@CrossOrigin
(Spring MVC)
- Converts the body of our response to JSON for us. Placed at either the class level or method level. No more GSON!
@ResponseBody
(Spring MVC)
- allows for getting a path variable out of a URI and used in the parameter of the controller method that took the request.
@PathVariable
(Spring MVC)
- Parses the JSON body of the request to an object specified in the parameters of the Controller method that took the requests
@RequestBody
(Spring MVC)
- This combines the two annotations of @Controller and @ResponseBody. Convenient!!!
@RestController
(JPA Annotations)
- Indicates that the Class is meant to be mapped to a DB table
@Entity
(JPA Annotations)
- Doesn’t actually make a class a table (@Entity does that) but it’s useful for setting table options such as the name of the table in the database
@Table
(JPA Annotations)
- Defines a variable as a column in the table. Hibernate will turn all of a Class’s field in DB columns by default, BUT using the annotation lets us set things such as column name, or constraints like not null, and unique.
@Column
(JPA Annotations)
- Declares a variable as a primary key in a table
@Id
(JPA Annotations)
- This gives you control over the options for how Hibernate will auto-generate your primary key.
@GeneratedValue
(JPA Annotations)
define the relationship between our model classes in Java.
@ManyToOne/@OneToMany/@ManyToMany -
(JPA Annotations)
- Specifies a column to establish the relationship on. Just like we do normally, this is usually a Foreign Key pointing to the Primary Key of the table being referred to.
@JoinColumn
(Spring Data Annotations)
Configures how the database transactions behave. See the Transaction notes below, you’ll often need to use this with updates/deletes
@Transactional
(Spring Data Annotations)
Creates an Interface that provides common methods for child repositories
@NoRepositoryBean
(Spring Data Annotations)
Parameters can be passed to queries that are defined with @query
@param
(Spring Data Annotations)
Marks a field in a Model class as the primary key
@Id