teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

現在のソースコード

2019/01/24 11:47

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -69,55 +69,112 @@
69
69
  ```
70
70
  **Employee:**
71
71
  ```ここに言語を入力
72
- package com.spring.data.jpa.example.entity;
72
+ package com.spring.data.jpa.example.repository.entity;
73
73
 
74
74
  import java.io.Serializable;
75
-
76
75
  import javax.persistence.Column;
77
76
  import javax.persistence.Entity;
78
77
  import javax.persistence.EnumType;
79
78
  import javax.persistence.Enumerated;
80
79
  import javax.persistence.GeneratedValue;
81
80
  import javax.persistence.Id;
82
-
83
81
  import lombok.Getter;
84
82
  import lombok.Setter;
85
83
  import lombok.ToString;
86
84
 
87
-
88
85
  @Entity
89
86
  @Getter
90
87
  @Setter
91
88
  @ToString
92
89
  public class Employee implements Serializable {
93
- private static final long serialVersionUID=1L;
90
+ private static final long serialVersionUID = 1L;
94
91
 
92
+ /**
93
+ * 性別の列挙
94
+ */
95
- public static enum Sex{
95
+ public static enum Sex {
96
- male,female
96
+ male, female
97
- }
97
+ }
98
98
 
99
+ /** 社員番号 */
99
- @Id
100
+ @Id
100
- @GeneratedValue
101
+ @GeneratedValue
101
- private Integer no;
102
+ private Integer no;
102
103
 
104
+ /** 名前 */
103
- @Column(length = 20, nullable =false)
105
+ @Column(length = 20, nullable = false)
104
- private String firstName;
106
+ private String firstName;
105
107
 
108
+ /** 苗字 */
106
- @Column(length = 20, nullable =false)
109
+ @Column(length = 20, nullable = false)
107
- private String lastName;
110
+ private String lastName;
108
111
 
112
+ /** 性別 */
109
- @Column(length = 10)
113
+ @Column(length = 10)
110
- @Enumerated(EnumType.STRING)
114
+ @Enumerated(EnumType.STRING)
111
- private Sex sex;
115
+ private Sex sex;
112
116
 
117
+ /** 生年月日 */
113
- private java.sql.Date birthday;
118
+ private java.sql.Date birthday;
114
119
 
120
+ /** メールアドレス */
115
- @Column(unique = true)
121
+ @Column(unique = true)
116
- private String mailAddress;
122
+ private String mailAddress;
123
+ }
117
124
 
125
+ ```
126
+ **EmployeeRepository**
127
+ ```ここに言語を入力
128
+ package com.spring.data.jpa.example.repository;
129
+
130
+ import org.springframework.data.jpa.repository.JpaRepository;
131
+ import org.springframework.stereotype.Repository;
132
+
133
+ import com.spring.data.jpa.example.repository.entity.Employee;
134
+
135
+ @Repository
136
+ public interface EmployeeRepository
137
+ extends JpaRepository<Employee, Integer> {
118
138
  }
139
+ ```
140
+ **EmployeeService**
141
+ ```ここに言語を入力
142
+ package com.spring.data.jpa.example.service;
119
143
 
144
+ import java.util.List;
145
+
146
+ import com.spring.data.jpa.example.repository.entity.Employee;
147
+
148
+ public interface EmployeeService {
149
+ public List<Employee> getEmployeeList();
150
+ }
120
151
  ```
152
+ **EmployeeServiceImpl**
153
+ ```ここに言語を入力
154
+ package com.spring.data.jpa.example.service;
155
+
156
+ import java.util.List;
157
+
158
+ import org.springframework.beans.factory.annotation.Autowired;
159
+ import org.springframework.stereotype.Service;
160
+ import org.springframework.transaction.annotation.Transactional;
161
+
162
+ import com.spring.data.jpa.example.repository.EmployeeRepository;
163
+ import com.spring.data.jpa.example.repository.entity.Employee;
164
+
165
+ @Service
166
+ @Transactional(readOnly = true)
167
+ public class EmployeeServiceImpl implements EmployeeService {
168
+ @Autowired
169
+ private EmployeeRepository employeeRepository;
170
+
171
+ @Override
172
+ public List<Employee> getEmployeeList() {
173
+ return employeeRepository.findAll();
174
+ }
175
+ }
176
+ ```
177
+
121
178
  **ログ:**
122
179
  ```
123
180
  Hibernate: drop table if exists employee

2

環境更新

2019/01/24 11:47

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -144,4 +144,12 @@
144
144
  2019-01-20 14:56:04.739 DEBUG 10990 --- [nio-8080-exec-1] org.hibernate.SQL : select employee0_.no as no1_0_, employee0_.birthday as birthday2_0_, employee0_.first_name as first_na3_0_, employee0_.last_name as last_nam4_0_, employee0_.mail_address as mail_add5_0_, employee0_.sex as sex6_0_ from employee employee0_
145
145
  Hibernate: select employee0_.no as no1_0_, employee0_.birthday as birthday2_0_, employee0_.first_name as first_na3_0_, employee0_.last_name as last_nam4_0_, employee0_.mail_address as mail_add5_0_, employee0_.sex as sex6_0_ from employee employee0_
146
146
 
147
- ```
147
+ ```
148
+ **環境:**
149
+ mysql> select version();
150
+ +-----------+
151
+ | version() |
152
+ +-----------+
153
+ | 5.7.22 |
154
+ +-----------+
155
+ 1 row in set (0.02 sec)

1

若葉マーク追加

2019/01/24 10:12

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
File without changes