Spring Boot integrated MySQL

Source: Internet
Author: User

One, 4.21 accumulated knowledge points

  1. @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.

  2. @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
  3. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.