1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| package com.samjava.mall.controller;
import com.samjava.mall.AjaxResponse; import com.samjava.mall.model.Article; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*;
import java.util.Date;
@Slf4j @RestController @RequestMapping("/rest") //请求前缀。 public class ArticleController {
//查询一篇文章,根据ID // @RequestMapping(value = "/articles/{id}",method = RequestMethod.GET) @GetMapping("/articles/{id}") public AjaxResponse getArticle(@PathVariable("id") Long id){
Article article = Article.builder() .id(1L) .author("Sam") .content("内容内容") .createTime(new Date()) .title("tittle1").build(); log.info("getArticle:"+article); return AjaxResponse.success(article); }
//新增一篇文章 // @RequestMapping(value = "/articles",method = RequestMethod.POST) @PostMapping("/articles") public AjaxResponse saveArticle(@RequestBody Article article){ log.info("saveArticle:"+ article);
return AjaxResponse.success(); }
//修改一篇文章 // @RequestMapping(value = "/articles",method = RequestMethod.PUT) @PutMapping("/articles") public AjaxResponse updateArticle(@RequestBody Article article){
// if(article.getId() == null){ // // // }
log.info("updateArticle:"+article); return AjaxResponse.success(); }
//删除一篇文章 // @RequestMapping(value = "/articles/{id}",method = RequestMethod.DELETE) @DeleteMapping("/articles/{id}") public AjaxResponse deleteArticle(@PathVariable("id") Long id){
log.info("deleteArticle:"+id); return AjaxResponse.success(); }
}
|