编辑:下面是LatherupApplication应用程序类:
package latherup.com.latherup;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication(scanBasePackages = "latherup.com")
public class LatherupApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(LatherupApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(LatherupApplication.class, args);
}
}
下面是我家控制器:
package latherup.com.latherup;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/home")
public class HomeController {
@GetMapping("/home")
public String navigateToHomePage() {
return "home.jsp";
}
}
下面是pom.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>latherup.com</groupId>
<artifactId>latherup</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>latherup</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>13</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap-datepicker</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
</dependencies>
<build>
<!--plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins-->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
下面是home.jsp:
<html>
<head>
<title>Welcome</title>
<link href="webjars/bootstrap/3.3.6/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<div class="container">
<table class="table table-striped">
<caption>Your todos are</caption>
<thead>
<tr>
<th>Description</th>
<th>Target Date</th>
<th>Is it Done?</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td>Todo 1</td>
<td>10/12/2017</td>
<td>No</td>
<td><a class="btn btn-warning" href="/edit-todo">Edit Todo</a></td>
<td><a class="btn btn-warning" href="/delete-todo">Delete Todo</a></td>
</tr>
</tbody>
</table>
<div>
<a class="btn btn-default" href="/add-todo">Add a Todo</a>
</div>
<script src="webjars/jquery/1.9.1/jquery.min.js"></script>
<script src="webjars/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</div>
</body>
</html>
应用程序.属性:
spring.mvc.view.prefix=/LATHER-UP/jsp/
spring.mvc.view.suffix=.jsp
logging.level.org.springframework.web=INFO
您正在使用RestController
返回JSP。使用controller
注释处理视图部件。
在这里阅读更多关于它的控制器
我正在使用Spring形式。我只需要得到Staemap作为响应,但我得到的是整个jsp页面作为响应。
但是,当我返回列表时,就像这段代码: 对于完全相同的API的列表返回类型的响应是正确的响应: [{“SellingPrice”:23000,“ID”:1,“Version”:1,“CreatedOn”:“25Feb 2019,05:53”,“LastUpdatedOn”:“25Feb 2019,05:53”}]
我无法在SpringBoot中呈现html页面。这是密码... 但当我点击http://localhost:8080/home时,它会显示以下日志
你好,我是拉威尔的新手,也许这对你们来说太傻了。在laravel 8中,路由web。php我创建了一条如下的路线: 我想问的是,我们也可以从回调视图返回控制器吗?所以在路由 /editprofile中,第二个参数不是'App\Http\Controller\SiteController@edit_profile',而是一个回调函数,如路由'/home'。 但是它返回错误哈哈。假设我不想用__con
我不知道该用什么。我有两页——简介。jsp(1)和booksList.jsp(2)。对于每个页面,我都创建了一个控制器类。第一页有打开第二页的按钮: 第一个问题是:我不确定这个按钮的正确性。它工作得很好,但是按下这个按钮后我有问号。 第二个问题是:当我按下该按钮时,调用带有下一个注释的方法(第二页的控制器): 我应该用这种方法返回什么?换句话说,我怎么能从第一页跳到第二页? < li> < li>
目标是打印标签的当前文本。标签在整个程序中不断变化,使用当前的方法,我只能检索标签的初始化值。 我用来检索控制器实例的内容: