質問編集履歴
1
他クラスの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -77,3 +77,253 @@
|
|
77
77
|
where句を指定せずに、全て取得するようにすると問題なく取得できました。
|
78
78
|
|
79
79
|
where句を指定するとエラーになってしまいます。
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
## 追記
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
### UserController
|
88
|
+
|
89
|
+
```ここに言語を入力
|
90
|
+
|
91
|
+
package group.study.dev.sample.search.controller;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
import java.util.List;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
100
|
+
|
101
|
+
import org.springframework.stereotype.Controller;
|
102
|
+
|
103
|
+
import org.springframework.ui.Model;
|
104
|
+
|
105
|
+
import org.springframework.web.bind.annotation.RequestMapping;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
import group.study.dev.dto.sample.SampleDto;
|
110
|
+
|
111
|
+
import group.study.dev.sample.search.model.UserModel;
|
112
|
+
|
113
|
+
import group.study.dev.sample.search.service.UserService;
|
114
|
+
|
115
|
+
import group.study.dev.web.common.controller.AbstractController;
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
@Controller
|
120
|
+
|
121
|
+
public class UserController extends AbstractController {
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
@Autowired
|
126
|
+
|
127
|
+
private UserService userService;
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
@RequestMapping("/search")
|
132
|
+
|
133
|
+
public void init(UserModel userModel, Model model) {
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
List<SampleDto> listAll = userService.selectAll();
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
model.addAttribute("listAll", listAll);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
System.out.println("listAll=" + listAll);
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
### UserService
|
160
|
+
|
161
|
+
```ここに言語を入力
|
162
|
+
|
163
|
+
package group.study.dev.sample.search.service;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
import java.util.List;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
172
|
+
|
173
|
+
import org.springframework.stereotype.Service;
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
import group.study.dev.dao.sample.SampleDao;
|
178
|
+
|
179
|
+
import group.study.dev.dto.sample.SampleDto;
|
180
|
+
|
181
|
+
import group.study.dev.sample.search.model.UserModel;
|
182
|
+
|
183
|
+
import group.study.dev.web.common.controller.AbstractController;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
@Service
|
188
|
+
|
189
|
+
public class UserService extends AbstractController{
|
190
|
+
|
191
|
+
@Autowired
|
192
|
+
|
193
|
+
private SampleDao sampleMapper;
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
public List<SampleDto> selectAll(){
|
198
|
+
|
199
|
+
UserModel userModel = new UserModel();
|
200
|
+
|
201
|
+
//sampleMapper.selectAll();
|
202
|
+
|
203
|
+
userModel.setSampleList(sampleMapper.selectAll());
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
return userModel.getSampleList();
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
### UserModel
|
222
|
+
|
223
|
+
```ここに言語を入力
|
224
|
+
|
225
|
+
package group.study.dev.sample.search.model;
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
import java.util.List;
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
import group.study.dev.dto.sample.SampleDto;
|
234
|
+
|
235
|
+
import group.study.dev.web.common.controller.AbstractController;
|
236
|
+
|
237
|
+
import lombok.Data;
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
@Data
|
242
|
+
|
243
|
+
public class UserModel extends AbstractController{
|
244
|
+
|
245
|
+
private List<SampleDto> sampleList;
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
### SampleDto
|
254
|
+
|
255
|
+
```ここに言語を入力
|
256
|
+
|
257
|
+
package group.study.dev.dto.sample;
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
import lombok.Data;
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
@Data
|
266
|
+
|
267
|
+
public class SampleDto {
|
268
|
+
|
269
|
+
private String sample_id;
|
270
|
+
|
271
|
+
private String sample_name;
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
```
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
### SampleDao
|
280
|
+
|
281
|
+
```ここに言語を入力
|
282
|
+
|
283
|
+
package group.study.dev.dao.sample;
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
import java.util.List;
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
import org.apache.ibatis.annotations.Mapper;
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
import group.study.dev.dto.sample.SampleDto;
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
@Mapper
|
300
|
+
|
301
|
+
public interface SampleDao {
|
302
|
+
|
303
|
+
public List<SampleDto> selectAll();
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
```
|
310
|
+
|
311
|
+
### SampleMapper
|
312
|
+
|
313
|
+
```ここに言語を入力
|
314
|
+
|
315
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
316
|
+
|
317
|
+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
318
|
+
|
319
|
+
<mapper namespace="group.study.dev.dao.sample.SampleDao">
|
320
|
+
|
321
|
+
<select id="selectAll" resultType="group.study.dev.dto.sample.SampleDto">
|
322
|
+
|
323
|
+
select sample_name, sample_id from public.sample_table where sample_id = 'S002';
|
324
|
+
|
325
|
+
</select>
|
326
|
+
|
327
|
+
</mapper>
|
328
|
+
|
329
|
+
```
|