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

質問編集履歴

1

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

2018/11/26 14:48

投稿

takahiro00
takahiro00

スコア84

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  ### 発生している問題・エラーメッセージ
8
8
 
9
9
  ```
10
- 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
10
+ java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
11
11
  ```
12
12
 
13
13
  ### 該当のソースコード
@@ -25,30 +25,87 @@
25
25
  import org.springframework.web.servlet.ModelAndView;
26
26
  import com.kproject01.service.UserEditService;
27
27
 
28
+ /**
29
+ * ユーザ編集ページのコントローラー
30
+ * @author takahiro
31
+ *
32
+ */
28
33
  @Controller
29
34
  public class UserEditController {
30
35
 
31
36
  @Autowired
32
37
  UserEditService userEditService;
33
38
 
39
+ /**
40
+ * 初期表示
41
+ * @param mav
42
+ * @return mav
43
+ */
44
+ @GetMapping(path = "/user-edit")
45
+ public ModelAndView useEdit(ModelAndView mav) {
46
+ //userEditService.userEditUserSelect();
34
- public Map<Integer, String> getSelectedUser =
47
+ Map<Integer, String> getSelectedUser =
35
- Collections.unmodifiableMap(new LinkedHashMap<Integer, String>() {
48
+ Collections.unmodifiableMap(new LinkedHashMap<Integer, String>() {
36
- private static final long serialVersionUID = 1L;
49
+ private static final long serialVersionUID = 1L;
37
- Map<Integer, String> userList = userEditService.userEditUserSelect();
50
+ Map<Integer, String> userList = userEditService.userEditUserSelect();
38
- {
51
+ {
39
- for(Map.Entry<Integer, String>entry :userList.entrySet()){
52
+ for(Map.Entry<Integer, String>entry :userList.entrySet()){
53
+ System.out.println(entry.getKey());
54
+ System.out.println(entry.getValue());
40
- put(entry.getKey(), entry.getValue());
55
+ put(entry.getKey(), entry.getValue());
56
+ }
41
57
  }
58
+ });
42
- System.out.println();
59
+ mav.setViewName("user-edit");
60
+ return mav;
43
- }
61
+ }
44
- });
62
+ }
63
+
64
+ ```
65
+ ```xml
66
+ <?xml version="1.0" encoding="UTF-8" ?>
67
+ <!DOCTYPE mapper
68
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
69
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
70
+ <mapper namespace="com.kproject01.mapper.UserEditMapper">
71
+ <select id="userEditUserSelect" resultType="map">
72
+ select
73
+ user_id,
74
+ first_nm
75
+ from
76
+ m_user
77
+ where
78
+ delete_flg = 0
79
+ </select>
80
+ </mapper>
81
+ ```
82
+ ```java
83
+ package com.kproject01.mapper;
84
+
85
+ import java.util.List;
86
+ import java.util.Map;
87
+
88
+ import org.apache.ibatis.annotations.MapKey;
89
+
90
+ import com.kproject01.entity.UserEditUserSelect;
91
+ import com.kproject01.entity.UserTop;
92
+
93
+ /**
94
+ * ユーザ編集ページ
95
+ * @author takahiro
96
+ *
97
+ */
98
+ public interface UserEditMapper {
45
99
 
100
+ //コンボボックスに格納するユーザID、ユーザ名を取得
101
+ @MapKey("userId")
102
+ Map<Integer, String> userEditUserSelect();
46
103
  }
47
104
 
48
105
  ```
49
106
  ### 補足情報(FW/ツールのバージョンなど)
50
- Map<Integer, String> userList = userEditService.userEditUserSelect();
107
+ xmlのresultTypeをhashmapにしたりエンティティにしたりしたのですが、うまくいかず
51
- ↑部分でエラーになってるようです。
108
+ 型が違うというのはなんとなく分かったのです。。。
52
109
 
53
110
  java8
54
111
  SpringBoot8