parent
526820f9cb
commit
3b6e837ebd
@ -1 +1 @@
|
||||
22912
|
||||
9364
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.sky.config;
|
||||
//配置类Oss
|
||||
|
||||
import com.sky.properties.AliOssProperties;
|
||||
import com.sky.utils.AliOssUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class OssConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
|
||||
log.info("开始上传阿里云文件上传工具类对象:{}",aliOssProperties);
|
||||
return new AliOssUtil(aliOssProperties.getEndpoint(),aliOssProperties.getAccessKeyId(),
|
||||
aliOssProperties.getAccessKeySecret(),aliOssProperties.getBucketName());
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/*
|
||||
* 菜品管理
|
||||
* */
|
||||
@RestController
|
||||
@RequestMapping("/admin/dish")
|
||||
@Api(tags = "菜品相关接口")
|
||||
@Slf4j
|
||||
public class DishController {
|
||||
@Autowired
|
||||
private DishService dishService;
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("新增菜品")
|
||||
public Result save(@RequestBody DishDTO dishDTO){
|
||||
log.info("新增菜品{}",dishDTO);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.DishFlavor;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DishFlavorMapper {
|
||||
|
||||
// 批量插入
|
||||
void insertBatch(List<DishFlavor> flavors);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
|
||||
public interface DishService {
|
||||
// 新增菜品和对应的口味
|
||||
public void saveWithFlavor(DishDTO dishDTO);
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.DishFlavor;
|
||||
import com.sky.mapper.DishFlavorMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.service.DishService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DishServiceImpl implements DishService {
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
|
||||
@Autowired
|
||||
private DishFlavorMapper dishFlavorMapper;
|
||||
|
||||
//新增菜品和口味数据,加上事务管理,原子性。成功全成功,失败全失败
|
||||
@Transactional
|
||||
@Override
|
||||
public void saveWithFlavor(DishDTO dishDTO) {
|
||||
Dish dish = new Dish();
|
||||
//对象的属性拷贝
|
||||
BeanUtils.copyProperties(dishDTO,dish);
|
||||
//向菜品表插入一条数据
|
||||
dishMapper.insert(dish);
|
||||
|
||||
Long dishId = dish.getId();
|
||||
|
||||
// 向口味表插入n条数据
|
||||
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||
if(flavors != null&&flavors.size() > 0){
|
||||
//给口味附加上菜品的id
|
||||
flavors.forEach(dishFlavor -> {
|
||||
dishFlavor.setDishId(dishId);
|
||||
});
|
||||
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* ┌─────────────────────────────────────────────────────────────┐
|
||||
* │┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│
|
||||
* ││Esc│!1 │@2 │#3 │$4 │%5 │^6 │&7 │*8 │(9 │)0 │_- │+= │|\ │`~ ││
|
||||
* │├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┤│
|
||||
* ││ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{[ │}] │ BS ││
|
||||
* │├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤│
|
||||
* ││ Ctrl │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter ││
|
||||
* │├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────┬───┤│
|
||||
* ││ Shift │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│Shift │Fn ││
|
||||
* │└─────┬──┴┬──┴──┬┴───┴───┴───┴───┴───┴──┬┴───┴┬──┴┬─────┴───┘│
|
||||
* │ │Fn │ Alt │ Space │ Alt │Win│ HHKB │
|
||||
* │ └───┴─────┴───────────────────────┴─────┴───┘ │
|
||||
* └─────────────────────────────────────────────────────────────┘
|
||||
* Happy Hacking auto coding
|
||||
*/
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.DishFlavorMapper">
|
||||
|
||||
<insert id="insertBatch">
|
||||
insert into dish_flavor (dish_id, name, value) VALUES
|
||||
<foreach collection="flavors" item="df" separator=",">
|
||||
(#{df.dishId},#{df.name},#{df.value}})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.DishMapper">
|
||||
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user,status)
|
||||
values
|
||||
(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})
|
||||
</insert>
|
||||
</mapper>
|
Before Width: | Height: | Size: 371 KiB |
Before Width: | Height: | Size: 66 KiB |
@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<div v-if="visible" class="modal">
|
||||
<h2>{{ title }}</h2>
|
||||
<button @click="closeModal" class="close-button">关闭</button>
|
||||
<div v-for="comment in comments" :key="comment.comment_id" class="comment">
|
||||
<button @click="handleDelete(comment)" class="delete-button">删除</button>
|
||||
<p class="post-title"><strong>文章标题:</strong> {{ comment.post_title }}</p>
|
||||
<p class="comment-content"><strong>评论内容:</strong> {{ comment.content }}</p>
|
||||
<p class="comment-author"><strong>评论者:</strong> {{ comment.username }}</p>
|
||||
<p class="comment-time"><strong>评论时间:</strong> {{ comment.updated_at }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { defineProps, defineEmits } from 'vue';
|
||||
import { useLoginStore } from '@/stores/Login';
|
||||
import axios from 'axios';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
|
||||
const props = defineProps<{
|
||||
title: string;
|
||||
visible: boolean;
|
||||
comments: Array<{
|
||||
comment_id: number;
|
||||
post_id: number;
|
||||
user_id: number;
|
||||
content: string;
|
||||
updated_at: string;
|
||||
username: string;
|
||||
post_title: string;
|
||||
}>;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', value: boolean): void;
|
||||
}>();
|
||||
|
||||
const loginStore = useLoginStore();
|
||||
|
||||
const closeModal = () => {
|
||||
emit('update:visible', false);
|
||||
};
|
||||
|
||||
const handleDelete = (comment: {
|
||||
comment_id: number;
|
||||
post_id: number;
|
||||
user_id: number;
|
||||
content: string;
|
||||
updated_at: string;
|
||||
username: string;
|
||||
post_title: string;
|
||||
}) => {
|
||||
console.log("当前登录用户的用户名:",loginStore.userInfo.username);
|
||||
console.log("当前评论用户的用户名:",String(comment.username));
|
||||
if (loginStore.userInfo.username === comment.username) {
|
||||
// 用户可以删除评论
|
||||
ElMessageBox.confirm('确定要删除此评论吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
// 发送删除请求
|
||||
axios.delete('http://localhost:8080/comment/delete', {
|
||||
data: {
|
||||
token: loginStore.userInfo.token,
|
||||
comment_id: comment.comment_id,
|
||||
post_id: comment.post_id
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
// 处理成功响应
|
||||
console.log('Response:', response.data);
|
||||
// 从 comments 中移除已删除的评论
|
||||
props.comments.splice(props.comments.indexOf(comment), 1);
|
||||
ElMessageBox.alert('评论已删除', '成功', {
|
||||
confirmButtonText: '确定',
|
||||
type: 'success'
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
// 处理错误
|
||||
console.error('Error:', error);
|
||||
ElMessageBox.alert('删除评论失败,请重试', '错误', {
|
||||
confirmButtonText: '确定',
|
||||
type: 'error'
|
||||
});
|
||||
});
|
||||
}).catch(() => {
|
||||
// 用户取消删除
|
||||
ElMessageBox.alert('已取消删除', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
type: 'info'
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// 用户不能删除评论
|
||||
ElMessageBox.alert('您只能删除您自己的评论', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
type: 'warning'
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
z-index: 1000;
|
||||
width: 80%;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.close-button {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
background-color: #f4f4f4;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
padding: 5px 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.close-button:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.comment {
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.comment-content {
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.comment-author {
|
||||
font-size: 16px;
|
||||
color: #555;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.post-title, .comment-time {
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.delete-button {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 500px;
|
||||
background-color: #ff4d4d;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 5px 10px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.delete-button:hover {
|
||||
background-color: #ff1a1a;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,114 @@
|
||||
<!-- src/components/Modal.vue -->
|
||||
<template>
|
||||
<div v-if="visible" class="modal-overlay" @click="closeModal">
|
||||
<div class="modal-content" @click.stop>
|
||||
<h2>{{ title }}</h2>
|
||||
<div v-if="step === 1">
|
||||
<button @click="selectType('blog')">查询博客</button>
|
||||
<button @click="selectType('comment')">查询评论</button>
|
||||
</div>
|
||||
<div v-else-if="step === 2">
|
||||
<div v-if="selectedType === 'blog'">
|
||||
<button @click="selectCriteria('author')">根据作者名称查询</button>
|
||||
<button @click="selectCriteria('title')">根据文章名称查询</button>
|
||||
</div>
|
||||
<div v-else-if="selectedType === 'comment'">
|
||||
<button @click="selectCriteria('user')">根据用户名称查询</button>
|
||||
<button @click="selectCriteria('content')">根据评论内容查询</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="step === 3">
|
||||
<input v-model="searchQuery" type="text" placeholder="请输入查询内容" />
|
||||
<button @click="performSearch">确认</button>
|
||||
<button @click="closeModal">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
const props = defineProps<{
|
||||
title: string;
|
||||
visible: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', value: boolean): void;
|
||||
(e: 'select', type: string, criteria: string, query: string): void;
|
||||
}>();
|
||||
|
||||
const step = ref(1);
|
||||
const selectedType = ref('');
|
||||
const selectedCriteria = ref('');
|
||||
const searchQuery = ref('');
|
||||
|
||||
const closeModal = () => {
|
||||
emit('update:visible', false);
|
||||
step.value = 1;
|
||||
selectedType.value = '';
|
||||
selectedCriteria.value = '';
|
||||
searchQuery.value = '';
|
||||
};
|
||||
|
||||
const selectType = (type: string) => {
|
||||
selectedType.value = type;
|
||||
step.value = 2;
|
||||
};
|
||||
|
||||
const selectCriteria = (criteria: string) => {
|
||||
selectedCriteria.value = criteria;
|
||||
step.value = 3;
|
||||
};
|
||||
|
||||
const performSearch = () => {
|
||||
emit('select', selectedType.value, selectedCriteria.value, searchQuery.value);
|
||||
closeModal();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
width: 300px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.modal-content button {
|
||||
margin: 10px;
|
||||
padding: 10px 20px;
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-content button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
.modal-content input {
|
||||
margin: 10px;
|
||||
padding: 10px;
|
||||
width: calc(100% - 20px);
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,144 @@
|
||||
<template>
|
||||
<div class="comment-section">
|
||||
<h2>评论区</h2>
|
||||
<!-- 评论列表 -->
|
||||
<div v-for="(comment, index) in commentList" :key="index" class="comment">
|
||||
<p class="comment-content">{{ comment.content }}</p>
|
||||
<div class="comment-meta">
|
||||
<span class="comment-username">{{ comment.username }}</span>
|
||||
<span class="comment-updated-at">{{ comment.updated_at }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 添加评论表单 -->
|
||||
<form @submit.prevent="addComment">
|
||||
<textarea v-model="newComment" placeholder="添加评论..." required></textarea>
|
||||
<button type="submit">提交</button>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref,reactive,onMounted } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { useLoginStore } from '@/stores/Login';
|
||||
import { useToast } from 'vue-toastification'
|
||||
|
||||
const toast = useToast();
|
||||
const loginStore = useLoginStore();
|
||||
|
||||
const props = defineProps(['post_id'])
|
||||
|
||||
interface comment{
|
||||
post_id: number;
|
||||
username: string;
|
||||
content: string;
|
||||
token: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
let commentList = ref<comment[]>([]);
|
||||
|
||||
function getComments(){
|
||||
axios.get('http://localhost:8080/comment',{
|
||||
params:{
|
||||
post_id: props.post_id
|
||||
}
|
||||
})
|
||||
.then(res=>{
|
||||
commentList.value = res.data.data;
|
||||
console.log(commentList.value);
|
||||
})
|
||||
.catch(err=>{
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
|
||||
const newComment = ref('');
|
||||
const addComment = async () => {
|
||||
if(loginStore.userInfo.token===''||loginStore.userInfo.token===null){
|
||||
toast.error("请先登录");
|
||||
}
|
||||
else{
|
||||
axios.post('http://localhost:8080/comment',{
|
||||
post_id: props.post_id,
|
||||
content: newComment.value,
|
||||
token: loginStore.userInfo.token
|
||||
})
|
||||
.then(res=>{
|
||||
toast.success("评论成功");
|
||||
getComments();
|
||||
newComment.value = '';
|
||||
})
|
||||
.catch(err=>{
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(()=>{
|
||||
getComments();
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
<style scoped>
|
||||
.comment-section {
|
||||
position: fixed;
|
||||
top: 100px;
|
||||
right: 50%; /* 调整右侧位置 */
|
||||
transform: translateX(250%); /* 调整位置以居中 */
|
||||
width: 300px;
|
||||
background-color: #fff;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
padding: 10px;
|
||||
height: 75vh;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.comment {
|
||||
margin-bottom: 15px;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd; /* 添加边框 */
|
||||
border-radius: 5px; /* 圆角边框 */
|
||||
background-color: #f9f9f9; /* 浅背景色 */
|
||||
}
|
||||
|
||||
.comment-content {
|
||||
font-size: 16px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.comment-meta {
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.comment-username {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
margin-bottom: 10px;
|
||||
padding: 5px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 5px 10px;
|
||||
border: none;
|
||||
background-color: #007bff;
|
||||
color: #fff;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,23 @@
|
||||
package top.lejings.demo;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig {
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**") // 对所有的URL都生效
|
||||
.allowedOrigins("http://localhost:82") // 允许的来源
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法
|
||||
.allowedHeaders("*") // 允许的头部
|
||||
.allowCredentials(true); // 是否允许发送Cookie
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package top.lejings.demo.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.lejings.demo.pojo.Comments;
|
||||
import top.lejings.demo.pojo.Result;
|
||||
import top.lejings.demo.service.CommentsService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* 对评论进行操作
|
||||
* 查询评论
|
||||
* 增加评论
|
||||
* */
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/comment")
|
||||
@CrossOrigin(origins = "http://localhost:82")
|
||||
public class CommentsController {
|
||||
|
||||
@Autowired
|
||||
CommentsService commentsService;
|
||||
|
||||
@GetMapping
|
||||
@CrossOrigin(origins = "http://localhost:82")
|
||||
public Result getComment(Integer post_id){
|
||||
log.info("获取文章id为{}的评论区",post_id);
|
||||
List<Comments> CommentsList = commentsService.getComment(post_id);
|
||||
log.info("列表为{}",CommentsList);
|
||||
return Result.success(CommentsList);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@CrossOrigin(origins = "http://localhost:82")
|
||||
public Result addComment(@RequestBody Comments comments){
|
||||
log.info("增加新的评论{}",comments);
|
||||
commentsService.addComment(comments);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
public Result search(String content,String username){
|
||||
log.info("特定查询评论");
|
||||
List<Comments> searchComments = commentsService.search(content,username);
|
||||
return Result.success(searchComments);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
public Result deleteComment(@RequestBody Comments comments){
|
||||
log.info("删除评论{}",comments.getComment_id());
|
||||
commentsService.delete(comments);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package top.lejings.demo.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import top.lejings.demo.pojo.Comments;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CommentsMapper {
|
||||
|
||||
List<Comments> getComment(Integer postId);
|
||||
|
||||
void addComment(Comments comments);
|
||||
|
||||
// 根据用户名搜索评论
|
||||
|
||||
List<Comments> searchByUser(@Param("username") String username);
|
||||
|
||||
// 根据内容搜索评论
|
||||
|
||||
List<Comments> searchByContent(@Param("content") String content);
|
||||
|
||||
@Delete("DELETE FROM comments WHERE comment_id = #{comment_id} AND post_id = #{post_id} AND user_id = #{user_id}")
|
||||
void delete(Comments comments);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package top.lejings.demo.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/*
|
||||
* 评论实体类和DTO
|
||||
*
|
||||
* */
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Comments {
|
||||
private Integer comment_id;
|
||||
private Integer post_id;
|
||||
private String post_title;
|
||||
private Integer user_id;
|
||||
private String content;
|
||||
private String username;
|
||||
private String token;//可以为空,为空则为游客
|
||||
private LocalDateTime updated_at;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package top.lejings.demo.service;
|
||||
|
||||
import top.lejings.demo.pojo.Comments;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommentsService {
|
||||
List<Comments> getComment(Integer postId);
|
||||
|
||||
void addComment(Comments comments);
|
||||
|
||||
List<Comments> search(String content, String username);
|
||||
|
||||
void delete(Comments comments);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue