|
@@ -2,6 +2,8 @@ package org.example;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Optional;
|
|
|
|
+
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
@@ -20,6 +22,9 @@ public class ArticleController {
|
|
@Autowired
|
|
@Autowired
|
|
private IArticleService articleService;
|
|
private IArticleService articleService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ArticleRepository articleRepository;
|
|
|
|
+
|
|
//Fetches all articles
|
|
//Fetches all articles
|
|
@GetMapping(value= "articles")
|
|
@GetMapping(value= "articles")
|
|
public ResponseEntity<List<ArticleInfo>> getAllArticles() {
|
|
public ResponseEntity<List<ArticleInfo>> getAllArticles() {
|
|
@@ -43,4 +48,43 @@ public class ArticleController {
|
|
headers.setLocation(builder.path("/article/{id}").buildAndExpand(article.getArticleId()).toUri());
|
|
headers.setLocation(builder.path("/article/{id}").buildAndExpand(article.getArticleId()).toUri());
|
|
return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
|
|
return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
|
|
}
|
|
}
|
|
|
|
+ @GetMapping("/getOne")
|
|
|
|
+ public Optional<Article> getOne(Long id) {
|
|
|
|
+ return articleRepository.findById(id);
|
|
|
|
+ }
|
|
|
|
+ // 127.0.0.1:8080/user/getOne?id=1
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增数据.
|
|
|
|
+ * @param article 新增Test对象
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/insert")
|
|
|
|
+ public String insert(Article article) {
|
|
|
|
+ System.out.println(article);
|
|
|
|
+ articleRepository.save(article);
|
|
|
|
+ return "success";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据ID删除数据.
|
|
|
|
+ * @param id ID
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @GetMapping("/delete")
|
|
|
|
+ public String delete(Long id) {
|
|
|
|
+ articleRepository.deleteById(id);
|
|
|
|
+ return "success";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改test数据.
|
|
|
|
+ * @param article Test对象
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/update")
|
|
|
|
+ public String update(Article article) {
|
|
|
|
+ articleRepository.save(article);
|
|
|
|
+ return "success";
|
|
|
|
+ }
|
|
}
|
|
}
|