当前位置:   article > 正文

python222网站实战(SpringBoot+SpringSecurity+MybatisPlus+thymeleaf+layui)-友情链接管理实现

python222网站实战(SpringBoot+SpringSecurity+MybatisPlus+thymeleaf+layui)-友情链接管理实现

锋哥原创的Springboot+Layui python222网站实战:

python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )_哔哩哔哩_bilibilipython222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )共计23条视频,包括:python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )、第2讲 架构搭建实现、第3讲 页面系统属性动态化设计实现等,UP主更多精彩视频,请关注UP账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV1yX4y1a7qM/

后端:

  1. package com.python222.controller.admin;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.python222.entity.Link;
  4. import com.python222.entity.PageBean;
  5. import com.python222.service.LinkService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12. /**
  13. * 管理员-友情链接控制器
  14. * @author Administrator
  15. *
  16. */
  17. @RestController
  18. @RequestMapping(value = "/admin/link")
  19. public class LinkAdminController {
  20. @Autowired
  21. private LinkService linkService;
  22. /**
  23. * 根据条件分页查询友情链接
  24. * @param page
  25. * @param limit
  26. * @return
  27. * @throws Exception
  28. */
  29. @RequestMapping(value = "/list")
  30. public Map<String,Object> list(@RequestParam(value="page",required=false)Integer page,@RequestParam(value="limit",required=false)Integer limit)throws Exception{
  31. Map<String, Object> resultMap = new HashMap<>();
  32. PageBean pageBean=new PageBean(page,limit);
  33. Page<Link> linkPage = linkService.page(new Page<>(pageBean.getPage(), pageBean.getPageSize()));
  34. resultMap.put("code", 0);
  35. resultMap.put("count", linkPage.getTotal());
  36. resultMap.put("data", linkPage.getRecords());
  37. return resultMap;
  38. }
  39. /**
  40. * 添加或者修改友情链接
  41. * @param link
  42. * @return
  43. */
  44. @RequestMapping("/save")
  45. public Map<String,Object> save(Link link){
  46. if(link.getId()==null){
  47. linkService.save(link);
  48. }else{
  49. linkService.updateById(link);
  50. }
  51. Map<String, Object> resultMap = new HashMap<>();
  52. resultMap.put("success", true);
  53. return resultMap;
  54. }
  55. /**
  56. * 删除友情链接
  57. * @param id
  58. * @return
  59. * @throws Exception
  60. */
  61. @RequestMapping("/delete")
  62. public Map<String,Object> delete(Integer id)throws Exception{
  63. Map<String, Object> resultMap = new HashMap<>();
  64. linkService.removeById(id);
  65. resultMap.put("success", true);
  66. return resultMap;
  67. }
  68. /**
  69. * 根据id查询友情链接实体
  70. * @param id
  71. * @return
  72. * @throws Exception
  73. */
  74. @RequestMapping("/findById")
  75. public Map<String,Object> findById(Integer id)throws Exception{
  76. Map<String, Object> resultMap = new HashMap<>();
  77. Link link=linkService.getById(id);
  78. resultMap.put("link", link);
  79. resultMap.put("success", true);
  80. return resultMap;
  81. }
  82. }

前端linkManage.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>友情链接管理</title>
  6. <link rel="stylesheet" href="/static/layui/css/layui.css"></link>
  7. <link rel="stylesheet" href="/static/css/css.css"></link>
  8. </head>
  9. <body>
  10. <div style="padding: 20px">
  11. <span class="layui-breadcrumb">
  12. <a>首页</a>
  13. <a><cite>友情链接管理</cite></a>
  14. </span>
  15. <div style="padding-top: 20px;">
  16. <div>
  17. <div>
  18. <button class="layui-btn layuiadmin-btn-list" data-type="batchdel" onclick="addLink()">添加</button>
  19. </div>
  20. </div>
  21. <div>
  22. <table width="100%" id="linkListTable" ></table>
  23. </div>
  24. </div>
  25. </div>
  26. <script src="/static/layui/layui.js"></script>
  27. <script src="/static/js/jquery.js"></script>
  28. <script src="/static/js/common.js"></script>
  29. <script type="text/javascript">
  30. layui.use(['element','form','table'], function(){
  31. var form=layui.form;
  32. var element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
  33. $ = layui.jquery; // 使用jquery
  34. table = layui.table;
  35. table.render({
  36. elem: '#linkListTable'
  37. ,url:'/admin/link/list'
  38. ,cols: [[
  39. {type:'checkbox'}
  40. ,{field:'id', width:100,title: '编号'}
  41. ,{field:'name', width:200,title: '友情链接名称'}
  42. ,{field:'url', width:250,title: '友情链接地址'}
  43. ,{field:'sort', width:100, title: '排列序号',align:'center'}
  44. ,{field:'remark', title: '描述',align:'center'}
  45. ,{field:'action', width:150, title: '操作',align:'center',templet:formatAction}
  46. ]]
  47. ,page: true
  48. });
  49. });
  50. function deleteOne(id){
  51. layer.confirm('您确定要删除这条记录吗?', {
  52. title:"系统提示"
  53. ,btn: ['确定','取消'] //按钮
  54. }, function(){
  55. layer.closeAll('dialog');
  56. $.post("/admin/link/delete",{"id":id},function(result){
  57. if(result.success){
  58. layer.msg("删除成功!");
  59. table.reload("linkListTable",{});
  60. }else{
  61. layer.msg("删除失败,请联系管理员!");
  62. }
  63. },"json");
  64. }, function(){
  65. });
  66. }
  67. function addLink(){
  68. layer.open({
  69. type: 2,
  70. title: '添加友情链接',
  71. area: ['500px', '500px'],
  72. content: '/admin/saveLink.html' //iframe的url
  73. });
  74. }
  75. function modifyLink(id){
  76. layer.open({
  77. type: 2,
  78. title: '修改友情链接',
  79. area: ['500px', '500px'],
  80. content: '/admin/saveLink.html?id='+id //iframe的url
  81. });
  82. }
  83. function formatAction(d){
  84. return "<button class='layui-btn layui-btn-normal layui-btn-xs' onclick='modifyLink("+d.id+")'><i class='layui-icon layui-icon-edit'></i>编辑</button><button class='layui-btn layui-btn-warm layui-btn-xs' onclick='deleteOne("+d.id+")'><i class='layui-icon layui-icon-delete' ></i>删除</button>";
  85. }
  86. </script>
  87. </body>
  88. </html>

