質問編集履歴
2
説明分の編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,18 +8,18 @@
|
|
8
8
|
```Java
|
9
9
|
|
10
10
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
11
|
-
private Long
|
11
|
+
private Long Id;
|
12
12
|
|
13
|
-
private String
|
13
|
+
private String Nm;
|
14
14
|
|
15
15
|
```Java
|
16
16
|
@Entity
|
17
|
-
@Table
|
17
|
+
@Table
|
18
18
|
@Data
|
19
|
-
public class
|
19
|
+
public class User {
|
20
20
|
|
21
21
|
@Id
|
22
22
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
23
|
-
private Long
|
23
|
+
private Long Id;
|
24
24
|
|
25
|
-
private Long
|
25
|
+
private Long name;
|
1
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,36 +3,15 @@
|
|
3
3
|
二つのテーブルを持っており、@OneToMany、@ManyToOneで関連を持たせて、
|
4
4
|
その後repositoryでfindByで検索した条件に一致したデータを取得できるようにしたいです。
|
5
5
|
|
6
|
-
その際のcontroller、serviceでのfindByメソッドの実装方法がわからず、苦戦しています。
|
7
|
-
特に引数の扱いに困っています。
|
8
6
|
|
9
7
|
|
10
8
|
```Java
|
11
|
-
|
9
|
+
|
12
|
-
@Table(name = "m_bldg")
|
13
|
-
@Data
|
14
|
-
public class MBldg {
|
15
|
-
@Id
|
16
10
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
17
|
-
private Long
|
11
|
+
private Long bId;
|
18
12
|
|
19
|
-
private String
|
13
|
+
private String bNm;
|
20
|
-
|
21
|
-
|
14
|
+
|
22
|
-
|
23
|
-
private String prefNm;
|
24
|
-
|
25
|
-
private Long cityId;
|
26
|
-
|
27
|
-
private string cityNm;
|
28
|
-
|
29
|
-
private String town;
|
30
|
-
|
31
|
-
private String cho
|
32
|
-
|
33
|
-
@OneToMany(mappedBy="mBldg")
|
34
|
-
private List<MUnit> mUnitList;
|
35
|
-
```
|
36
15
|
```Java
|
37
16
|
@Entity
|
38
17
|
@Table(name="m_unit")
|
@@ -41,62 +20,6 @@
|
|
41
20
|
|
42
21
|
@Id
|
43
22
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
44
|
-
private Long
|
23
|
+
private Long uId;
|
45
24
|
|
46
|
-
private Long
|
25
|
+
private Long bId;
|
47
|
-
|
48
|
-
private String roomNo;
|
49
|
-
|
50
|
-
private Integer layoutNum;
|
51
|
-
|
52
|
-
private String layoutKbn;
|
53
|
-
|
54
|
-
@ManyToOne
|
55
|
-
@JoinColumn(name = "bldgId", insertable = false, updatable = false)
|
56
|
-
private MBldg mBldg;
|
57
|
-
```
|
58
|
-
|
59
|
-
```Java(repository)
|
60
|
-
@Repository
|
61
|
-
public interface MUnitRepository extends JpaRepository<MUnit, Long>, JpaSpecificationExecutor<MUnit> {
|
62
|
-
|
63
|
-
public List<MUnit> findByBldgNmAndRoomNoAndPrefNmAndCityNmAndTownAndCho
|
64
|
-
(String bldgNm,String roomNo,String prefNm, String cityNm, String town,String cho);
|
65
|
-
|
66
|
-
}
|
67
|
-
|
68
|
-
```
|
69
|
-
|
70
|
-
下記serviceでの「findByBldgNmAndRoomNoAndPrefNmAndCityNmAndTownAndCho()」
|
71
|
-
の引数に何を指定すればよいのかわかりません。
|
72
|
-
単純にrepositoryで指定してある値を入れたらいいのか…
|
73
|
-
理解が足りていないのは、確かだとおもうのですが、どなたか助言等頂けると助かります。
|
74
|
-
|
75
|
-
```Java(service)
|
76
|
-
@Service
|
77
|
-
public class UnitService {
|
78
|
-
|
79
|
-
@Autowired
|
80
|
-
MUnitRepository mUnitRepository;
|
81
|
-
|
82
|
-
public List<MUnit> search(UnitForm form) throws Exception {
|
83
|
-
List <MUnit> result = mUnitRepository.findByBldgNmAndRoomNoAndPrefNmAndCityNmAndTownAndCho();
|
84
|
-
return result;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
```
|
88
|
-
|
89
|
-
```java
|
90
|
-
@RestController
|
91
|
-
@RequestMapping("/unit")
|
92
|
-
public class UnitRestController {
|
93
|
-
|
94
|
-
// 戸サービスクラス
|
95
|
-
@Autowired
|
96
|
-
UnitService unitService;
|
97
|
-
|
98
|
-
@RequestMapping(path = "search", method = RequestMethod.GET)
|
99
|
-
public String search(UnitForm form, Model model) throws Exception {
|
100
|
-
return JsonUtil.convSearchData(unitService.search(form));
|
101
|
-
}
|
102
|
-
```
|