在SpringBoot框架下,页面通过service层return回html页面后设置的背景图片失效不显示,该如何解决?
图片存储路径如下
前端html代码如下
<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<style>
body{
width: 100%;
height: 100vh;/*屏幕高度*/
display: flex;
justify-content: center;
align-items: center;
background-image: url("images/background.jpg");
background-size: 100% 100%;
}
input{
margin-top: 20px;
width: 200px;
height: 20px;
}
.login_box{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 600px;
height: 450px;
text-align: center;
padding-top: 50px;
background-color: #00000070;/*颜色的后两位是透明度*/
border-radius: 15px;
color: white;
}
.login_btn{
margin-top: 30px;
height: 40px;
width: 80px;
border-radius: 5px;
background-color: #65b565;
font-size: 14px;
color: white;
}
.input_area{
font-size: 18px;
}
.tologin{
padding: 10px 25px;
border-radius: 5px;
background-color: #4d6ea5;
font-size: 14px;
color: white;
}
.toregister{
padding: 10px 25px;
border-radius: 5px;
background-color: #c3c361;
font-size: 14px;
color: white;
}
</style>
<body>
<div class="login_box">
<h1>网上考试系统</h1>
<form th:action="@{/user/login}" method="post" th:object="${bUser}">
<div class="input_area">
用户名:<input type="text" required th:field="*{bname}"><br>
密 码:<input type="password" required th:field="*{bpwd}"><br>
</div>
<div style="margin-top:30px; text-align: center">
<font size="4" color="red">
<span th:text="${errorMessage}"></span>
</font>
</div>
<button class="login_btn" type="submit">登录</button>
</form>
<div style="margin-top: 20px">
<a class="toregister" href="/toRegister">注册</a>
</div>
<div style="margin-top: 30px">
<a class="tologin" href="/toAdminLogin">后台</a>
</div>
</div>
</body>
</html>
serviceImpl的代码如下
@Override
public String login(BUser bUser, Model model, HttpSession session) {
List<BUser> list = userRepository.login(bUser);
if (list.size()>0){
session.setAttribute("bUser",list.get(0));
return "user/selectInfo";
}
else{
model.addAttribute("errorMessage","用户名或密码错误!");
return "user/login";
}
}
return后首页背景图片消失了