saveLink.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>添加或者修改友情链接</title>
  6. <link rel="stylesheet" href="/static/layui/css/layui.css"></link>
  7. <style type="text/css">
  8. table tr td{
  9. padding: 10px;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <div style="padding: 20px">
  15. <form method="post">
  16. <table>
  17. <tr>
  18. <td>友情链接名称:</td>
  19. <td><input type="text" id="name" name="name" class="layui-input" style="width: 300px"/></td>
  20. </tr>
  21. <tr>
  22. <td>友情链接地址:</td>
  23. <td><input type="text" id="url" name="url" class="layui-input" style="width: 300px"/></td>
  24. </tr>
  25. <tr>
  26. <td>友情链接描述:</td>
  27. <td>
  28. <textarea type="text" id="remark" name="remark" class="layui-input" style="width: 300px;height: 100px" ></textarea>
  29. </td>
  30. </tr>
  31. <tr>
  32. <td>排列序号:</td>
  33. <td><input type="text" id="sort" name="sort" class="layui-input" style="width: 100px;display: inline;"/>&nbsp;&nbsp;<span>(根据数值从小到大排序)</span></td>
  34. </tr>
  35. <tr>
  36. <td><button class="layui-btn" onclick="submitData();return false;">提交</button></td>
  37. <td><font id="errorInfo" color="red"></font></td>
  38. </tr>
  39. </table>
  40. </form>
  41. </div>
  42. <script src="/static/layui/layui.js"></script>
  43. <script src="/static/js/jquery.js"></script>
  44. <script src="/static/js/common.js"></script>
  45. <script type="text/javascript">
  46. layui.use(['form'], function(){
  47. });
  48. function submitData(){
  49. var name=$("#name").val().trim();
  50. var url=$("#url").val().trim();
  51. var remark=$("#remark").val().trim();
  52. var sort=$("#sort").val().trim();
  53. if(name=="") {
  54.         $("#errorInfo").text("请输入友情链接名称!");
  55. $("#name").focus();
  56.        return false;
  57.    }
  58. if(url=="") {
  59.         $("#errorInfo").text("请输入友情链接地址!");
  60. $("#url").focus();
  61.        return false;
  62.    }
  63. if(!IsURL(url)){
  64. $("#errorInfo").text("友情链接地址格式不正确!");
  65. $("#url").focus();
  66.        return false;
  67. }
  68. if(sort=="") {
  69.         $("#errorInfo").text("请输入排列序号!");
  70. $("#sort").focus();
  71.        return false;
  72.    }
  73.    if (!(/(^[1-9]\d*$)/.test(sort))) {
  74.       $("#errorInfo").text("排列序号必须是正整数!");
  75. $("#sort").focus();
  76.       return false;
  77.    }
  78. var id=getQueryVariable("id");
  79. if(id){
  80. $.post("/admin/link/save",{id:id,name:name,url:url,sort:sort,remark:remark},function(result){
  81. if(result.success){
  82. layer.alert('修改成功!',function () {
  83. parent.reloadPage();
  84. });
  85. }else{
  86. $("#errorInfo").text(result.errorInfo);
  87. }
  88. },"json");
  89. }else{
  90. $.post("/admin/link/save",{name:name,url:url,sort:sort,remark:remark},function(result){
  91. if(result.success){
  92. layer.alert('添加成功!',function () {
  93. parent.reloadPage();
  94. });
  95. }else{
  96. $("#errorInfo").text(result.errorInfo);
  97. }
  98. },"json");
  99. }
  100. }
  101. function getQueryVariable(variable){
  102. var query = window.location.search.substring(1);
  103. var vars = query.split("&");
  104. for (var i=0;i<vars.length;i++) {
  105. var pair = vars[i].split("=");
  106. if(pair[0] == variable){return pair[1];}
  107. }
  108. return(false);
  109. }
  110. $(function(){
  111.   
  112. var id=getQueryVariable("id");
  113. if(id){
  114. $.post("/admin/link/findById",{id:id},function(result){
  115. if(result.success){
  116. var link=result.link;
  117. $("#name").val(link.name);
  118. $("#url").val(link.url);
  119. $("#sort").val(link.sort);
  120. $("#remark").val(link.remark);
  121. }else{
  122. layer.alert('服务器加载有问题,请联系管理员!');
  123. }
  124. },"json");
  125. }
  126. });
  127. </script>
  128. </body>
  129. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/45608
推荐阅读
相关标签
  

闽ICP备14008679号