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

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 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败