首页 > 编程知识 正文

20p亚洲上一篇下一篇,公众号上一篇下一篇

时间:2023-05-05 17:56:44 阅读:258371 作者:4656

在使用springboot开发官网时,遇到这个问题。

解决思路:利用ajax,加载后台方法,写入到前端。

我是更具 nid 来获取上一条和下一条

sql部分:

上一篇 SELECT * FROM new_info WHERE nid<9 ORDER BY nid DESC LIMIT 1; 下一篇 SELECT * FROM new_info WHERE nid>9 ORDER BY nid ASC LIMIT 1;

serviceimp部分:

@Overridepublic NewsDO getpre(Map<String,Object> map) {NewsDO newsDO=infoDao.getpre(map);return newsDO;}@Overridepublic NewsDO getnext(Map<String,Object> map) {NewsDO newsDO=infoDao.getnext(map);return newsDO;}

controller部分:

//获取上一页 @ResponseBody @GetMapping("/getpre") NewsDO getpre(@RequestParam Map<String, Object> params){ NewsDO info=infoService.getpre(params); return info; } //获取下一页 @ResponseBody @GetMapping("/getnext") NewsDO getnext(@RequestParam Map<String, Object> params){ NewsDO info=infoService.getnext(params); return info; }

前端ajax部分:

function getpre() { var nid = /*[[${info.nid}]]*/ //这里用到thymelea获取model中的值 var type= /*[[${info.type}]]*/ var status= /*[[${info.status}]]*/ $.ajax({ url: '/news/getpre?nid='+nid+'&type='+type+'&status='+status, method: "get", dataType : 'json', success: function (data) { var htmlText = ""; if (data.nid != null){ htmlText += '上一篇: <a rel="external nofollow" rel="external nofollow" href="/news/open/'+data.nid+'">'; htmlText += data.title+'</a>'; } $("#info-pre").append(htmlText); } }); } function getnext() { var nid = /*[[${info.nid}]]*/ var type= /*[[${info.type}]]*/ var status= /*[[${info.status}]]*/ $.ajax({ url: '/news/getnext?nid='+nid+'&type='+type+'&status='+status, method : 'get', // dataType : 'json', success : function(data) { var htmlText = ""; if (data.nid != null){ htmlText += '下一篇: <a rel="external nofollow" rel="external nofollow" href="/news/open/'+data.nid+'">'; htmlText += data.title+'</a>'; } $("#info-next").append(htmlText); } }); }

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。