我开始学习Spring Boot,但我无法通过初学者指南来显示模型属性
我的模型控制器
package com.rahulweb.spring.springtest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ModelController {
@RequestMapping("/test")
public String demo(Model model) {
Person person = new Person();
person.setName("Rahul");
person.setAge("22");
model.addAttribute("person", person);
return "index";
}
}
和我的index.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"></meta>
<title>Insert title here</title>
</head>
<body>
FirstName :<span th:text="${person.name}"></span>
Age : <span th:text="${person.age}"></span>
</body>
</html>
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rahulweb.spring</groupId>
<artifactId>springtest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestModel</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</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-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
当运行maven clean and install时,在控制台中得到以下错误
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestModel 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ springtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ springtest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\Users\SINGH\Documents\Spring\TestModel\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.297 s
[INFO] Finished at: 2016-11-01T10:33:39+05:30
[INFO] Final Memory: 16M/180M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project springtest: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
我的Spring开机入门课
package com.rahulweb.spring.springtest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestModelApplication {
public static void main(String[] args) {
SpringApplication.run(TestModelApplication.class, args);
}
}
你能试着运行下面的命令吗,你在github中引用的项目正在我的机器上为我工作。
mvn clean package
或
MVN clean install-u
(这将刷新所有依赖项并重新下载它们)
然后运行应用程序
$ mvn spring-boot:run
我坚持使用这个简单的MVC示例。当我启动应用程序并转到localhost:8080时,我得到了“白标签错误页面”,甚至我在“src/main/资源/模板”中创建了“index.html”。我还在我的索引方法上添加了@Request estMap(“/”)。我找不到问题。 : : -在"src/main/资源/模板"下:
下面是我的代码:我正在从application.properties文件swagerconfig.java获取所有值 下面是我的springboot初始值设定项: ServletInitializer.java 日志显示它已映射: 这是我得到的错误:
这也没有空格啊,为什么会高出一些? font-size: 0; 这样可以解决,但空格都没有这个属性作用到哪里去了?
我试图创建一个spring boot starter项目。当我试着运行这个时,我遇到了这个错误。 白标签错误页面 此应用程序没有 /error的显式映射,因此您将此视为后备。 Fri Dec29 14:16:46IST 2017有一个意外的错误(type=未找到,status=404)。/ 我将jsp文件添加到src/web-inf/views中/ 已添加 Springmvc。看法前缀=/WEB-
我不知道如何解决这个问题 spring端:role.java 因此,如果我现在尝试inline=“javascript”: 当我运行它时,我得到这样的响应: 白标签错误页