2025-04-08 23:41:22 +08:00

19 lines
893 B
Java

package com.luozhihui.project.mapper;
import com.luozhihui.project.entity.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
public interface CommentMapper {
// SQL语句 将 姓名、内容、帖子ID、用户ID、发布时间插入到comments表中
@Insert("insert into `comments`(`UserName`,`text`,`CarId`,`UserId`,`pub_date`) VALUES(#{UserName},#{text},#{CarId},#{UserId},NOW())")
@Transactional
void save(Comment comment);
//查询所有评论
@Select("SELECT comments.CommentId,comments.text,comments.pub_date,car.CarLicense,car.CarModel,user.UserName FROM `comments` JOIN `user` ON `user`.UserId = `comments`.UserId JOIN `car` ON `car`.CarId = `comments`.CarId ")
List<Comment> FindAllComment();
}