SpringBoot+Spring+JPA+Redis+MySql+Swagger 博客系统 Day2

发表文章

发表文章的时候,可以支持添加标签

DTO
package com.xsz.dto;

import java.util.List;

import com.xsz.entity.Blog;
import com.xsz.entity.Tag;

public class ArticleDTO extends Blog {
	private List<Tag> tags;

	public List<Tag> getTags() {
		return tags;
	}

	public void setTags(List<Tag> tags) {
		this.tags = tags;
	}
	
	
}

Conroller
//发表文章
	@ApiOperation(value = "发表文章", notes = "发表文章")
	@ApiImplicitParam(name = "adto", value = "发表文章对象", required = true, dataType = "ArticleDTO")
	@PostMapping("save")
	public Blog add(@RequestBody ArticleDTO adto) {
		return blogService.add(adto);
	}

标签管理

package com.xsz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;

import com.xsz.entity.Tag;
import com.xsz.service.TagService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author Bsea
 * 	文件管理模块 标签控制类
 */
@RequestMapping("tag")
@RestController
@Api(value = "标签API")
public class TagController {
	@Resource
	TagService tagService;
	//发表标签
	@ApiOperation(value = "新建标签", notes = "新建标签")
	@PostMapping("save")
	public Tag add(@RequestBody Tag tag) {
		return tagService.add(tag);
	}
	//修改标签
	@ApiOperation(value = "修改标签", notes = "修改标签")
	@PostMapping("modify")
	public Tag update(@RequestBody Tag tag) {
		return tagService.update(tag);
	}
	//删除标签
	@ApiOperation(value = "删除标签", notes = "删除标签")
	@ApiImplicitParam(name = "id", value = "标签的主键Id", required = true, dataType = "String", paramType = "path")
	@PostMapping("delete/{id}")
	public Map<String, String> delete(@PathVariable("id") String id) {
		Map<String, String> result=new HashMap();
		tagService.delete(id);
		result.put("result", "success");
		return result;
	}
	
	

    //查询标签
	@ApiOperation(value = "查询所有标签", notes = "查询所有标签")
	@GetMapping("showAll")
	public List<Tag> selectAll() {
		return tagService.selectAll();
	}
	

}

评论管理

package com.xsz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;

import com.xsz.entity.Comment;
import com.xsz.service.CommentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author Bsea
 * 	文件管理模块 评论控制类
 */
@RequestMapping("Comment")
@RestController
@Api(value = "评论API")
public class CommentController {
	@Resource
	CommentService commentService;
	//发表评论
	@ApiOperation(value = "新建评论", notes = "新建评论")
	@PostMapping("save")
	public Comment add(@RequestBody Comment comment) {
		return commentService.add(comment);
	}
	//修改评论
	@ApiOperation(value = "修改评论", notes = "修改评论")
	@PostMapping("modify")
	public Comment update(@RequestBody Comment comment) {
		return commentService.update(comment);
	}
	//删除评论
	@ApiOperation(value = "删除评论", notes = "删除评论")
	@ApiImplicitParam(name = "id", value = "评论的主键Id", required = true, dataType = "String", paramType = "path")
	@PostMapping("delete/{id}")
	public Map<String, String> delete(@PathVariable("id") String id) {
		Map<String, String> result=new HashMap();
		commentService.delete(id);
		result.put("result", "success");
		return result;
	}
	
	

    //查询评论
	@ApiOperation(value = "查询所有评论", notes = "查询所有评论")
	@GetMapping("showAll")
	public List<Comment> selectAll() {
		return commentService.selectAll();
	}
	
	    //根据blog id查询评论
		@ApiOperation(value = "根据博客查询评论", notes = "根据blog id查询评论")
		@GetMapping("showByBlog/{bid}")
		@ApiImplicitParam(name = "bid", value = "评论的主键Id", required = true, dataType = "String", paramType = "path")
		public List<Comment> selectByBlog(@PathVariable("bid") String blogId) {
			return commentService.selectByBlogId(blogId);
		}
	

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值