1. 程式人生 > >springCloud 使用sql更新資料庫

springCloud 使用sql更新資料庫

1、controller 層:

@RequestMapping(value = "v2/member/blog/cancelBlogShield")//取消遮蔽別人的帖子
public Object cancelBlogShield(@RequestParam String blogId, HttpServletRequest httpServletRequest) {
Member member = memberService.checkIdAndToken(httpServletRequest);
if (member == null) {
return new APIResult(1000, "登入失效");
}
int rs = memberblogShieldService.updateActivesFalseByMemberIdAndBlogId(member.getId(), blogId);
System.out.println("updateBlogShieldNun=====" + rs);
return APIResult.createSuccess();
}

2、serviceImpl層:

@Autowired
MemberBlogShieldRepository memberBlogShieldRepository;

public int updateActivesFalseByMemberIdAndBlogId(String memberId, String blogId) {
return memberBlogShieldRepository.updateActivesFalseByMemberIdAndBlogId(memberId, blogId);
}

3、repository層:

@Modifying
@Transactional
@Query("update MemberBlogShield set actives = 0 where member_id = ?1 and blog_id = ?2")
int updateActivesFalseByMemberIdAndBlogId(String memberId, String blogId);