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

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 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同