提交 409dccea 编写于 作者: 221900223吴良杰's avatar 221900223吴良杰

“我的”mapper

上级 388ef380
package com.nav.dao;
import com.nav.pojo.FollowList;
import com.nav.pojo.User;
import com.nav.vo.result.LifePostResult;
import org.apache.ibatis.annotations.Param;
......@@ -49,6 +50,24 @@ public interface MyDao {
*/
public List<User> getFollowList(@Param("userId") long userId);
/**
* @Author: wlj
* @Description: 根据用户id和关注者id添加关注关系
* @DateTime: 2022/5/3 10:26
* @Params: [userId, followerId]
* @Return void
*/
public void addFollower(FollowList followList);
/**
* @Author: wlj
* @Description: 根据用户id和关注者id取消关注关系
* @DateTime: 2022/5/3 10:27
* @Params: [userId, followerId]
* @Return void
*/
public void deleteFollower(FollowList followList);
/**
* @Author: wlj
* @Description: 根据用户id获取粉丝列表
......@@ -57,4 +76,6 @@ public interface MyDao {
* @Return java.util.List<com.nav.pojo.User>
*/
public List<User> getFanList(@Param("userId") long userId);
}
......@@ -29,7 +29,7 @@ public interface MyService {
* @Params: [userId]
* @Return java.util.List<com.nav.vo.result.LifePostResult>
*/
public List<LifePostResult> getMyPosts(@Param("userId") long userId);
public List<LifePostResult> getMyPosts(@Param("userId") long userId,int currPage, int pageSize);
/**
* @Author: wlj
......@@ -38,7 +38,7 @@ public interface MyService {
* @Params: [userId]
* @Return java.util.List<com.nav.vo.result.LifePostResult>
*/
public List<LifePostResult> getMyCollection(@Param("userId") long userId);
public List<LifePostResult> getMyCollection(@Param("userId") long userId,int currPage, int pageSize);
/**
* @Author: wlj
......
package com.nav.service.imp;
import com.nav.dao.MyDao;
import com.nav.dao.PostDao;
import com.nav.dao.UserDao;
import com.nav.pojo.User;
import com.nav.service.MyService;
import com.nav.vo.result.LifePostResult;
......@@ -17,20 +19,33 @@ import java.util.List;
@Service
public class MyServiceImpl implements MyService {
private MyDao myDao;
private UserDao userDao;
private PostDao postDao;
@Override
public User getMyInfo(long userId) {
return myDao.getMyInfo(userId);
return userDao.selectUserByID(userId);
}
@Override
public List<LifePostResult> getMyPosts(long userId) {
return myDao.getMyPosts(userId);
public List<LifePostResult> getMyPosts(long userId,int currPage, int pageSize) {
//分页
List<LifePostResult> posts = postDao.selectLifePostById(userId);
//从第几条数据开始
int firstIndex = (currPage - 1) * pageSize;
//到第几条数据结束
int lastIndex = currPage * pageSize;
return posts.subList(firstIndex, lastIndex); //直接在list中截取
}
@Override
public List<LifePostResult> getMyCollection(long userId) {
return myDao.getMyCollection(userId);
public List<LifePostResult> getMyCollection(long userId,int currPage, int pageSize) {
//分页
List<LifePostResult> posts = myDao.getMyCollection(userId);
//从第几条数据开始
int firstIndex = (currPage - 1) * pageSize;
//到第几条数据结束
int lastIndex = currPage * pageSize;
return posts.subList(firstIndex, lastIndex); //直接在list中截取
}
@Override
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nav.dao.MyDao">
<select id="getMyCollection" parameterType="long" resultType="com.nav.vo.result.LifePostResult">
select p.postTitle,p.postContent,p.postCover,p.nickname,p.gmtCreate,c.userId
from collectionList c
left join post p
on c.postId=p.id
where c.userId=#{userId}
</select>
<select id="getFollowList" parameterType="long" resultType="com.nav.pojo.User">
select * from user
INNER JOIN followList
on user.id=follwList.userId
where followList.userId=#{userId};
</select>
<select id="getFanList" parameterType="long" resultType="com.nav.pojo.User">
select * from user
INNER JOIN followList
on user.id=followList.followId
where followList.followId=#{userId};
</select>
<insert id="addFollower" parameterType="com.nav.pojo.FollowList">
insert into followList(userId,followId)
value(#{userId}, #{followId})
</insert>
<delete id="deleteFollower" parameterType="com.nav.pojo.FollowList">
delete from followList
where userId=#{userId} and followId=#{followId}
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册