由于要跳轉(zhuǎn)頁面,我這里使用thymleaf模板
引入了Spirng Boot對thymleaf模板引擎的依賴。版本(Mar 03, 2017)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
寫幾個簡單的頁面,用thymleaf模板的一些配置在我簡書的一篇文章也有寫到http://www.itdecent.cn/p/381e02c283f3
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Insert title here</title>
</head>
<body>
<h1>index</h1>
</body>
</html>
login.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Insert title here</title>
</head>
<body>
錯誤信息:<h4 th:text="${msg}"></h4>
<form action="" method="post">
<p>賬號:<input type="text" name="username" value="admin"/></p>
<p>密碼:<input type="text" name="password" value="123456"/></p>
<p><input type="submit" value="登錄"/></p>
</form>
</body>
</html>
寫完之后是訪問不了login頁面的,是因為還沒寫Controller,不能寫成@RestController,因為不是返回json數(shù)據(jù),而是跳轉(zhuǎn)頁面
@Controller
public class HomeController {
@RequestMapping({"/","/index"})
public String index(){
return"/index";
}
@GetMapping("login")
public String login(){
return"login";
}
}
接下來再創(chuàng)建兩個頁面,userInfo和userInfoAdd
userInfo
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<h3>用戶查詢界面</h3>
</body>
</html>
userInfoAdd
<!DOCTYPE html>
<html lang="en">
<head>
<title>Insert title here</title>
</head>
<body>
<h3>用戶添加界面</h3>
</body>
</html>
userInfoDel
<!DOCTYPE html>
<html lang="en">
<head>
<title>Insert title here</title>
</head>
<body>
<h3>用戶刪除界面</h3>
</body>
</html>
當然了,后面這是要一定權限才可以登錄進去的,那怎么做了,接下來再講