소스 검색

Entity, JPA annotations?

Trinh Tong 6 년 전
부모
커밋
23e361fc5c

+ 5
- 5
src/main/java/io/zipcoder/persistenceapp/controller/PersonController.java 파일 보기

@@ -61,11 +61,11 @@ public class PersonController {
61 61
         Iterable<Person> p = personService.findPeopleByLastName(lastName);
62 62
         return new ResponseEntity<>(p, HttpStatus.OK);
63 63
     }
64
-    @GetMapping("/people/surname")
65
-    public ResponseEntity<Iterable<Person>> getSurnames(String lastName) {
66
-        Iterable<Person> p = personService.generateSurnameMap(lastName);
67
-        return new ResponseEntity<>(p, HttpStatus.OK);
68
-    }
64
+//    @GetMapping("/people/surname")
65
+//    public ResponseEntity<Iterable<Person>> getSurnames(String lastName) {
66
+//        Iterable<Person> p = personService.generateSurnameMap(lastName);
67
+//        return new ResponseEntity<>(p, HttpStatus.OK);
68
+//    }
69 69
 //    @GetMapping("/people/firstname/stats")
70 70
 //
71 71
 }

+ 11
- 0
src/main/java/io/zipcoder/persistenceapp/model/Person.java 파일 보기

@@ -1,11 +1,22 @@
1 1
 package io.zipcoder.persistenceapp.model;
2 2
 
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.GenerationType;
6
+import javax.persistence.Id;
3 7
 import java.util.Date;
4 8
 
9
+@Entity
5 10
 public class Person {
11
+
12
+    @Id
13
+    @GeneratedValue(strategy = GenerationType.AUTO)
6 14
     private Integer id;
15
+
7 16
     private String firstName, lastName, mobile;
17
+
8 18
     private Date birthday;
19
+
9 20
     private Integer homeId;
10 21
 
11 22
     public Person() {}

+ 2
- 0
src/main/java/io/zipcoder/persistenceapp/service/JdbcPersonServiceImpl.java 파일 보기

@@ -3,6 +3,7 @@ package io.zipcoder.persistenceapp.service;
3 3
 import io.zipcoder.persistenceapp.controller.mappers.PersonRowMapper;
4 4
 import io.zipcoder.persistenceapp.model.Person;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.context.annotation.Primary;
6 7
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
7 8
 import org.springframework.jdbc.core.JdbcTemplate;
8 9
 import org.springframework.stereotype.Service;
@@ -11,6 +12,7 @@ import java.sql.JDBCType;
11 12
 import java.util.List;
12 13
 
13 14
 @Service
15
+@Primary
14 16
 public class JdbcPersonServiceImpl implements PersonService {
15 17
 
16 18
     private final JDBCType[] types = {JDBCType.VARCHAR, JDBCType.VARCHAR, JDBCType.VARCHAR, JDBCType.DATE, JDBCType.SMALLINT };

+ 0
- 5
src/main/java/io/zipcoder/persistenceapp/service/JpaPersonServiceImpl.java 파일 보기

@@ -48,9 +48,4 @@ public class JpaPersonServiceImpl implements PersonService {
48 48
     public List<Person> findPeopleByLastName(String lastName) {
49 49
         return personRepository.findByLastName(lastName);
50 50
     }
51
-
52
-//    @Override
53
-//    public List<Person> generateSurnameMap(String lastName) {
54
-//        return null;
55
-//    }
56 51
 }

+ 0
- 2
src/main/java/io/zipcoder/persistenceapp/service/PersonService.java 파일 보기

@@ -13,6 +13,4 @@ public interface PersonService {
13 13
     List<Person> getAllPeople();
14 14
     List<Person> findPeopleByMobile(String mobile);
15 15
     List<Person> findPeopleByLastName(String lastName);
16
-//    List<Person> generateSurnameMap(String lastName);
17
-
18 16
 }