当前位置:   article > 正文

2021暑期项目实训(三)_import com.jxust.cn标红

import com.jxust.cn标红

1、编写接口

          完成了获取历史会议列表的接口,并对数据库的表项进行了熟悉

2、熟悉SpringBoot

         对SpringBoot的增删改查进行了学习,并进行了相应的实践

  1. package com.jxust.sspringbootdemo.controller;
  2. import com.jxust.sspringbootdemo.dao.PersonRepository;
  3. import com.jxust.sspringbootdemo.entity.Person;
  4. import com.jxust.sspringbootdemo.service.PersonService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.*;
  7. import java.util.List;
  8. @RestController
  9. public class PersonController {
  10. @Autowired
  11. PersonRepository personRepository;
  12. @Autowired
  13. private PersonService personService;
  14. @GetMapping(value = "/person")
  15. private List<Person> personList() {
  16. return personRepository.findAll();
  17. }
  18. @PostMapping(value = "/person")
  19. public Person personAdd(@RequestParam("name") String name,@RequestParam("age") Integer age) {
  20. Person person = new Person();
  21. person.setName(name);
  22. person.setAge(age);
  23. return personRepository.save(person);
  24. }
  25. @GetMapping(value = "/person/{id}")
  26. public Person personFindOne(@PathVariable("id") Integer id) {
  27. return personRepository.findById(id).orElse(null);
  28. }
  29. // @DeleteMapping(value = "/person/{id}")
  30. // public void personDelete(@PathVariable("id") Integer id) {
  31. // personRepository.delete(id);
  32. // }
  33. @PutMapping(value = "/person/{id}")
  34. public Person personUpdate(@PathVariable("id") Integer id,
  35. @RequestParam("name") String name,
  36. @RequestParam("age") Integer age) {
  37. Person person = new Person();
  38. person.setId(id);
  39. person.setName(name);
  40. person.setAge(age);
  41. return personRepository.save(person);
  42. }
  43. @GetMapping(value = "/person/age/{age}")
  44. public List<Person> personListByAge(@PathVariable("age") Integer age) {
  45. return personRepository.findByAge(age);
  46. }
  47. @PostMapping("/person/two")
  48. public void personTwo() {
  49. personService.insertTwo();
  50. }
  51. }

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/847320
推荐阅读
相关标签
  

闽ICP备14008679号