我目前正在Spring Boot中开发常见问题Web应用程序。我的索引页面运行良好,但如果我想打开另一个超文本标记语言页面,我的浏览器中会出现404未找到错误页面,Intellij说:
WARN 8068 --- [nio-8080-exec-6] o.s.web.servlet.PageNotFound : No mapping for GET /new
我怎样才能解决这个问题?
索引控制器:
@Controller
public class IndexController {
@Autowired
private FAQService service;
@RequestMapping("/")
public String viewHomePage(Model model) {
List<FAQ> listFaqs = service.listAll();
model.addAttribute("listFaqs", listFaqs);
return "index";
}
@RequestMapping("/home")
public String backHomePage(Model model) {
List<FAQ> listFaqs = service.listAll();
model.addAttribute("listFaqs", listFaqs);
return "index";
}
@RequestMapping("/new")
public String showNewProductForm(Model model) {
FAQ faq = new FAQ();
model.addAttribute("faq", faq);
return "new_product";
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveProduct(@ModelAttribute("faq") FAQ faq) {
service.save(faq);
return "redirect:/";
}
@RequestMapping("/edit/{id}")
public ModelAndView showEditProductPage(@PathVariable(name = "id") int id) {
ModelAndView mav = new ModelAndView("edit_faq");
FAQ faq = service.get(id);
mav.addObject("faq", faq);
return mav;
}
@RequestMapping("/delete/{id}")
public String deleteProduct(@PathVariable(name = "id") int id) {
service.delete(id);
return "redirect:/";
}
指数html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org" xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3" lang="en">
<link rel="stylesheet" type="text/css" th:href="@{/static/css/styles.css}"/>
<head>
<title>WebApp</title>
</head>
<body>
<div align="center"><h3 th:inline="text">Welcome [[${#httpServletRequest.remoteUser}]]</h3></div>
<div class="logout-btn" th:align="center">
<a th:href="@{/logout}"><button>Logout</button></a>
</div>
<div align="center">
<br>
<h1>Manage Excel Files</h1>
<th:block th:include="/_menu"></th:block>
<div class="ncontent-btn">
<a href="/new"><button>New Entry</button></a>
<a th:href="@{/excel/export}"><button>Export to Excel</button></a>
</div>
<br/>
</div>
</body>
</html>
xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.22</version>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
应用属性
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=5MB
spring.servlet.multipart.max-request-size=10MB
spring.mvc.dispatch-options-request=true
spring.datasource.continue-on-error=true
spring.mvc.static-path-pattern=/static/**
spring.jpa.open-in-view=false
我的所有HTML文件都位于/resources/templates路径中。
您正在以/new方法返回“new_product”。您必须创建一个新的产品视图(new\u product.jsp/new\u product.html.)在里面做任何你想做的事,然后一切都会好起来,你会得到200的回复。
如果文件已经存在,则可能路径不正确,您必须对其进行配置。尝试将html文件放在静态文件夹中,否则请在应用程序中添加路径。属性
我使用SpringBoot start构建了一个用于学习的项目 但是当我添加由mybatis生成器生成的orm文件时,它启动失败。 例如: 我已经配置了mybatis locationmapper属性和sqlSessionFactoryBean 这是我的application.properties文件:
我正在尝试使用spring MVC。我的问题是,在我的控制器中没有请求映射工作,只有我的主页链接:“/”工作。 我的web.xml文件是: 2019年5月9日下午4:55:42 org.springframework.web.servlet.dispatcherservlet noHandlerFound警告:GET/springmvc/showform没有映射
Object文字符号在map函数中不起作用吗?我在节点12和15 REPL中尝试过
如何检索找到的标记映射(例如),以便验证文本是否已正确映射到标记?
在get方法中尝试在springboot中按id查找行时,收到一个空值。我在这里对数据库的调用是否有误? 存储库- 服务- 控制器-
当我重命名应用程序packagename并尝试启动springboot时,我得到一条错误消息。错误消息如下: