HopperRose 2023-03-30 21:45 采纳率: 50%
浏览 18
已结题

SpringBoot框架下Servuce层return页面后背景图片不显示

在SpringBoot框架下,页面通过service层return回html页面后设置的背景图片失效不显示,该如何解决?

img

图片存储路径如下

img

前端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>&nbsp;&nbsp;&nbsp;码:<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后首页背景图片消失了

img

  • 写回答

1条回答 默认 最新

  • 关注
    
     background-image: url("/images/background.jpg")
    

    你图在根路径下,前面加个/就好了,你不加斜线是相对于当前路径,你当前路径是user/login,当然找不到了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月7日
  • 已采纳回答 3月30日
  • 修改了问题 3月30日
  • 创建了问题 3月30日

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用