Browse Source

dianzan

dev
Administrator 1 month ago
parent
commit
6f87f2cdf7
  1. 36
      src/main/java/org/hlrj/duobao_demo/controller/RecommendationController.java
  2. 10
      src/main/java/org/hlrj/duobao_demo/controller/SpecialTopicController.java
  3. 6
      src/main/java/org/hlrj/duobao_demo/service/IRecommendationService.java
  4. 6
      src/main/java/org/hlrj/duobao_demo/service/impl/RecommendationServiceImpl.java
  5. 4
      src/main/resources/mapper/RecommendationMapper.xml

36
src/main/java/org/hlrj/duobao_demo/controller/RecommendationController.java

@ -67,18 +67,18 @@ public class RecommendationController {
return Result.success(); return Result.success();
} }
/**
* 新增操作
* @param recommendation
* @return
*/
@PostMapping("/addRecommendation")
public Result addRecommendation(@RequestBody Recommendation recommendation) {
log.info("新增推荐内容:{}",recommendation);
//调用service
recommendationService.add(recommendation);
return Result.success();
}
// /**
// * 新增操作
// * @param recommendation
// * @return
// */
// @PostMapping("/addRecommendation")
// public Result addRecommendation(@RequestBody Recommendation recommendation) {
// log.info("新增推荐内容:{}",recommendation);
// //调用service
// recommendationService.add(recommendation);
// return Result.success();
// }
/** /**
* 根据id查询数据 * 根据id查询数据
@ -106,13 +106,15 @@ public class RecommendationController {
/** /**
* 点赞数量加1 * 点赞数量加1
* @param recommendation
* @param
* @return * @return
*/ */
@PostMapping("/addLike")
public Result addLike(@RequestBody Recommendation recommendation){
log.info("增加点赞操作:{}",recommendation);
recommendationService.addLike(recommendation);
@PostMapping("/addLike/{id}")
public Result addLike( @PathVariable Integer id){
log.info("增加点赞操作:{}");
Recommendation recommendation1 = recommendationService.selectById(id);
recommendationService.addLike(recommendation1);
return Result.success(); return Result.success();
} }

10
src/main/java/org/hlrj/duobao_demo/controller/SpecialTopicController.java

@ -68,12 +68,14 @@ public class SpecialTopicController {
} }
/** /**
* 点赞数量加1 * 点赞数量加1
* @param specialTopic
* @param id
* @return * @return
*/ */
@PostMapping("/addLike")
public Result addLike(@RequestBody SpecialTopic specialTopic){
log.info("增加点赞操作:{}",specialTopic);
@PostMapping("/addLike/{id}")
public Result addLike(@PathVariable Integer id){
log.info("增加点赞操作:{}");
SpecialTopic specialTopic = specialTopicService.selectById(id);
specialTopicService.addLike(specialTopic); specialTopicService.addLike(specialTopic);
return Result.success(); return Result.success();
} }

6
src/main/java/org/hlrj/duobao_demo/service/IRecommendationService.java

@ -27,11 +27,7 @@ public interface IRecommendationService extends IService<Recommendation> {
*/ */
public void delete(Integer id); public void delete(Integer id);
/**
* 增添
* @param recommendation
*/
public void add(Recommendation recommendation);
/** /**
* 根据id进行查询 * 根据id进行查询

6
src/main/java/org/hlrj/duobao_demo/service/impl/RecommendationServiceImpl.java

@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -36,12 +37,7 @@ public class RecommendationServiceImpl extends ServiceImpl<RecommendationMapper,
recommendationMapper.deleteById(id); recommendationMapper.deleteById(id);
} }
@Override
public void add(Recommendation recommendation) {
recommendation.setPublishTime(LocalDateTime.now());
recommendationMapper.insert(recommendation);
}
@Override @Override
public Recommendation selectById(Integer id) { public Recommendation selectById(Integer id) {

4
src/main/resources/mapper/RecommendationMapper.xml

@ -29,7 +29,7 @@
<if test="author !=null and author!=''"> <if test="author !=null and author!=''">
author=#{author}, author=#{author},
</if> </if>
<if test="publishTime !=null and publishTime!=''">
<if test="publishTime !=null">
publish_time=#{publishTime}, publish_time=#{publishTime},
</if> </if>
<if test="comments !=null and comments!=''"> <if test="comments !=null and comments!=''">
@ -42,7 +42,7 @@
source=#{source}, source=#{source},
</if> </if>
<if test="head !=null and head!=''"> <if test="head !=null and head!=''">
head=#{head}
head=#{head},
</if> </if>
likes = likes + 1 likes = likes + 1
</set> </set>

Loading…
Cancel
Save