Я использую MySQL Ver 15.1 Distrib 10.1.38-MariaDB для debian-linux-gnu (x86_64).
Open-JDK 1.8.0
Пружинный ботинок 2.1.4 RELEASE
Получая доступ к моему приложению, я получил эту трассировку стека на своей странице, доступной для рисования:
This application has no explicit mapping for /error, so you are seeing
this as a fallback.
Mon May 27 16:12:06 AZOST 2019
There was an unexpected error (type=Internal Server Error, status=500).
No method or field with name 'id' on line 15
com.samskivert.mustache.MustacheException$Context: No method or field
with name 'id' on line 15
at com.samskivert.mustache.Template.checkForMissing(Template.java:326)
at com.samskivert.mustache.Template.getValue(Template.java:234)
at com.samskivert.mustache.Template.getValueOrDefault(Template.java:279)
at com.samskivert.mustache.Mustache$VariableSegment.execute(Mustache.java:802)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:881)
at com.samskivert.mustache.Template.executeSegs(Template.java:157)
at com.samskivert.mustache.Template.execute(Template.java:134)
at org.springframework.boot.web.servlet.view.MustacheView.renderMergedTemplateModel(MustacheView.java:81)
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:178)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
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:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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:92)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Это мой код:
main.mustache
<html>
<body>
<div>
<form method="POST">
<input type ="text" name="text" placeholder="Введите сообщение" />
<input type ="text" name="tag" placeholder="Тег"/>
<button type="submit">Добавить</button>
</form>
</div>
<div>Message list</div>
{{#messages}}
<div>
<b>{{id}}</b>
<span>{{text}}</span>
<i>{{tag}}</i>
</div>
{{/messages}}
Это мой контроллер:
GreetingController
package com.example.sweater;
import com.example.sweater.domain.Message;
import com.example.sweater.repos.MessageRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
@Controller
public class GreetingsController {
@Autowired
private MessageRepo messageRepo;
@RequestMapping("/greeting")
public String greeting(@RequestParam(name="name", required = false, defaultValue = "World") String name,
Map<String, Object> model)
{
model.put("name", name);
return "greeting";
}
@GetMapping
public String main(Map<String, Object> model){
Iterable<Message> messages = messageRepo.findAll();
model.put("messages", "messages");
return "main";
}
@PostMapping
public String add(@RequestParam String text, @RequestParam String tag, Map<String, Object> model){
Message message = new Message(text, tag);
messageRepo.save(message);
Iterable<Message> messages = messageRepo.findAll();
model.put("messages", messages);
return "main";
}
}
Это моя структура проекта:
! [ProjectStructure]: (https://lh3.googleusercontent.com/PKENYsmd29WxawAs-jMtrwBTBqDHNMoS3LWU_BTyDOjO7L5z8DrojsmB-pHfb03QE2Ce7Q3_xE4HrMk3PZax06Cd2b-NY42pB9e5DzCv-Uh6VlkbtebFb2W0HYq8u7WaG7WWU7uC7_7z5x8TXTXl65Wg-rMCes6HkQ8PTQ2_-QOMBW_I2yV8dXN2Xs2-vsHAWX5upPKw2oi3ZAtxOVvDKUm-znDD4czMIPAMKsDAfBXWWf5QbVpTysOEoE_rF7_7z9lWBf0ujZBYpllK5aXxsWB0OorsnnLb9XvmCMaGU-3xsOykLRFiq_LcYk5erFkEsBSkkobYT67ZPIPxrcnC3iGluBy5IYjDUrhwVpn-WPv76RsEID0qF0PYrAGO01M1Xb0QzhOJjx0wKsIKIDBRSEfxSRSLp-rGVW0rsDF_VIQeRXLs-Bvt45LznMXIBjCH_OLA3sg5p7RsgmiiRrjtsFhKmH-GOUds1GvrUTfpdpjlcySm_vpYK84WhyGfc64As45xB04w62mkD0LgZpw9pFcENbp8l9_MNhRlh0dLccB0Tku5H9h1-9H4FD3OzHYlw6SlsoNfYob_7BeZK3QXaTujtu1K7Hn-5zaxJ_oI4Ea_4P59BSmzAp6X_D6O0Rs9rZ8zPtSPNHiBzB6SP_vOuCfMuOAa8w=w340-h520-no)
Я ожидал, что этот код будет отображать HTML-код с пустыми полями, ожидая, пока я заполню их, получу доступ к базе данных и покажу все кортежи, которые были введены в пустые поля, но вместо этого я наткнулся на эту трассировку стека. Что я должен исправить, чтобы он работал правильно?