質問編集履歴

1

色々ソースを編集して状況が変わったので編集しました。

2018/11/26 14:48

投稿

takahiro00
takahiro00

スコア84

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  ```
18
18
 
19
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userEditController' defined in file [/Users/takahiro/Documents/workspace/KProject01/bin/main/com/kproject01/controller/UserEditController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.kproject01.controller.UserEditController]: Constructor threw exception; nested exception is java.lang.NullPointerException
19
+ java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
20
20
 
21
21
  ```
22
22
 
@@ -52,6 +52,16 @@
52
52
 
53
53
 
54
54
 
55
+ /**
56
+
57
+ * ユーザ編集ページのコントローラー
58
+
59
+ * @author takahiro
60
+
61
+ *
62
+
63
+ */
64
+
55
65
  @Controller
56
66
 
57
67
  public class UserEditController {
@@ -64,30 +74,134 @@
64
74
 
65
75
 
66
76
 
77
+ /**
78
+
79
+ * 初期表示
80
+
81
+ * @param mav
82
+
83
+ * @return mav
84
+
85
+ */
86
+
87
+ @GetMapping(path = "/user-edit")
88
+
89
+ public ModelAndView useEdit(ModelAndView mav) {
90
+
91
+ //userEditService.userEditUserSelect();
92
+
67
- public Map<Integer, String> getSelectedUser =
93
+ Map<Integer, String> getSelectedUser =
68
-
94
+
69
- Collections.unmodifiableMap(new LinkedHashMap<Integer, String>() {
95
+ Collections.unmodifiableMap(new LinkedHashMap<Integer, String>() {
70
-
96
+
71
- private static final long serialVersionUID = 1L;
97
+ private static final long serialVersionUID = 1L;
72
-
98
+
73
- Map<Integer, String> userList = userEditService.userEditUserSelect();
99
+ Map<Integer, String> userList = userEditService.userEditUserSelect();
74
-
100
+
75
- {
101
+ {
76
-
102
+
77
- for(Map.Entry<Integer, String>entry :userList.entrySet()){
103
+ for(Map.Entry<Integer, String>entry :userList.entrySet()){
104
+
78
-
105
+ System.out.println(entry.getKey());
106
+
107
+ System.out.println(entry.getValue());
108
+
79
- put(entry.getKey(), entry.getValue());
109
+ put(entry.getKey(), entry.getValue());
110
+
111
+ }
80
112
 
81
113
  }
82
114
 
115
+ });
116
+
83
- System.out.println();
117
+ mav.setViewName("user-edit");
118
+
84
-
119
+ return mav;
120
+
85
- }
121
+ }
86
-
122
+
87
- });
123
+ }
124
+
125
+
126
+
127
+ ```
128
+
129
+ ```xml
130
+
131
+ <?xml version="1.0" encoding="UTF-8" ?>
132
+
133
+ <!DOCTYPE mapper
134
+
135
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
136
+
137
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
138
+
139
+ <mapper namespace="com.kproject01.mapper.UserEditMapper">
140
+
141
+ <select id="userEditUserSelect" resultType="map">
142
+
143
+ select
144
+
145
+ user_id,
146
+
147
+ first_nm
148
+
149
+ from
150
+
151
+ m_user
152
+
153
+ where
154
+
155
+ delete_flg = 0
156
+
157
+ </select>
158
+
159
+ </mapper>
160
+
161
+ ```
162
+
163
+ ```java
164
+
165
+ package com.kproject01.mapper;
166
+
167
+
168
+
169
+ import java.util.List;
170
+
171
+ import java.util.Map;
172
+
173
+
174
+
175
+ import org.apache.ibatis.annotations.MapKey;
176
+
177
+
178
+
179
+ import com.kproject01.entity.UserEditUserSelect;
180
+
181
+ import com.kproject01.entity.UserTop;
182
+
183
+
184
+
185
+ /**
186
+
187
+ * ユーザ編集ページ
188
+
189
+ * @author takahiro
190
+
191
+ *
192
+
193
+ */
194
+
195
+ public interface UserEditMapper {
88
196
 
89
197
 
90
198
 
199
+ //コンボボックスに格納するユーザID、ユーザ名を取得
200
+
201
+ @MapKey("userId")
202
+
203
+ Map<Integer, String> userEditUserSelect();
204
+
91
205
  }
92
206
 
93
207
 
@@ -96,9 +210,9 @@
96
210
 
97
211
  ### 補足情報(FW/ツールのバージョンなど)
98
212
 
99
- Map<Integer, String> userList = userEditService.userEditUserSelect();
213
+ xmlのresultTypeをhashmapにしたりエンティティにしたりしたのですが、うまくいかず
100
-
214
+
101
- ↑部でエラーになているようです。
215
+ 型が違うというのはなんとなくたのです。。。
102
216
 
103
217
 
104
218