create comment
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package io.spring.infrastructure.comment;
|
||||
|
||||
import io.spring.core.comment.Comment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Mapper
|
||||
public interface CommentMapper {
|
||||
void insert(@Param("comment") Comment comment);
|
||||
|
||||
Comment findById(@Param("id") String id);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.spring.infrastructure.comment;
|
||||
|
||||
import io.spring.core.comment.Comment;
|
||||
import io.spring.core.comment.CommentRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class MyBatisCommentRepository implements CommentRepository {
|
||||
private CommentMapper commentMapper;
|
||||
|
||||
@Autowired
|
||||
public MyBatisCommentRepository(CommentMapper commentMapper) {
|
||||
this.commentMapper = commentMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Comment comment) {
|
||||
commentMapper.insert(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Comment> findById(String id) {
|
||||
return Optional.ofNullable(commentMapper.findById(id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user