Ank*_*ane 6 java spring spring-mvc spring-boot
这是一个 springboot 应用程序。它运行完美,但没有得到输出(它在浏览器中显示 HTTP 状态 404 错误)
pom.xml
<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.exaample.demo</groupId>
<artifactId>SpringBootMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Maven spring boot project</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
Run Code Online (Sandbox Code Playgroud)
Springboot启动类 Main方法
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WebMainMethod {
public static void main(String[] args) {
SpringApplication.run(WebMainMethod.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器在主类之后加载
**Rest Controller**
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHi() {
return "Hi";
}
}
Run Code Online (Sandbox Code Playgroud)
网址: http://localhost:8080/hello 输出


Nip*_*ana -2
您是否创建了一个名为 hi 的 jsp 或 html 页面...检查您的视图...您没有要查看的页面...请创建一个 jsp 并将其放在
@RequestMapping("/hello")
public String sayHi(Model model) {
model.addAttribute("Hi","Hi")
return "Hi";
}
Run Code Online (Sandbox Code Playgroud)
jsp页面必须是Hi
| 归档时间: |
|
| 查看次数: |
12340 次 |
| 最近记录: |