• 论文管理系统(用户列表显示功能)


    上次我们已经实现了论文管理系登录功能,这次我们要实现登录之后的跳转到首页,并且让首页列表显示出数据库的信息并在Mapper中写入模糊查询功能语句,这次我们不使用MybatisPlus写这个功能,这次使用Mybatis来写,区别就是Plus是继承于Mapper,Mybatis则是我们通过读取Mapper.xml文件中的sql语句,实现效果如下图所示,:

     

    一、后端部分 

    1.1 实体类

    再次强调我们每次传递数据是通过HttpResult 实体类来响应前端的数据

    1. package com.woniu.paper.entity;
    2. import lombok.AllArgsConstructor;
    3. import lombok.Data;
    4. import lombok.NoArgsConstructor;
    5. @Data
    6. @AllArgsConstructor
    7. @NoArgsConstructor
    8. public class HttpResult {
    9. private Object data;
    10. private int pageTotle;
    11. private int code;//200=成功,500=失败
    12. private String msg;//给前端的提示
    13. }

     实体类paper

    1. package com.woniu.paper.entity;
    2. import com.baomidou.mybatisplus.annotation.IdType;
    3. import com.baomidou.mybatisplus.annotation.TableId;
    4. import com.baomidou.mybatisplus.annotation.TableName;
    5. import lombok.AllArgsConstructor;
    6. import lombok.Data;
    7. import lombok.NoArgsConstructor;
    8. import java.io.Serializable;
    9. import java.time.LocalDateTime;
    10. @Data
    11. @AllArgsConstructor
    12. @NoArgsConstructor
    13. public class Paper {
    14. private Long id;
    15. private String title;
    16. private Long typeId;
    17. private String paperSummary;
    18. private String paperPath;
    19. private String createdBy;
    20. private LocalDateTime creationData;
    21. private String modifyBy;
    22. private LocalDateTime modifyData;
    23. private String fileName;
    24. private String typeName;
    25. }

     这里大家发现实体类里面多了一个属性typeName,这是方便我们后面模糊查询,因为paper数据表中的的论文类型是id,不是文本形式,没有办法进行模糊查询,所以我们需要在里面自己加入typeName这个变量

    1.2 paperMapper.xml

    1. "1.0" encoding="UTF-8"?>
    2. mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    3. <mapper namespace="com.woniu.paper.mapper.PaperMapper">
    4. <resultMap id="paperResult" type="Paper">
    5. <result column="id" property="id"/>
    6. <result column="title" property="title"/>
    7. <result column="type_id" property="typeId"/>
    8. <result column="paper_summary" property="paperSummary"/>
    9. <result column="paper_path" property="paperPath"/>
    10. <result column="created_by" property="createdBy"/>
    11. <result column="creation_data" property="creationData"/>
    12. <result column="modify_by" property="modifyBy"/>
    13. <result column="modify_data" property="modifyData"/>
    14. <result column="file_name" property="fileName"/>
    15. <result column="type_name" property="typeName"/>
    16. resultMap>
    17. <select id="selectPaperListByCondition" resultMap="paperResult">
    18. select p.*, t.type_name from t_paper as p LEFT JOIN t_type as t on
    19. p.type_id=t.id
    20. <where>
    21. <if test="title!=null and title!=''">
    22. and title like '%${title}%'
    23. if>
    24. <if test="typeName!=null and typeName!=''">
    25. and type_name=#{typeName}
    26. if>
    27. where>
    28. limit #{start},#{size}
    29. select>
    30. <select id="count" resultType="int">
    31. select count(t.type_name) from t_paper as p LEFT JOIN t_type as t on
    32. p.type_id=t.id
    33. <where>
    34. <if test="title!=null and title!=''">
    35. and title like '%${title}%'
    36. if>
    37. <if test="typeName!=null and typeName!=''">
    38. and type_name=#{typeName}
    39. if>
    40. where>
    41. select>
    42. <insert id="insertPaper">
    43. insert into t_paper (title,type_id,paper_summary,paper_path,created_by,modify_by,file_name) values (#{title},#{typeId},#{paperSummary},#{paperPath},#{createdBy},#{modifyBy},#{fileName})
    44. insert>
    45. mapper>

    数据库内外链接补充

     1.3 PaperMapper类

    1. public interface PaperMapper extends BaseMapper {
    2. List selectPaperListByCondition(String title, String typeName, int start, int size);
    3. int count(String title, String typeName);//查询总数,用于列表分页
    4. }

     1.4Service层

    接口

    1. package com.woniu.paper.service;
    2. import com.woniu.paper.entity.HttpResult;
    3. import com.woniu.paper.entity.Paper;
    4. import com.baomidou.mybatisplus.extension.service.IService;
    5. /**
    6. *

    7. * 服务类
    8. *

    9. *
    10. * @author zhang
    11. * @since 2022-11-18
    12. */
    13. public interface IPaperService {
    14. public HttpResult selectPaperListByCondition(String title, String typeName, int pageIndex, int pageSize);
    15. public HttpResult insertPaper(String title,Long typeId,String paperSummary,String paperPath,String createdBy,String modifyBy,String fileName);
    16. }

    实现类

    1. package com.woniu.paper.service.impl;
    2. import com.woniu.paper.entity.HttpResult;
    3. import com.woniu.paper.entity.Paper;
    4. import com.woniu.paper.mapper.PaperMapper;
    5. import com.woniu.paper.mapper.UserMapper;
    6. import com.woniu.paper.service.IPaperService;
    7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    8. import org.springframework.beans.factory.annotation.Autowired;
    9. import org.springframework.stereotype.Service;
    10. import java.util.List;
    11. /**
    12. *

    13. * 服务实现类
    14. *

    15. *
    16. * @author zhang
    17. * @since 2022-11-18
    18. */
    19. @Service
    20. public class PaperServiceImpl implements IPaperService {
    21. @Autowired(required = false)
    22. private PaperMapper paperMapper;//实例化DAO对象
    23. @Override
    24. public HttpResult selectPaperListByCondition(String title, String typeName, int pageIndex, int pageSize) {
    25. List papers = paperMapper.selectPaperListByCondition(title, typeName, (pageIndex - 1) * pageSize, pageSize);
    26. int count = paperMapper.count(title, typeName);
    27. HttpResult result=null;
    28. if (papers!=null&&papers.size()>0){
    29. result= new HttpResult(papers,count,200,null);
    30. }else{
    31. result= new HttpResult(null,0,500,"没有更多数据");
    32. }
    33. return result;
    34. }
    35. }

     1.5 Controller层

    1. package com.woniu.paper.controller;
    2. import com.woniu.paper.entity.HttpResult;
    3. import com.woniu.paper.service.IPaperService;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.CrossOrigin;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.stereotype.Controller;
    8. import org.springframework.web.bind.annotation.RestController;
    9. /**
    10. *

    11. * 前端控制器
    12. *

    13. *
    14. * @author zhang
    15. * @since 2022-11-18
    16. */
    17. @RestController
    18. @RequestMapping("/paper/paper")
    19. public class PaperController {
    20. @Autowired
    21. private IPaperService paperService;//实例化Service对象
    22. /**
    23. * 根据分页查询论文列表
    24. * @return
    25. */
    26. @RequestMapping("/list")
    27. @CrossOrigin(origins = "*")
    28. public HttpResult selectPaperListByCondition(String title,String typeName,int pageIndex,int pageSize) {
    29. return paperService.selectPaperListByCondition(title,typeName,pageIndex,pageSize);
    30. }
    31. /**
    32. * 新增
    33. */
    34. }

     二、前端部分

    效果图

     

    源码如下 :

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>论文管理系统title>
    6. <link href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    7. <script src="assets/jquery-3.5.1.min.js">script>
    8. <script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js">script>
    9. <script src="assets/vue.min-v2.5.16.js">script>
    10. <script src="assets/axios.min.js">script>
    11. <script src="assets/vue-router.min-2.7.0.js">script>
    12. <body>
    13. <div id="app">
    14. <div style="margin-left: auto; margin-right: auto;">
    15. <div style="width: 1000px; height: 100px; border: 1px solid black; text-align: center;font-size: 18px; line-height: 100px;">
    16. 论文管理系统
    17. div>
    18. <div style="width: 200px; height: 700px; border: 1px solid black; text-align: center; font-size: 18px; line-height: 50px; float: left">
    19. <div>
    20. <button class="btn btn-link" @click="doUserManager">用户管理button>
    21. div>
    22. <div>
    23. <button class="btn btn-link" @click="doPaperManager">论文管理button>
    24. div>
    25. div>
    26. <div style="width: 800px; height: 700px; border: 1px solid black; float: left">
    27. <div v-if="isShow">
    28. 论文主题:
    29. <input type="text" v-model="title">
    30. 论文类型:
    31. <select v-model="typeName">
    32. <option>软件option>
    33. <option>财务option>
    34. select>
    35. <button @click="doQuery">查询button>
    36. <table class="table table-striped">
    37. <caption>论文列表caption>
    38. <thead>
    39. <tr>
    40. <th>论文主题th>
    41. <th>作者th>
    42. <th>论文类型th>
    43. <th>发表时间th>
    44. <th>修改时间th>
    45. <th>操作th>
    46. tr>
    47. thead>
    48. <tbody>
    49. <tr v-for="p in papers">
    50. <td>{{p.title}}td>
    51. <td>{{p.createdBy}}td>
    52. <td>{{p.typeName}}td>
    53. <td>{{p.creationData}}td>
    54. <td>{{p.modifyData}}td>
    55. <td>
    56. <button class="btn btn-link">修改button>
    57. <button class="btn btn-link">删除button>
    58. td>
    59. tr>
    60. tbody>
    61. table>
    62. <ul class="pagination" v-for="p in pageNum">
    63. <li v-if="p == pageIndex" class="active">
    64. <a @click="doGo(p)">{{p}}a>
    65. li>
    66. <li v-else="p == pageIndex">
    67. <a @click="doGo(p)">{{p}}a>
    68. li>
    69. ul>
    70. div>
    71. div>
    72. div>
    73. div>
    74. <script>
    75. new Vue({
    76. //将id=app的div的管理权交给vue
    77. el:'#app',
    78. //需要绑定的数据
    79. data:{
    80. papers:null,//论文列表
    81. isShow:false,//控制列表是否显示
    82. //用于条件查询
    83. title:null,
    84. typeName:null,
    85. //用户分页
    86. pageIndex:1,//当前页面
    87. pageSize:10,//每页显示的条数
    88. pageTotle:0,//数据总条数
    89. pageNum:0
    90. },
    91. //需要绑定的函数
    92. methods:{
    93. //请求论文列表
    94. requestPapers(url){
    95. axios.get(url).then(respones =>{
    96. console.log(respones.data);
    97. this.papers =respones.data.data;//给论文列表赋值
    98. this.pageTotle = respones.data.pageTotle;//给总条数赋值
    99. //Math.ceril函数=>小数去整,向上取整
    100. this.pageNum = Math.ceil(this.pageTotle / this.pageSize);//计算页数
    101. });
    102. },
    103. doGo(p){
    104. this.pageIndex = p;
    105. var url="http://localhost:8080/paper/paper/list?pageIndex="+p+"&pageSize="+this.pageSize+"&uid="+localStorage.getItem("uid");
    106. this.requestPapers(url);//调用请求论文列表的函数发送请求
    107. },
    108. //用户管理
    109. doUserManager(){
    110. this.isShow = true;//让列表显示
    111. },
    112. //论文管理
    113. doPaperManager(){
    114. this.isShow = true;//让列表显示
    115. },
    116. //点击查询按钮执行
    117. doQuery(){
    118. var url="http://localhost:8080/paper/paper/list?pageIndex="+this.pageIndex+"&pageSize="+this.pageSize+"&uid="+localStorage.getItem("uid")+"&title="+this.title+"&typeName="+this.typeName;
    119. this.requestPapers(url);//调用请求论文列表的函数发送请求
    120. }
    121. },
    122. //页面加载完成后执行
    123. created:function () {
    124. //re
    125. var url="http://localhost:8080/paper/paper/list?pageIndex="+this.pageIndex+"&pageSize="+this.pageSize+"&uid="+localStorage.getItem("uid");
    126. this.requestPapers(url);//调用请求论文列表的函数发送请求
    127. }
    128. });
    129. script>
    130. body>
    131. html>

     代码讲解

    整体思路,我们要先保证能显示列表信息,之后进行跳转和模糊查询等等其他功能

    1. <link href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    2. <script src="assets/jquery-3.5.1.min.js">script>
    3. <script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js">script>
    4. <script src="assets/vue.min-v2.5.16.js">script>
    5. <script src="assets/vue-router.min-2.7.0.js">script>
    6. <script src="assets/axios.min.js">script>

    这两个按钮是页面左边的菜单栏的选项

     

     分页功能

     

     JS部分都有具体注释,分页功能可参考往期博客

    主页面图 

     模糊查询效果图

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    Stable Diffusion插件(翻译)
    SpringBoot的初步认识
    VMware17.0.1密匙/下载/安装Ubuntu18.04
    Lambda表达式
    【base-0】如果各个前端框架的父子通信都统一会怎样?
    【uniapp】小程序中input输入框的placeholder-class不生效以及解决办法
    Qt扫描-QMoive 理论总结
    神经网络科普视频下载,神经网络视频教程
    Miko二次元动漫视频网站源码 视频播放带仿哔哩哔哩视频字幕弹幕
    记录:2022-9-28 岛屿的最大面积 字母异位词分组 雪花算法实现 偏向锁 |锁升级 阻塞线程的方式
  • 原文地址:https://blog.csdn.net/magic_818/article/details/127945732