前提・実現したいこと
ここに質問の内容を詳しく書いてください。
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
エラーメッセージ
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/new.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/new.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(
org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118)
at org.springframework.web.servlet.DispatcherServlet.doDispatch()
at org.springframework.web.servlet.FrameworkServlet.processRequest(6) at org.springframework.web.servlet.FrameworkServlet.doPost() at org.springframework.web.servlet.FrameworkServlet.service at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter( at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(19) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "d1" (template: "new" - line 38, col 5)
... 48 more
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "d1" (template: "new" - line 38, col 5)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'd1' cannot be found on object of type 'com.example.demo.domain.Date' - maybe not public or not valid?
該当のソースコード
ソースコード package com.example.demo.domain; @Entity @Table(name="date") public class Date { private LocalDate d1; @GeneratedValue private Long id; @Id private String word; private String name; private int year; private int month; private int day; public void setId(Long id) { this.id=id; } public Long getId() { return id; } public void setWord(String word) { this.word=word; } public String getWord() { return word; } public void setName(String name) { this.name=name; } public String getName() { return name; } public void setYear(int year) { this.year=year; } public int getYear() { return year; } public void setMonth(int month) { this.month=month; } public int getMonth() { return month; } public void setDay(int day) { this.day=day; } public int getDay() { return day; } public void setL(LocalDate d1) { this.d1=d1; } public LocalDate getL() { return d1; } public void calculate(LocalDate X) { LocalDate R= X.plusYears(getYear()); LocalDate R1= R.plusMonths(getMonth()); LocalDate d1= R1.plusDays(getDay()); } package com.example.demo.controller; @Controller @RequestMapping("/") public class dateController { @Autowired dateMapper mapper; @Autowired private dateRepository repository; @GetMapping public String top(Model model) { model.addAttribute("dates", mapper.findAll()); return "new"; } @PostMapping("/new") public String create(@ModelAttribute Date date,Model model) { mapper.save(date); return "redirect:/"; } @GetMapping("/edit/{word}") public ModelAndView edit(@PathVariable String word, @ModelAttribute Date date ,ModelAndView mav) { mav.addObject("date",mapper.findOne(word) ); mav.setViewName("edit"); return mav; } @PostMapping("/edit") @Transactional public String update( @ModelAttribute("date")Date date, Model model) { mapper.update(date); return "redirect:/"; } @PostMapping("/calculate") public String cal( @RequestParam("d")LocalDate d ,Model model) { List<Date> D=repository.findAll(); for(int i=0;D.size()>i;i++) { D.get(i).calculate(d); } model.addAttribute("R",repository.findAll()); return "new"; } @PostMapping("/delete/{word}") public String delete(@PathVariable String word ,Model model) { mapper.delete(word); return "redirect:/"; } } html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> 計算式 <th:text="${msg}"> <form th:objext="${form}" th:method="post" th:action="@{/new}"> 日付ID <input type="text" name="word" th:value="${word}" ><br> 名前<input type="text" name="name" th:value="${name}"><br> 加減(Y)<input type="text" name="year" th:value="${year}"><br> 加減(M)<input type="text" name="month" th:value="${month}"><br> 加減(D)<input type="text" name="day" th:value="${day}"><br> <button type="submit">登録</button> </form> 日付 <form method="post" th:action="@{/calculate}" th:object="${date}" ><input type="datetime" placeholder="yyyy/MM/dd" name="d" th:value="${d}"> <button value="submit">実行</button> </form> <td th:text="${result}"></td> <table> <tr > <td>id</td> <td>日付ID</td> <td>名前</td> <td >結果</td> <td >加減(Y/M/D)</td> </tr> <tr th:each="obj:${R}" th:object="${obj}"> <td th:text="*{id}"></td> <td th:text="*{word}" ></td> <td th:text="*{name}"></td> <td th:text="*{d1}" ></td> <td th:text="|*{year}/*{month}/*{day}|"> <td><form method="get" th:action="@{/edit/{word}(word=*{word})}"> <button value="submit">更新</button></form></td> <td><form method="post" th:action="@{/delete/{word}(word=*{word})}"> <button value="submit">削除</button> </form></td> </table> </body> </html> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.demo.mapper.dateMapper"> <select id="findAll" resultType="com.example.demo.domain.Date"> select * from date </select> <select id="findOne" resultType="com.example.demo.domain.Date"> select * from date where word= #{word} </select> <insert id="save" useGeneratedKeys="true" keyProperty="word"> insert into date (id,word, name , year,month,day) values(#{id},#{word}, #{name}, #{year},#{month},#{day}) </insert> <update id="update"> update date set name=#{name}, year=#{year},month=#{month},day=#{day} where word= #{word} </update> <delete id="delete"> delete from date where word = #{word} </delete> </mapper> package com.example.demo.mapper; @Mapper public interface dateMapper { List<Date> findAll(); Date findOne(String word); void save(Date date); void update(Date date); void delete(String word); } ### 試したこと ここに問題に対して試したことを記載してください。 ### 補足情報(FW/ツールのバージョンなど) springboot eclipse ![イメージ説明](5b93c6dcdc6f10266d717dfe02357ba6.png) ここにより詳細な情報を記載してください。 日付IDをプライマリーキーにして年、月、日の加減 の数値を計算式として登録して任意の日付に対して結果を表示させるアプリを作っていますが、計算結果と登録した式を一緒に表示させることができません。
回答1件
あなたの回答
tips
プレビュー