Spring Boot QuickStart 5: Transaction Management

Source: Internet
Author: User

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

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.