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 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