Transaction management:
Two new girls added:
First step: Create Girlrespository
PackageCom.payease.service;ImportCom.payease.entity.Girl;Importorg.springframework.data.jpa.repository.JpaRepository;Importjava.util.List;/*** Created by liuxiaoming on 2017/11/6.*/ Public InterfaceGirlrespositoryextendsJparepository<girl,integer>{ //Conditional query: Search by age PublicList<girl>findbyage (Integer age);}
Step Two: Create girlservice
PackageCom.payease.service;ImportCom.payease.entity.Girl;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Service;/*** Created by liuxiaoming on 2017/11/7.*/@Service Public classGirlservice {@AutowiredPrivategirlrespository girlrespository; Public voidInserttwo () {Girl Girla=NewGirl (); Girla.setcupsize (A); Girla.setage (18); Girlrespository.save (Girla); Girl girlb=NewGirl (); Girlb.setcupsize (B); Girlb.setage (20); Girlrespository.save (GIRLB); }}
Step three: write in the controller
Public class Girlcontroller { @Autowired private girlservice girlservice; @PostMapping ("Girls/two") publicvoid girltwo () { Girlservice.inserttwo (); }}
Fourth step: Start the project postman submit
Original database:
Postman after submitting the request:
Transaction management: Failed to insert data when data insertion is required
First step: Change the length of this field to 1
Step Two: Add annotations to the service
Spring Boot QuickStart 5: Transaction Management