分页修改和评论获取
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package com.yaoyuan.jiscuss.common;
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.common
|
||||
* @Description:
|
||||
* @date 2020/8/17 14:51
|
||||
*/
|
||||
@Data
|
||||
public class Node {
|
||||
|
||||
public Node() {
|
||||
|
||||
}
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer discussionId;
|
||||
|
||||
private Integer number;
|
||||
|
||||
private Date time;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private String type;
|
||||
|
||||
private String content;
|
||||
|
||||
private Integer parentId;
|
||||
|
||||
private Date editTime;
|
||||
|
||||
private Integer editUserId;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
private String copyright;
|
||||
|
||||
private Integer isApproved;
|
||||
|
||||
private Integer createId;
|
||||
|
||||
private Date createTime;
|
||||
//下一条回复
|
||||
private List<Node> nextNodes = new ArrayList<Node>();
|
||||
|
||||
|
||||
/**
|
||||
* 将单个node添加到链表中
|
||||
*
|
||||
* @param list
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public static boolean addNode(List<Node> list, Node node) {
|
||||
for (Node node1 : list) { //循环添加
|
||||
if (node1.getId() .equals(node.getParentId()) ) { //判断留言的上一段是都是这条留言
|
||||
node1.getNextNodes().add(node); //是,添加,返回true;
|
||||
System.out.println("添加了一个");
|
||||
return true;
|
||||
} else { //否则递归继续判断
|
||||
if (node1.getNextNodes().size() != 0) {
|
||||
if (Node.addNode(node1.getNextNodes(), node)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将查出来的lastId不为null的回复都添加到第一层Node集合中
|
||||
*
|
||||
* @param firstList
|
||||
* @param thenList
|
||||
* @return
|
||||
*/
|
||||
public static List addAllNode(List<Node> firstList, List<Posts> thenList) {
|
||||
while (thenList.size() != 0) {
|
||||
int size = thenList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Node node = new Node();
|
||||
BeanUtils.copyProperties(thenList.get(i), node);
|
||||
if (Node.addNode(firstList, node)) {
|
||||
thenList.remove(i);
|
||||
i--;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return firstList;
|
||||
}
|
||||
|
||||
//打印
|
||||
public static void show(List<Node> list) {
|
||||
for (Node node : list) {
|
||||
System.out.println(node.getUserId() + " 用户回复了你:" + node.getContent());
|
||||
if (node.getNextNodes().size() != 0) {
|
||||
Node.show(node.getNextNodes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,17 +1,20 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.yaoyuan.jiscuss.common.Node;
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import com.yaoyuan.jiscuss.service.IPostsService;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
@@ -58,6 +61,27 @@ public class UserPostController extends BaseController {
|
||||
Discussions discussions = discussionsService.findOne(id);
|
||||
|
||||
List<Posts> posts = postsService.findOneBy(id);
|
||||
|
||||
//查询id为1且parentId为null的评论
|
||||
List<Posts> firstList = postsService.findAllByDIdAndparentIdNull(1);
|
||||
//查询id为1且parentId不为null的评论
|
||||
List<Posts> thenList = postsService.findAllByDIdAndparentIdNotNull(1);
|
||||
//新建一个Node集合。
|
||||
ArrayList<Node> nodes = new ArrayList<>();
|
||||
//将第一层评论都添加都Node集合中
|
||||
for (Posts post : firstList) {
|
||||
Node node = new Node();
|
||||
BeanUtils.copyProperties(post, node);
|
||||
nodes.add(node);
|
||||
}
|
||||
//将回复添加到对应的位置
|
||||
List list = Node.addAllNode(nodes, thenList);
|
||||
System.out.println();
|
||||
//打印回复链表
|
||||
Node.show(list);
|
||||
|
||||
|
||||
|
||||
map.put("discussions", discussions);
|
||||
map.put("posts", posts);
|
||||
UserInfo user = getUserInfo(request);
|
||||
@@ -78,10 +102,10 @@ public class UserPostController extends BaseController {
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
discussions.setLast_user_id( user.getId());
|
||||
discussions.setCreate_id( user.getId());
|
||||
discussions.setLastUserId( user.getId());
|
||||
discussions.setCreateId( user.getId());
|
||||
}
|
||||
discussions.setCreate_time(new Date());
|
||||
discussions.setCreateTime(new Date());
|
||||
|
||||
Discussions saveDiscussions = discussionsService.insert(discussions);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
@@ -109,9 +133,9 @@ public class UserPostController extends BaseController {
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
posts.setCreate_id( user.getId());
|
||||
posts.setCreateId( user.getId());
|
||||
}
|
||||
posts.setCreate_time(new Date());
|
||||
posts.setCreateTime(new Date());
|
||||
|
||||
Posts savePost = postsService.insert(posts);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
@@ -135,9 +159,9 @@ public class UserPostController extends BaseController {
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
tags.setCreate_id( user.getId());
|
||||
tags.setCreateId( user.getId());
|
||||
}
|
||||
tags.setCreate_time(new Date());
|
||||
tags.setCreateTime(new Date());
|
||||
|
||||
Tags saveTags = tagsService.insert(tags);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
|
||||
@@ -53,13 +53,15 @@ public class UserSystemController extends BaseController {
|
||||
|
||||
int pageSiz = 5;
|
||||
int pageNumNew = pageNum - 1;
|
||||
|
||||
Discussions discussions = new Discussions();
|
||||
//分页获取主题帖子
|
||||
Page<Discussions> allDiscussionsPage = discussionsService.queryAllDiscussionsList(pageNumNew,pageSiz);
|
||||
Page<Discussions> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussions,pageNumNew,pageSiz);
|
||||
|
||||
List<Discussions> allDiscussions =allDiscussionsPage.getContent();
|
||||
|
||||
logger.info("全部主题==>:{}",allDiscussions);
|
||||
|
||||
Long total = allDiscussionsPage.getTotalElements();
|
||||
|
||||
//获取主题帖子的分页数据
|
||||
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
@@ -73,10 +75,13 @@ public class UserSystemController extends BaseController {
|
||||
map.put("allDiscussions", allDiscussions);
|
||||
map.put("pageDiscussions", pageNumList);
|
||||
map.put("allTags", allTags);
|
||||
|
||||
map.put("tag", tag);
|
||||
map.put("type", type);
|
||||
|
||||
map.put("pageSize",pageSiz);
|
||||
map.put("pageTotal", total);
|
||||
map.put("pageNum", pageNum);
|
||||
map.put("pageNumAll", pageNumList.size());
|
||||
map.put("pageTotalPages", allDiscussionsPage.getTotalPages());
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
map.put("username", user.getUsername());
|
||||
@@ -85,38 +90,6 @@ public class UserSystemController extends BaseController {
|
||||
return "index";
|
||||
}
|
||||
|
||||
|
||||
// //首页main
|
||||
// @RequestMapping("/main")
|
||||
// public String homePage(HttpServletRequest request, ModelMap map) {
|
||||
// logger.info(">>> index");
|
||||
//
|
||||
// //分页获取主题帖子
|
||||
// Page<Discussions> allDiscussionsPage = discussionsService.queryAllDiscussionsList(0,20);
|
||||
//
|
||||
// List<Discussions> allDiscussions =allDiscussionsPage.getContent();
|
||||
//
|
||||
// logger.info("全部主题==>:{}",allDiscussions);
|
||||
//
|
||||
// //获取主题帖子的分页数据
|
||||
// List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
//
|
||||
// //获取所有标签(以后尝试去缓存中取)
|
||||
// List<Tags> allTags = tagsService.getAllList();
|
||||
// logger.info("全部标签==>:{}",allTags);
|
||||
//
|
||||
// map.put("data", "Jiscuss 用户");
|
||||
// map.put("allDiscussions", allDiscussions);
|
||||
// map.put("pageDiscussions", pageNumList);
|
||||
// map.put("allTags", allTags);
|
||||
// UserInfo user = getUserInfo(request);
|
||||
// if(user != null){
|
||||
// map.put("username", user.getUsername());
|
||||
// map.put("data", "Jiscuss 用户:" + user.getUsername());
|
||||
// }
|
||||
// return "index";
|
||||
// }
|
||||
|
||||
|
||||
private List<String> getPageNumList(int size) {
|
||||
List<String> pageNumList = new ArrayList<String>();
|
||||
@@ -127,28 +100,6 @@ public class UserSystemController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
//登录
|
||||
// @PostMapping(value = "/login")
|
||||
// @ResponseBody
|
||||
// public String login(@RequestParam("username") String username, @RequestParam("password") String password,
|
||||
// HttpSession session) {
|
||||
// JSONObject resultobj = new JSONObject();
|
||||
// Users user = usersService.checkByUsernameAndPassword(username, password);
|
||||
// if (user!=null) {
|
||||
// //用户名和密码完成校验
|
||||
// session.setAttribute("username", username); //缓存session
|
||||
// session.setAttribute("userid", user.getId()); //缓存session
|
||||
// resultobj.put("username", username);
|
||||
// resultobj.put("msg", "登录成功");
|
||||
// resultobj.put("flag", true);
|
||||
// } else {
|
||||
// //用户名和密码未完成校验
|
||||
// resultobj.put("msg", "用户名或密码错误");
|
||||
// resultobj.put("flag", false);
|
||||
// }
|
||||
// return resultobj.toString();
|
||||
// }
|
||||
|
||||
//登录页
|
||||
@GetMapping("/login")
|
||||
public String login(@RequestParam(value = "error", required = false) String error,
|
||||
@@ -165,17 +116,6 @@ public class UserSystemController extends BaseController {
|
||||
return "login";
|
||||
}
|
||||
|
||||
//退出
|
||||
// @PostMapping(value = "/loginout")
|
||||
// @ResponseBody
|
||||
// public String logout(HttpServletRequest request, HttpServletResponse response){
|
||||
// JSONObject resultobj = new JSONObject();
|
||||
// HttpSession session=request.getSession();
|
||||
// session.invalidate();
|
||||
// resultobj.put("msg", "用户退出成功");
|
||||
// resultobj.put("flag", true);
|
||||
// return resultobj.toString(); //
|
||||
// }
|
||||
|
||||
//注册
|
||||
|
||||
|
||||
@@ -29,49 +29,49 @@ public class Discussions implements Serializable {
|
||||
private String content;
|
||||
|
||||
@Column(name="comments_count")
|
||||
private Integer comments_count;
|
||||
private Integer commentsCount;
|
||||
|
||||
@Column(name="participants_count")
|
||||
private Integer participants_count;
|
||||
private Integer participantsCount;
|
||||
|
||||
@Column(name="number_index")
|
||||
private Integer number_index;
|
||||
private Integer numberIndex;
|
||||
|
||||
@Column(name="start_time")
|
||||
private Date start_time;
|
||||
private Date startTime;
|
||||
|
||||
@Column(name="start_user_id")
|
||||
private Integer start_user_id;
|
||||
private Integer startUserId;
|
||||
|
||||
@Column(name="start_post_id")
|
||||
private Integer start_post_id;
|
||||
private Integer startPostId;
|
||||
|
||||
@Column(name="last_time")
|
||||
private Date last_time;
|
||||
private Date lastTime;
|
||||
|
||||
@Column(name="last_user_id")
|
||||
private Integer last_user_id;
|
||||
private Integer lastUserId;
|
||||
|
||||
@Column(name="last_post_id")
|
||||
private Integer last_post_id;
|
||||
private Integer lastPostId;
|
||||
|
||||
@Column(name="last_post_number")
|
||||
private Integer last_post_number;
|
||||
private Integer lastPostNumber;
|
||||
|
||||
@Column(name="is_approved")
|
||||
private Integer is_approved;
|
||||
private Integer isApproved;
|
||||
|
||||
@Column(name="like_count")
|
||||
private Integer like_count;
|
||||
private Integer likeCount;
|
||||
|
||||
|
||||
@Column(name="ip_address")
|
||||
private String ip_address;
|
||||
private String ipAddress;
|
||||
|
||||
@Column(name="create_id")
|
||||
private Integer create_id;
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
private Date create_time;
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ public class DiscussionsTags implements Serializable{
|
||||
|
||||
@Id
|
||||
@Column(name="discussion_id")
|
||||
private Integer discussion_id;
|
||||
private Integer discussionId;
|
||||
|
||||
@Column(name="tag_id")
|
||||
private Integer tag_id;
|
||||
private Integer tagId;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Posts implements Serializable{
|
||||
private Integer id;
|
||||
|
||||
@Column(name="discussion_id")
|
||||
private Integer discussion_id;
|
||||
private Integer discussionId;
|
||||
|
||||
@Column(name="number")
|
||||
private Integer number;
|
||||
@@ -32,7 +32,7 @@ public class Posts implements Serializable{
|
||||
private Date time;
|
||||
|
||||
@Column(name="user_id")
|
||||
private Integer user_id;
|
||||
private Integer userId;
|
||||
|
||||
@Column(name="type")
|
||||
private String type;
|
||||
@@ -41,27 +41,27 @@ public class Posts implements Serializable{
|
||||
private String content;
|
||||
|
||||
@Column(name="parent_id")
|
||||
private Integer parent_id;
|
||||
private Integer parentId;
|
||||
|
||||
@Column(name="edit_time")
|
||||
private Date edit_time;
|
||||
private Date editTime;
|
||||
|
||||
@Column(name="edit_user_id")
|
||||
private Integer edit_user_id;
|
||||
private Integer editUserId;
|
||||
|
||||
@Column(name="ip_address")
|
||||
private String ip_address;
|
||||
private String ipAddress;
|
||||
|
||||
@Column(name="copyright")
|
||||
private String copyright;
|
||||
|
||||
@Column(name="is_approved")
|
||||
private Integer is_approved;
|
||||
private Integer isApproved;
|
||||
|
||||
@Column(name="create_id")
|
||||
private Integer create_id;
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
private Date create_time;
|
||||
private Date createTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,20 +35,20 @@ public class Tags implements Serializable{
|
||||
private Integer position;
|
||||
|
||||
@Column(name="parent_id")
|
||||
private Integer parent_id;
|
||||
private Integer parentId;
|
||||
|
||||
@Column(name="discussions_count")
|
||||
private String discussions_count;
|
||||
private String discussionsCount;
|
||||
|
||||
@Column(name="last_time")
|
||||
private Date last_time;
|
||||
private Date lastTime;
|
||||
|
||||
@Column(name="last_discussion_id")
|
||||
private Integer last_discussion_id;
|
||||
private Integer lastDiscussionId;
|
||||
|
||||
@Column(name="create_id")
|
||||
private Integer create_id;
|
||||
private Integer createId;
|
||||
|
||||
@Column(name="create_time")
|
||||
private Date create_time;
|
||||
private Date createTime;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Users implements Serializable {
|
||||
private String password;
|
||||
|
||||
@Column(name="join_time")
|
||||
private Date join_time;
|
||||
private Date joinTime;
|
||||
|
||||
@Column(name="age")
|
||||
private Integer age;
|
||||
@@ -56,13 +56,13 @@ public class Users implements Serializable {
|
||||
private String phone;
|
||||
|
||||
@Column(name="discussions_count")
|
||||
private Integer discussions_count;
|
||||
private Integer discussionsCount;
|
||||
|
||||
@Column(name="comments_count")
|
||||
private Integer comments_count;
|
||||
private Integer commentsCount;
|
||||
|
||||
@Column(name="last_seen_time")
|
||||
private Date last_seen_time;
|
||||
private Date lastSeenTime;
|
||||
|
||||
@Column(name="flag")
|
||||
private Integer flag;
|
||||
|
||||
@@ -17,7 +17,12 @@ public interface PostsRepository extends JpaRepository<Posts,Integer> {
|
||||
* @param dId
|
||||
* @return
|
||||
*/
|
||||
@Query("from Posts where discussion_id = :dId")
|
||||
@Query("from Posts where discussionId = :dId")
|
||||
List<Posts> findOneBy(@Param("dId")Integer dId);
|
||||
|
||||
@Query("from Posts where parentId is null and discussionId = :dId")
|
||||
List<Posts> findAllByDIdAndparentIdNull(@Param("dId")Integer dId);
|
||||
|
||||
@Query("from Posts where parentId is not null and discussionId = :dId")
|
||||
List<Posts> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId);
|
||||
}
|
||||
|
||||
@@ -27,12 +27,6 @@ public interface UsersRepository extends JpaRepository<Users,Integer> {
|
||||
*/
|
||||
Users getById(Integer id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void deleteById(Integer id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
|
||||
@@ -14,6 +14,6 @@ public interface IDiscussionsService {
|
||||
|
||||
Discussions findOne(Integer id);
|
||||
|
||||
Page<Discussions> queryAllDiscussionsList(int pageNum,int pageSize);
|
||||
Page<Discussions> queryAllDiscussionsList(Discussions discussions,int pageNum,int pageSize);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,4 +10,8 @@ public interface IPostsService {
|
||||
Posts insert(Posts posts);
|
||||
|
||||
List<Posts> findOneBy(Integer id);
|
||||
|
||||
List<Posts> findAllByDIdAndparentIdNull(Integer dId);
|
||||
|
||||
List<Posts> findAllByDIdAndparentIdNotNull(Integer dId);
|
||||
}
|
||||
|
||||
@@ -5,10 +5,7 @@ import java.util.List;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussions;
|
||||
@@ -40,10 +37,13 @@ public class DiscussionsServiceImpl implements IDiscussionsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Discussions> queryAllDiscussionsList(int pageNum, int pageSize) {
|
||||
public Page<Discussions> queryAllDiscussionsList(Discussions discussions,int pageNum, int pageSize) {
|
||||
Sort sort=new Sort(Sort.Direction.DESC,"id");
|
||||
@SuppressWarnings("deprecation")
|
||||
Pageable pageable=new PageRequest(pageNum,pageSize,sort);
|
||||
return discussionsRepository.findAll(pageable);
|
||||
//将匹配对象封装成Example对象
|
||||
Example<Discussions> example = Example.of(discussions);
|
||||
|
||||
return discussionsRepository.findAll(example,pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,20 @@ public class PostsServiceImpl implements IPostsService {
|
||||
@Override
|
||||
public List<Posts> findOneBy(Integer id) {
|
||||
|
||||
List<Posts> ss = postsRepository.findOneBy(id);
|
||||
return ss;
|
||||
List<Posts> posts = postsRepository.findOneBy(id);
|
||||
return posts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Posts> findAllByDIdAndparentIdNull(Integer dId) {
|
||||
List<Posts> posts = postsRepository.findAllByDIdAndparentIdNull(dId);
|
||||
return posts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Posts> findAllByDIdAndparentIdNotNull(Integer dId) {
|
||||
List<Posts> posts = postsRepository.findAllByDIdAndparentIdNotNull(dId);
|
||||
return posts;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,3 +47,21 @@ values (11, '测试主题11', '测试内容3测试测试测试测试测试测试
|
||||
insert into tags
|
||||
values (1, '测试标签1',null,null,null,null,null,null,null,null,null);
|
||||
|
||||
|
||||
insert into posts
|
||||
values (1, 1, 1,null,1,null,'评论内容222',null,null,1,null,null,null,null);
|
||||
|
||||
insert into posts
|
||||
values (2, 1, 2,null,1,null,'评论内容333',null,null,1,null,null,null,null);
|
||||
|
||||
insert into posts
|
||||
values (3, 1, 3,null,1,1,'评论内容444',null,null,1,null,null,null,null);
|
||||
|
||||
insert into posts
|
||||
values (4, 1, 4,null,1,1,'评论内容555',null,null,1,null,null,null,null);
|
||||
|
||||
insert into posts
|
||||
values (5, 1, 5,null,1,2,'评论内容666',null,null,1,null,null,null,null);
|
||||
|
||||
insert into posts
|
||||
values (6, 1, 6,null,1,5,'评论内容777',null,null,1,null,null,null,null);
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
<form class="ui large form" action="/logout" id="logoutForm" method="post" style="display: none;">
|
||||
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
||||
</form>
|
||||
${username} <a href="javascript:document.getElementById('logoutForm').submit();">注销</a>
|
||||
${username} <a href="javascript:document.getElementById('logoutForm').submit();">注销</a>
|
||||
<#else>
|
||||
<a href="/login" id="loginmodel">登录 & 注册</a>
|
||||
<a href="/login" id="loginmodel">登录 & 注册</a>
|
||||
</#if>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<#--
|
||||
参数解释:
|
||||
page:当前页码,从1开始
|
||||
pagesize:分页大小
|
||||
totalpages:总页数。也可以放到模板里计算。这里在MyPager类里已计算过了。
|
||||
totalrecords:总记录数
|
||||
url:链接地址,自动拼接page参数。为了简单,没有判断当前页面是否有get参数了,直接做了&连接,默认认为原来就有参数。当前你也可以用servlet自己获取当前url及参数,就不用传了。
|
||||
|
||||
以上这些参数除url外均可以从MyPager实例中获取。其实可以直接把mypager实例传进来,为了便于以后扩展,分字段传过来。
|
||||
-->
|
||||
<#macro fpage page pagesize totalpages totalrecords url>
|
||||
<a class="icon item" id="upPage">
|
||||
<i class="left chevron icon"></i>
|
||||
</a>
|
||||
<#-- <li class="page-item"><span class="page-link">共条${totalrecords}记录 第${page}页/共${totalpages}页</span></li>-->
|
||||
<a class="item" ><span >共条${totalrecords}记录 第${page}页/共${totalpages}页</span></a>
|
||||
|
||||
<#--startpage:起始页码就是page,endpage:结束页码,showfirstpage是否显示首页按钮,showlastpage:是否显示末页按钮,showpre是否显示前...,shownext是否显示后...-->
|
||||
<#assign startpage = page,endpage=10,showfirstpage=false,showlastpage=false,showpre=false,shownext=false,prepage = 1,nextpage=11>
|
||||
<#--是否显示首页按钮及计算初始页码-->
|
||||
<#if page gt 1>
|
||||
<#assign showfirstpage = true>
|
||||
<#--startpage向前挪4页,如果不足4页,则startpage=1-->
|
||||
<#assign startpage=(page-4)>
|
||||
<#if startpage lte 0>
|
||||
<#assign startpage = 1>
|
||||
</#if>
|
||||
</#if>
|
||||
<#--是否显示前n页的...,以及...的链接-->
|
||||
<#if page gt 5>
|
||||
<#assign showpre = true,prepage=page-5>
|
||||
</#if>
|
||||
<#--计算endpage-->
|
||||
<#if page+pagesize-1 lt totalpages>
|
||||
<#assign endpage = page+pagesize-1>
|
||||
<#--显示后面的...按钮-->
|
||||
<#assign shownext = true>
|
||||
<#--后面...的页面码-->
|
||||
<#assign nextpage=page+pagesize>
|
||||
<#--显示末页-->
|
||||
<#assign showlastpage = true>
|
||||
<#else>
|
||||
<#assign endpage = totalpages>
|
||||
</#if>
|
||||
<#if endpage lte 0>
|
||||
<#assign endpage = 1>
|
||||
</#if>
|
||||
|
||||
<#--开始展示-->
|
||||
|
||||
<#--首页-->
|
||||
<#if showfirstpage>
|
||||
<#-- <li class="page-item"><span><a class="page-link" href="${url}&pageNum=1">首页</a></span></li>-->
|
||||
<a class="item" href="${url}&pageNum=1">首页</a>
|
||||
</#if>
|
||||
<#--前面的...-->
|
||||
<#if showpre>
|
||||
<#-- <li class="page-item"><span><a class="page-link" href="${url}&page=${prepage}">...</a></span></li>-->
|
||||
<a class="item" href="${url}&pageNum=${prepage}">...</a>
|
||||
</#if>
|
||||
<#--显示的页码按钮-->
|
||||
<#list startpage..endpage as p>
|
||||
<#-- <li class="page-item <#if p == page>active</#if>"><span><a class="page-link" href="${url}&pageNum=${p}">${p}</a></span></li>-->
|
||||
<a class="item" style=" <#if p == page>background-color: #7d827d;</#if>" href="${url}&pageNum=${p}">${p}</a>
|
||||
</#list>
|
||||
<#--后面的...-->
|
||||
<#if shownext>
|
||||
<#-- <li class="page-item"><span><a class="page-link" href="${url}&pageNum=${nextpage}">...</a></span></li>-->
|
||||
<a class="item" href="${url}&pageNum=${nextpage}">...</a>
|
||||
</#if>
|
||||
<#--显示尾页-->
|
||||
<#if showlastpage>
|
||||
<#-- <li class="page-item"><span><a class="page-link" href="${url}&pageNum=${totalpages}">末页</a></span></li>-->
|
||||
<a class="item" href="${url}&pageNum=${totalpages}">末页</a>
|
||||
</#if>
|
||||
</#macro>
|
||||
@@ -381,6 +381,13 @@
|
||||
<a class="icon item" id="nextPage"> <i class="right chevron icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
<!--pager-->
|
||||
<div class="ui borderless menu">
|
||||
<ul class="pagination">
|
||||
<#import "./comm/page.ftl" as page />
|
||||
<@page.fpage page=pageNum pagesize=pageSize totalpages=pageTotalPages totalrecords=pageTotal url="/?type="+${type}+"&tag="+${tag}+"" />
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user