且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

springboot集成shiro前的工作

更新时间:2022-08-12 16:14:14

由于要跳转页面,我这里使用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.jianshu.com/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数据,而是跳转页面

@Controller
public class HomeController {
    @RequestMapping({"/","/index"})
    public String index(){
        return"/index";
    }

    @GetMapping("login")
    public String login(){
        return"login";
    }
}

接下来再创建两个页面,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>

当然了,后面这是要一定权限才可以登录进去的,那怎么做了,接下来再讲

文章主要参考于作者林祥纤的博客

http://412887952-qq-com.iteye.com/blog/2299732