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 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'
  • ¥15 vue+element项目中多tag时,切换Tab时iframe套第三方html页面需要实现不刷新