您当前的位置: 首页 > 

java持续实践

暂无认证

  • 2浏览

    0关注

    746博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

黑马十次方项目day07-12之在用户模块添加粉丝数和关注数

java持续实践 发布时间:2019-02-17 19:19:03 ,浏览量:2

文章目录
      • 一. Controller层
      • 二.Service层
      • 三.dao层

一. Controller层

在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);
关注
打赏
1658054974
查看更多评论
立即登录/注册

微信扫码登录

0.0533s