create comment

This commit is contained in:
aisensiy
2017-08-15 16:36:07 +08:00
parent 9dbb008dcb
commit 445311ee1b
15 changed files with 479 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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));
}
}