One, 4.21 accumulated knowledge points
@Controller identifies a spring class that is a spring MVC controller processor
@RestController: It is the combination of @controller and @responsebody, with two annotations combined.
- @Transactional: The class or method that called this annotation indicates that all the methods within the class or the transaction of the method are handled by spring to ensure the atomicity of the transaction, not knowing that you can understand it, that is, the method is in the face of the database operation, if it fails, spring is responsible for rolling back the operation, successfully committing the operation
application. JAVA files can not be placed directly under the Main/java folder, you must build a package to put him in, if no party in the words will be reported * * WARNING * *: Your ApplicationContext is unlikely to start Due to a @ComponentScan of the default package.
Second, connect the database using spring boot
1. Introducing JPA and MySQL and dependencies in maven
2. Create an entity class
3. Entity persistence: Define interface Inheritance Jparepository interface.
Repository
|
Crudrepository: Delete and change
|
Paginandsortingrepository: Provides paging and sorting capabilities
|
Jparepository
JPA also provides custom declarative method rules, using the keyword FindBy, readby, getby as a prefix, with the attribute fields of the entity class (capitalized), and the SQL query keyword to form a query method.
Eg:findbyidandname (Long id,string name);
Spring Boot integrated MySQL