-1
I am developing a Java application with Spring Boot, however, Controller is not able to find HTML, apparently...
Page not being found
Previsão do tempo
<table class="table">
<thead>
<tr>
<th scope="col">Dia</th>
<th scope="col">Temp. Mínima</th>
<th scope="col">Temp. Máxima</th>
<th scope="col">Humidade</th>
<th scope="col">Descrição</th>
<th scope="col">Data</th>
<th scope="col">latitude</th>
<th scope="col">Longitude</th>
</tr>
</thead>
<tbody>
<tr th:each="previsao : ${prev}">
<td th:text="${previsao.dia}"></td>
<td th:text="${previsao.minima}"></td>
<td th:text="${previsao.maxima}"></td>
<td th:text="${previsao.humidade}"></td>
<td th:text="${previsao.descri}"></td>
<td th:text="${previsao.data}"></td>
<td th:text="${previsao.latitude}"></td>
<td th:text="${previsao.longitude}"></td>
</tr>
</tbody>
</table>
Login controller that directs the page
package br.usjt.previsao.controller;
import javax.servlet.http.HttpServletRequest;
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.servlet.ModelAndView;
import br.usjt.previsao.model.Usuario;
import br.usjt.previsao.service.UsuarioService;
@Controller
public class LoginController {
@Autowired
private UsuarioService loginService;
@GetMapping(value = { "/login", "/" })
public ModelAndView login() {
ModelAndView mv = new ModelAndView("login");
mv.addObject(new Usuario());
return mv;
}
@PostMapping("/fazerLogin")
public String fazerLogin(HttpServletRequest request, Usuario usuario) {
if (loginService.logar(usuario)) {
request.getSession().setAttribute("usuarioLogado", usuario);
return "redirect:index";
} else {
return "login";
}
}
}
Controller of the main application
package br.usjt.previsao.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import br.usjt.previsao.model.PrevTempo;
import br.usjt.previsao.service.PrevService;
public class PrevController {
@Autowired
private PrevService prevservice;
@GetMapping ("/previsao")
public ModelAndView listarPrev() {
ModelAndView mv = new ModelAndView("index");
mv.addObject(new PrevTempo());
List<PrevTempo> prev = prevservice.listardias();
mv.addObject("previsao", prev);
mv.addObject(new PrevTempo());
return mv;
}
// MÉTODO PARA RETORNAR A PÁGINA INICIAL UTILIZANDO POST
@PostMapping
public String salvar(PrevTempo previsao) {
prevservice.salvar(previsao);
return "redirect:/index";
}
}
where is the page file physically? spring defaults to a folder for static files.
– Caio Augusto Papai
Check if the index.html page is in
src/main/resources/templates
and whether it has the mapping to index in the controller.– Jota Freitas Jr