微信小程序收藏功能

首先在wxml页面布局: (我这里简单的步了个局)
我这里简单的布了个局
这里我们用的技术栈就是wx:if,用它来判断收藏状态。catchtap是点击事件,点击切换收藏的状态。下面上js代码。
在这里插入图片描述
这样一个收藏功能加提示就做好了。

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以回答这个问题。以下是一个简单的实现收藏功能的 Spring Boot 微信小程序代码示例: 1. 创建一个收藏实体类 ```java @Entity @Table(name = "collection") public class Collection { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private Long userId; private Long articleId; public Collection() { } public Collection(Long userId, Long articleId) { this.userId = userId; this.articleId = articleId; } // getters and setters } ``` 2. 创建一个收藏服务类 ```java @Service public class CollectionService { @Autowired private CollectionRepository collectionRepository; public boolean isCollected(Long userId, Long articleId) { Collection collection = collectionRepository.findByUserIdAndArticleId(userId, articleId); return collection != null; } public void collect(Long userId, Long articleId) { if (!isCollected(userId, articleId)) { Collection collection = new Collection(userId, articleId); collectionRepository.save(collection); } } public void cancelCollect(Long userId, Long articleId) { Collection collection = collectionRepository.findByUserIdAndArticleId(userId, articleId); if (collection != null) { collectionRepository.delete(collection); } } } ``` 3. 创建一个收藏控制器类 ```java @RestController @RequestMapping("/api/collection") public class CollectionController { @Autowired private CollectionService collectionService; @PostMapping("/collect") public void collect(@RequestParam("userId") Long userId, @RequestParam("articleId") Long articleId) { collectionService.collect(userId, articleId); } @PostMapping("/cancelCollect") public void cancelCollect(@RequestParam("userId") Long userId, @RequestParam("articleId") Long articleId) { collectionService.cancelCollect(userId, articleId); } @GetMapping("/isCollected") public boolean isCollected(@RequestParam("userId") Long userId, @RequestParam("articleId") Long articleId) { return collectionService.isCollected(userId, articleId); } } ``` 以上代码仅供参考,实际应用时需要根据具体需求进行修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值