未找到Spring启动资源404错误html
我构建了一个名为Employer的crud应用程序。操作工作正常,但当在html控制台中显示它们时,显示未找到错误未找到Spring启动资源404错误html,spring,spring-boot,web,Spring,Spring Boot,Web,我构建了一个名为Employer的crud应用程序。操作工作正常,但当在html控制台中显示它们时,显示未找到错误 : Resource not found 2019-07-29 05:04:25.834 DEBUG 18656 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND 2019-07-29 05:04:25.834 DEBUG 18656 --- [nio-8
: Resource not found
2019-07-29 05:04:25.834 DEBUG 18656 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
2019-07-29 05:04:25.834 DEBUG 18656 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for GET "/error", parameters={}
2019-07-29 05:04:25.834 DEBUG 18656 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-07-29 05:04:25.834 DEBUG 18656 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
2019-07-29 05:04:25.834 DEBUG 18656 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Mon Jul 29 05:04:25 PDT 2019, status=404, error=Not Found, message=No message available, (truncated)...]
2019-07-29 05:04:25.835 DEBUG 18656 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 404
2019-07-29 05:04:37.741 DEBUG 18656 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : GET "/favicon.ico", parameters={}
2019-07-29 05:04:37.742 DEBUG 18656 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler [class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/], class path resource []]
2019-07-29 05:04:37.754 DEBUG 18656 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Completed 200 OK
:未找到资源
2019-07-29 05:04:25.834调试18656---[nio-8080-exec-1]o.s.web.servlet.DispatcherServlet:未找到已完成的404
2019-07-29 05:04:25.834调试18656---[nio-8080-exec-1]o.s.web.servlet.DispatcherServlet:“错误”调度获取“/错误”,参数={}
2019-07-29 05:04:25.834调试18656---[nio-8080-exec-1]s.w.s.m.m.a.RequestMappingHandlerMapping:映射到公共org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-07-29 05:04:25.834调试18656---[nio-8080-exec-1]o.s.w.s.m.m.a.HttpEntityMethodProcessor:使用'application/json',给定[*/*]并支持[application/json,application/*+json,application/json,application/*+json]
2019-07-29 05:04:25.834调试18656---[nio-8080-exec-1]o.s.w.s.m.m.a.HttpEntityMethodProcessor:正在写入[{timestamp=Mon Jul 29 05:04:25 PDT 2019,状态=404,错误=Not Found,消息=No message available,(截断)…]
2019-07-29 05:04:25.835调试18656---[nio-8080-exec-1]o.s.web.servlet.DispatcherServlet:退出“错误”调度,状态404
2019-07-29 05:04:37.741调试18656---[nio-8080-exec-3]o.s.web.servlet.DispatcherServlet:GET“/favicon.ico”,参数={}
2019-07-29 05:04:37.742调试18656---[nio-8080-exec-3]o.s.w.s.handler.SimpleUrlHandlerMapping:映射到ResourceHttpRequestHandler[class path resource[META-INF/resources/],class path resource[resources/],class path resource[static/],class path resource[public/],ServletContext resource[/],class path resource[]
2019-07-29 05:04:37.754调试18656---[nio-8080-exec-3]o.s.web.servlet.DispatcherServlet:完成200 OK
我尝试重新启动应用程序并更改实体的名称,但没有成功
EmployerController.java
package io.javabrains;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.hibernate.mapping.Index;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import io.javabrains.Entity.Employer;
@Controller
public class EmployerController {
@Autowired
private EmployerService service;
@RequestMapping("/")
public String newForm() {
return "form1";
}
public List<Employer>getAllEmployers()
{
return service.getAllEmployers();
}
@RequestMapping(value="/tables",method=RequestMethod.GET)
public String getAllEmployers(Model model)
{
List<Employer>employers = service.getAllEmployers();
model.addAttribute("Employer",employers);
return "tables";
}
@RequestMapping("/employer/{id}")
public Employer getEmployer(@PathVariable Integer id) {
return service.getEmployers(id);
}
@RequestMapping(method=RequestMethod.POST,value="/employer")
public void addEmployer(@RequestBody Employer employer) {
service.addEmployer(employer);
}
@RequestMapping(method=RequestMethod.PUT,value="/employer/{id}")
public void updateEmployer(@RequestBody Employer employer,@PathVariable int id) {
service.updateEmployer(id,employer);
}
@RequestMapping(method=RequestMethod.DELETE,value="/create/{id}")
public void deleteEmployer(@PathVariable int id)
{
service.deleteEmployer(id);
}
}
包io.javabrains;
导入java.util.List;
导入javax.servlet.http.HttpServletRequest;
导入org.hibernate.mapping.Index;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.Model;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.bind.annotation.PathVariable;
导入org.springframework.web.bind.annotation.RequestBody;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.RestController;
导入io.javabrains.Entity.Employer;
@控制器
公共类EmployeerController{
@自动连线
私人雇员服务;
@请求映射(“/”)
公共字符串newForm(){
返回“form1”;
}
公共列表GetAllEmployers()
{
return service.getAllEmployers();
}
@RequestMapping(value=“/tables”,method=RequestMethod.GET)
公共字符串getAllEmployers(模型)
{
Listemployers=service.getAllEmployers();
模型。添加属性(“雇主”,雇主);
返回“表”;
}
@请求映射(“/employer/{id}”)
公共雇主getEmployer(@PathVariable整数id){
返回服务。getEmployers(id);
}
@RequestMapping(method=RequestMethod.POST,value=“/employer”)
公共无效addEmployer(@RequestBody-Employer){
服务。雇主(雇主);
}
@RequestMapping(method=RequestMethod.PUT,value=“/employer/{id}”)
public void updateEmployer(@RequestBody-Employer,@PathVariable-int-id){
服务更新雇主(id,雇主);
}
@RequestMapping(method=RequestMethod.DELETE,value=“/create/{id}”)
public void deleteEmployer(@PathVariable int-id)
{
服务。删除雇主(id);
}
}
EmployerService.java
package io.javabrains;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.javabrains.Entity.Employer;
@Service
public class EmployerService {
@Autowired
private Repository repository;
public List<Employer>getAllEmployers(){
List<Employer>employers = new ArrayList<>();
repository.findAll()
.forEach(employers::add);
return employers;
}
public void addEmployer(Employer employer) {
repository.save(employer);
}
public void updateEmployer(int id, Employer employer) {
repository.save(employer);
}
public void deleteEmployer(int id) {
repository.deleteById(id);
;
}
public Employer getEmployers(int id)
{
return repository.getOne(id);
}
}
包io.javabrains;
导入java.util.ArrayList;
导入java.util.List;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Service;
导入io.javabrains.Entity.Employer;
@服务
公共类雇员服务{
@自动连线
私有存储库;
公共列表GetAllEmployers(){
Listemployers=newarraylist();
repository.findAll()
.forEach(雇主::添加);
返回雇主;
}
公共无效雇主(雇主){
保存(雇主);
}
public void updateEmployer(内部id,雇主){
保存(雇主);
}
公共部门(内部id){
repository.deleteById(id);
;
}
公共雇主(内部id)
{
返回repository.getOne(id);
}
}
雇主:Java
package io.javabrains;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.javabrains.Entity.Employer;
@Service
public class EmployerService {
@Autowired
private Repository repository;
public List<Employer>getAllEmployers(){
List<Employer>employers = new ArrayList<>();
repository.findAll()
.forEach(employers::add);
return employers;
}
public void addEmployer(Employer employer) {
repository.save(employer);
}
public void updateEmployer(int id, Employer employer) {
repository.save(employer);
}
public void deleteEmployer(int id) {
repository.deleteById(id);
;
}
public Employer getEmployers(int id)
{
return repository.getOne(id);
}
}
包io.javabrains;
导入java.util.ArrayList;
导入java.util.List;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Service;
导入io.javabrains.Entity.Employer;
@服务
公共类雇员服务{
@自动连线
私有存储库;
公共列表GetAllEmployers(){
Listemployers=newarraylist();
repository.findAll()
.forEach(雇主::添加);
返回雇主;
}
公共无效雇主(雇主){
保存(雇主);
}
public void updateEmployer(内部id,雇主){
保存(雇主);
}
公共部门(内部id){
repository.deleteById(id);
;
}
公共雇主(内部id)
{
返回repository.getOne(id);
}
}
table.html
<tbody>
<tr th:each="$(employers)">
<td th:text="${employers.name}"></td>
<td th:text="${employer.position}"></td>
<td th:text="${employer.office}"></td>
<td th:text="${employer.age}"></td>
<td th:text="${employer.salary}"></td>
</tr>
@RequestMapping(path="/template")
public ModelAndView getHelloTemplate(){
ModelAndView model = new ModelAndView();
model.setViewName("hello");
model.addObject("message", "Hello World");
return model;
}
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-freemarker</artifactId>-->
<!--<version>2.1.2.RELEASE</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
@Controller(value = "tvGuideController")
public class TvGuideController {
@RequestMapping(path="/template")
public ModelAndView getHelloTemplate(){
ModelAndView model = new ModelAndView();
model.setViewName("hello");
model.addObject("message", "Hello World");
return model;
}
@RequestMapping(path="/template1")
public String getHelloTemplate(Model model){
model.addAttribute("message", "Hello World 1");
return "hello";
}
@RequestMapping(path="/template2")
public String getHelloTemplate(ModelMap model){
model.addAttribute("message", "Hello World 2");
return "hello2";
}
}
git clone https://github.com/fiveobjects/reference.git
cd java/springboot
mvn spring-boot:run
http://localhost:8080/template
http://localhost:8080/template1
http://localhost:8080/template2