質問編集履歴

3

現在のソースコード

2019/01/24 11:47

投稿

MaikoH
MaikoH

スコア16

test CHANGED
File without changes
test CHANGED
@@ -140,14 +140,12 @@
140
140
 
141
141
  ```ここに言語を入力
142
142
 
143
- package com.spring.data.jpa.example.entity;
143
+ package com.spring.data.jpa.example.repository.entity;
144
144
 
145
145
 
146
146
 
147
147
  import java.io.Serializable;
148
148
 
149
-
150
-
151
149
  import javax.persistence.Column;
152
150
 
153
151
  import javax.persistence.Entity;
@@ -160,8 +158,6 @@
160
158
 
161
159
  import javax.persistence.Id;
162
160
 
163
-
164
-
165
161
  import lombok.Getter;
166
162
 
167
163
  import lombok.Setter;
@@ -170,8 +166,6 @@
170
166
 
171
167
 
172
168
 
173
-
174
-
175
169
  @Entity
176
170
 
177
171
  @Getter
@@ -182,55 +176,71 @@
182
176
 
183
177
  public class Employee implements Serializable {
184
178
 
185
- private static final long serialVersionUID=1L;
186
-
187
-
188
-
189
- public static enum Sex{
190
-
191
- male,female
192
-
193
- }
194
-
195
-
196
-
197
- @Id
198
-
199
- @GeneratedValue
200
-
201
- private Integer no;
202
-
203
-
204
-
205
- @Column(length = 20, nullable =false)
206
-
207
- private String firstName;
208
-
209
-
210
-
211
- @Column(length = 20, nullable =false)
212
-
213
- private String lastName;
214
-
215
-
216
-
217
- @Column(length = 10)
218
-
219
- @Enumerated(EnumType.STRING)
220
-
221
- private Sex sex;
222
-
223
-
224
-
225
- private java.sql.Date birthday;
226
-
227
-
228
-
229
- @Column(unique = true)
230
-
231
- private String mailAddress;
232
-
233
-
179
+ private static final long serialVersionUID = 1L;
180
+
181
+
182
+
183
+ /**
184
+
185
+ * 性別の列挙
186
+
187
+ */
188
+
189
+ public static enum Sex {
190
+
191
+ male, female
192
+
193
+ }
194
+
195
+
196
+
197
+ /** 社員番号 */
198
+
199
+ @Id
200
+
201
+ @GeneratedValue
202
+
203
+ private Integer no;
204
+
205
+
206
+
207
+ /** 名前 */
208
+
209
+ @Column(length = 20, nullable = false)
210
+
211
+ private String firstName;
212
+
213
+
214
+
215
+ /** 苗字 */
216
+
217
+ @Column(length = 20, nullable = false)
218
+
219
+ private String lastName;
220
+
221
+
222
+
223
+ /** 性別 */
224
+
225
+ @Column(length = 10)
226
+
227
+ @Enumerated(EnumType.STRING)
228
+
229
+ private Sex sex;
230
+
231
+
232
+
233
+ /** 生年月日 */
234
+
235
+ private java.sql.Date birthday;
236
+
237
+
238
+
239
+ /** メールアドレス */
240
+
241
+ @Column(unique = true)
242
+
243
+ private String mailAddress;
234
244
 
235
245
  }
236
246
 
@@ -238,6 +248,110 @@
238
248
 
239
249
  ```
240
250
 
251
+ **EmployeeRepository**
252
+
253
+ ```ここに言語を入力
254
+
255
+ package com.spring.data.jpa.example.repository;
256
+
257
+
258
+
259
+ import org.springframework.data.jpa.repository.JpaRepository;
260
+
261
+ import org.springframework.stereotype.Repository;
262
+
263
+
264
+
265
+ import com.spring.data.jpa.example.repository.entity.Employee;
266
+
267
+
268
+
269
+ @Repository
270
+
271
+ public interface EmployeeRepository
272
+
273
+ extends JpaRepository<Employee, Integer> {
274
+
275
+ }
276
+
277
+ ```
278
+
279
+ **EmployeeService**
280
+
281
+ ```ここに言語を入力
282
+
283
+ package com.spring.data.jpa.example.service;
284
+
285
+
286
+
287
+ import java.util.List;
288
+
289
+
290
+
291
+ import com.spring.data.jpa.example.repository.entity.Employee;
292
+
293
+
294
+
295
+ public interface EmployeeService {
296
+
297
+ public List<Employee> getEmployeeList();
298
+
299
+ }
300
+
301
+ ```
302
+
303
+ **EmployeeServiceImpl**
304
+
305
+ ```ここに言語を入力
306
+
307
+ package com.spring.data.jpa.example.service;
308
+
309
+
310
+
311
+ import java.util.List;
312
+
313
+
314
+
315
+ import org.springframework.beans.factory.annotation.Autowired;
316
+
317
+ import org.springframework.stereotype.Service;
318
+
319
+ import org.springframework.transaction.annotation.Transactional;
320
+
321
+
322
+
323
+ import com.spring.data.jpa.example.repository.EmployeeRepository;
324
+
325
+ import com.spring.data.jpa.example.repository.entity.Employee;
326
+
327
+
328
+
329
+ @Service
330
+
331
+ @Transactional(readOnly = true)
332
+
333
+ public class EmployeeServiceImpl implements EmployeeService {
334
+
335
+ @Autowired
336
+
337
+ private EmployeeRepository employeeRepository;
338
+
339
+
340
+
341
+ @Override
342
+
343
+ public List<Employee> getEmployeeList() {
344
+
345
+ return employeeRepository.findAll();
346
+
347
+ }
348
+
349
+ }
350
+
351
+ ```
352
+
353
+
354
+
241
355
  **ログ:**
242
356
 
243
357
  ```

2

環境更新

2019/01/24 11:47

投稿

MaikoH
MaikoH

スコア16

test CHANGED
File without changes
test CHANGED
@@ -291,3 +291,19 @@
291
291
 
292
292
 
293
293
  ```
294
+
295
+ **環境:**
296
+
297
+ mysql> select version();
298
+
299
+ +-----------+
300
+
301
+ | version() |
302
+
303
+ +-----------+
304
+
305
+ | 5.7.22 |
306
+
307
+ +-----------+
308
+
309
+ 1 row in set (0.02 sec)

1

若葉マーク追加

2019/01/24 10:12

投稿

MaikoH
MaikoH

スコア16

test CHANGED
File without changes
test CHANGED
File without changes