今天写了第一个springboot程序 ,跳转了.HTML
记录一下踩的坑,方便下一次查询。
先上代码
文件结构:
controller层:
Hello.java
package cn.cxc.helloworld.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author chenxiaochong
* @date 2019/9/26 17:51
*/
@Controller
public class Hello {
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String hello() {
return "static/hello";
}
@ResponseBody
@RequestMapping(value = "/hello1",method = RequestMethod.GET)
public String hello1() {
return "hello";
}
}
pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
hello.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>第一个页面</title>
</head>
<body>
<form action="/hello1" method="get">
账号:<input type="text" name="text" value="123"><br>
密码:<input type="password" name="password" value="321"><br>
提交:<input type="submit"><br>
重置: <input type="reset">
</form>
</body>
</html>
以上!
踩过的坑:
.html文件默认放在resources下的templates文件夹中,把.html文件放在这下面就不用再考虑配置变量。