Created
March 21, 2019 11:11
-
-
Save JavaNoobPig/9d01d5207d9d16cbb06809397a020de1 to your computer and use it in GitHub Desktop.
IntroductionSpring45_1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig.database.databasedemo.jpa; | |
| import javax.persistence.EntityManager; | |
| import javax.persistence.PersistenceContext; | |
| import javax.transaction.Transactional; | |
| import org.springframework.stereotype.Repository; | |
| import com.pig.database.databasedemo.entity.Person; | |
| @Repository | |
| @Transactional | |
| public class PersonJpaRepository { | |
| //connect to database | |
| @PersistenceContext | |
| EntityManager entityManager; | |
| public Person findById(int Id) { | |
| return entityManager.find(Person.class, Id); //JPA | |
| } | |
| //SQL Update NEW!!! | |
| public Person update(Person person) { | |
| return entityManager.merge(person); //都是用merge | |
| } | |
| //SQL Insert NEW!!! | |
| public Person insert(Person person) { | |
| return entityManager.merge(person); //都是用merge | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment