St0n233 2021-04-05 15:45 采纳率: 50%
浏览 749
已采纳

springboot 前端页面js怎么接收后端controller的model

想要实现一个网页弹窗功能,点击按钮后右下角会出现通知弹窗,可以查看通知。

前端页面代码

<!-- 通知 -->
<i class="fa fa-bell-o fa-1x" aria-hidden="true" style="color:white"></i>
    <div>
       <button id="show-notification-default-alert" class="btn btn-danger" th:if="true">新通知</button>
       <button class="btn btn-secondary" th:if="false">暂无通知</button>
    </div>
<!-- 通知 -->
<script type="text/javascript" th:src="@{/alert-resource/js/growl-notification.min.js}"></script>
<script>
    GrowlNotification.setGlobalOptions({
        buttons: {
            action: {
                text: 'Apply'
            },
            cancel: {
                text: 'Dismiss'
            }
        }
    });

    function getOptions() {
        var position = "bottom-right";
        var closeTimeout = 0;
        var animation = "slide";
        var showButtons = false;
        var showProgressBar = false;
        var animationOptions = {
            open: animation + '-in',
            close: animation + '-out'
        };

        if (animation === 'none') {
            animationOptions = {
                open: false,
                close: false
            };
        }

        return options = {
            description: 'I am a default notification',
            position: position,
            closeTimeout: closeTimeout,
            closeWith: ['click'],
            animation: animationOptions,
            showButtons: showButtons,
            buttons: {
                action: {
                    callback: function (notification) {
                        console.log('action button');
                    }
                }
            },
            showProgress: showProgressBar
        };
    }


    $('#show-notification-default-alert').on('click', function () {
        var options = getOptions();
        var noticeTitle = [[${notices.title}]];
        var noticeContent = [[${notices.content}]];
        options.title = noticeTitle;
        options.description = noticeContent;
        options.width = 500;
        GrowlNotification.notify(options);
    });


</script>

后端代码

	@RequestMapping(value = "get")
	public String getNotice(Notice notice,Model model){
		List<Notice> noticeList = noticeService.findList(new Notice());
		model.addAttribute("notices",noticeList);
		return "front/index";
	}

前端页面js想要实现foreach notices对象,把它分为一个个notice,再通过弹窗显示notice.title,notice.content。

  • 写回答

5条回答 默认 最新

  • 一剑荒芜 2021-04-06 09:03
    关注

    <script th:inline="javascript">
        var pages = [[${user}]];  // request(后台是user)
        var pages = [[${session.user}]];  // session(后台是user)
    </script>
    前端模板是thymeleaf

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)