1. Add pom dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version> 1.5.8.RELEASE</version>
</dependency>
2. Create entity table and JpaRepository
Add the following annotations to the entity table
@Entity
@Table(name = "realtablename")
JpaRepository declares as follows
@Repository public interface TestRepository extends JpaRepository<Test,Long> { List<About> findAll(); }
3. Common queries and usage
General queries are declared by connecting multiple query conditions directly with And
CustomerShipAddr findByUidAndIsdefault(int uid,int isdefount);
4. Simple joint table
@OneToOne @JoinColumn(name="picture") private GoodImage image;
The above statement will load the corresponding GoodImage table through the picture column, and there are many-to-many, one-to-many is not used for the time being.
5. Affairs
Add transaction support
Just add the annotation @Transactional to the Service method that accesses the database. If you don't need transactions, don't add such annotations.