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

質問編集履歴

3

エラーの追記

2020/12/05 15:05

投稿

pani-pani
pani-pani

スコア3

title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,12 @@
7
7
  ### 発生している問題・エラーメッセージ
8
8
 
9
9
  ```
10
+ 追記したエラーになります。
11
+ 2020-12-05 23:56:38.489 ERROR 19732 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/test1.html]")] with root cause
12
+
13
+ org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'day1_st1' cannot be found on null
14
+
15
+ 先ほど回答を頂いた方に言及して頂いたエラーになります。
10
16
  java.lang.IllegalStateException: No primary or single public constructor found for interface org.springframework.security.core.Authentication - and no default constructor found either
11
17
  ```
12
18
 

2

追記の為

2020/12/05 15:05

投稿

pani-pani
pani-pani

スコア3

title CHANGED
File without changes
body CHANGED
@@ -78,7 +78,40 @@
78
78
 
79
79
  }
80
80
  ```
81
+ Attendance.java
82
+ ```
83
+ package com.example.demo.model;
81
84
 
85
+ import javax.persistence.Entity;
86
+ import javax.persistence.GeneratedValue;
87
+ import javax.persistence.GenerationType;
88
+ import javax.persistence.Id;
89
+ import javax.validation.constraints.Size;
90
+
91
+ import lombok.Getter;
92
+ import lombok.Setter;
93
+
94
+ @Getter
95
+ @Setter
96
+ @Entity
97
+ public class Attendance {
98
+ @Id
99
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
100
+ private Long id;
101
+
102
+ @Size(min = 2, max = 20)
103
+ private String username;
104
+
105
+ private int month;
106
+
107
+ private int day1_st1;
108
+ private int day1_st2;
109
+ private int day1_end1;
110
+ private int day1_end2;
111
+
112
+ }
113
+ ```
114
+
82
115
  ### 試したこと
83
116
  コントローラのmv.addObject("attendance", new Attendance());
84
117
  htmlの th:object="${Attendance}"とth:value= を削除したところ、entitiyと関係のないhtmlの出力はできたので、entitiyに問題があると考えています。

1

追記の為

2020/12/05 14:25

投稿

pani-pani
pani-pani

スコア3

title CHANGED
File without changes
body CHANGED
@@ -1,2 +1,88 @@
1
1
  現在、勤怠管理ができるアプリを作ろうと思っています。その中で、
2
- spring boot で entityとして作成したクラスに値を入力したいと思っていますが、エラーが出てています。
2
+ spring boot で entityとして作成したクラスに値を入力したいと思っていますが、エラーが出てています。
3
+ ### 前提・実現したいこと
4
+
5
+
6
+
7
+ ### 発生している問題・エラーメッセージ
8
+
9
+ ```
10
+ java.lang.IllegalStateException: No primary or single public constructor found for interface org.springframework.security.core.Authentication - and no default constructor found either
11
+ ```
12
+
13
+ ### 該当のソースコード
14
+ test1.html
15
+ ```ここに言語名を入力
16
+ <!DOCTYPE html>
17
+ <html xmlns:th="http://www.thymeleaf.org">
18
+ <head>
19
+ <meta charset="UTF-8">
20
+ <title>Insert title here</title>
21
+ </head>
22
+ <body>
23
+ border="1" width="50%" align="center">
24
+ <form th:action="@{/attendance}" th:object="${Attendance}" method="post">
25
+ <tr><!-- ここから -->
26
+ <td th:text=${month}></td>
27
+ <th><input type="number" name="day1_st1" th:value="*{day1_st1}"max = 24 min = 0 >:<input type=number name="day1_st2" th:value="*{day1_st2}" max = 60 min = 0 ></th><!-- ここに出金時間を入れます -->
28
+ <th><input type="number" name="day1_end1" th:value="*{day1_end1}"max = 24 min = 0 >:<input type=number name="day1_end2" th:value="*{day1_end2}" max = 60 min = 0 ></th><!-- ここに退勤時間を入れます -->
29
+ <th></th><!-- ここに休憩時間を入れます -->
30
+ <th>勤務時間</th><!-- ここに勤務時間を入れます -->
31
+ </tr><!-- ここまで -->
32
+
33
+
34
+
35
+
36
+ </body>
37
+ </html>
38
+ ```
39
+
40
+
41
+ SecurityController.java
42
+ ```ここに言語名を入力
43
+
44
+ package com.example.demo.controller;
45
+
46
+ import org.springframework.security.core.Authentication;
47
+ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
48
+ import org.springframework.stereotype.Controller;
49
+ import org.springframework.ui.Model;
50
+ import org.springframework.validation.BindingResult;
51
+ import org.springframework.validation.annotation.Validated;
52
+ import org.springframework.web.bind.annotation.GetMapping;
53
+ import org.springframework.web.bind.annotation.ModelAttribute;
54
+ import org.springframework.web.bind.annotation.PostMapping;
55
+ import org.springframework.web.servlet.ModelAndView;
56
+
57
+ import com.example.demo.model.Attendance;
58
+ import com.example.demo.model.SiteUser;
59
+ import com.example.demo.repository.AttendanceRepository;
60
+ import com.example.demo.repository.SiteUserRepository;
61
+ import com.example.demo.util.Role;
62
+
63
+ import lombok.RequiredArgsConstructor;
64
+ @RequiredArgsConstructor
65
+ @Controller
66
+ public class SecurityController {
67
+
68
+ private final SiteUserRepository userRepository;
69
+ private final BCryptPasswordEncoder passwordEncoder;
70
+ private final AttendanceRepository attendanceRepository;
71
+ (...)
72
+ @GetMapping("/attendance")
73
+ public ModelAndView createAttendance (ModelAndView mv, @ModelAttribute("attendance") Authentication SiteUser) {
74
+ mv.setViewName("test1");
75
+ mv.addObject("attendance", new Attendance());
76
+ return mv;
77
+
78
+
79
+ }
80
+ ```
81
+
82
+ ### 試したこと
83
+ コントローラのmv.addObject("attendance", new Attendance());
84
+ htmlの th:object="${Attendance}"とth:value= を削除したところ、entitiyと関係のないhtmlの出力はできたので、entitiyに問題があると考えています。
85
+
86
+ ### 補足情報(FW/ツールのバージョンなど)
87
+ Spring Tools 4 for Eclipse
88
+ Spring Boot 2. 3. 5