文章目录
一. Controller层
- 一. Controller层
- 二.Service层
- 三.dao层
在tensquare_user工程的UserController层, 添加如下的代码 在方法的参数上,接收当前用户的id,喜欢或者是不喜欢的用户的id ,type为喜欢或者不喜欢
/**
* 方法名: updateFanscountAndFollowcount
* 方法描述: 更新粉丝数和关注数
* 修改日期: 2019/2/17 18:59
* @param userid
* @param friendid
* @return void
* @author taohongchao
* @throws
*/
@RequestMapping(value = "/{userid}/{friendid}/{type}",method = RequestMethod.PUT)
public void updateFanscountAndFollowcount(@PathVariable int type,@PathVariable String userid,@PathVariable String friendid){
userService.updateFanscountAndFollowcount(type,userid, friendid);
}
二.Service层
在UserService添加如下的代码, 分别对粉丝数和关注数进行处理
/**
* 修改粉丝数量和关注数量
* @param type
* @param userid
* @param friendid
*/
public void updateFanscountAndFollowcount(int type ,String userid, String friendid) {
//更新被关注人的粉丝数
userDao.updateFanscount(type,friendid);
//更新当前用户的关注数
userDao.updateFollowcount(type,userid);
}
三.dao层
在UserDao中, 编写sql,进行粉丝数和关注数的处理
/**
* 修改粉丝的数量信息
* @param type 数量加一或者减一
* @param friendid
*/
@Modifying
@Query(value = "update tb_user set fanscount=fanscount+? where id=?",nativeQuery = true)
public void updateFanscount(int type, String friendid);
/**
* 修改关注的数量信息
* @param type 数量加一或者减一
* @param friendid
*/
@Modifying
@Query(value = "update tb_user set followcount=followcount+? where id=?",nativeQuery = true)
public void updateFollowcount(int type, String userid);