1.Service代码:
<span style="font-family:Microsoft YaHei;">public interface CommentService {
/**
* 添加点评
* @param comment
* @return
* @throws Exception
*/
public Comment insertComment(Comment comment,List<String> atts) throws Exception;
/**
* 删除点评(根据id来删除已经发表的点评)
* @param id
* @return
* @throws Exception
*/
public boolean deleteCommentById(String id) throws Exception;
/**
* 修改点评
* @param comment
* @return
* @throws Exception
*/
public Comment updateComment(Comment comment,List<String> atts) throws Exception;
}</span>
2.Service里面的Impl:
<span style="font-family:Microsoft YaHei;">@Service
public class CommentServiceImpl implements CommentService{
private static final Logger logger = LoggerFactory.getLogger(ClickZanServiceImpl.class);
@Autowired
private CommentMapper commentMapper;//点评Mapper
@Autowired
private CommentAttachmentMapper commentAttachmentMapper;//附件Mapper
/**
* 添加点评
*/
public Comment insertComment(Comment comment,List<String> attachments) throws Exception {
String id = UUIDUtil.generateKey();
comment.setCreatedate(BaseUtil.timeToString(new Date()));
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String imageupdatename = sdf.format(date);
try {
if(attachments==null){
comment.setId(id) ;
commentMapper.insert(comment);
}else{
comment.setId(id) ;
CommentAttachment com = new CommentAttachment();
commentMapper.insert(comment);
for (String string : attachments) {
com.setCommentid(id);
com.setCreatedate(BaseUtil.ti