赞
踩
完成了获取历史会议列表的接口,并对数据库的表项进行了熟悉
对SpringBoot的增删改查进行了学习,并进行了相应的实践
- package com.jxust.sspringbootdemo.controller;
-
-
-
- import com.jxust.sspringbootdemo.dao.PersonRepository;
- import com.jxust.sspringbootdemo.entity.Person;
- import com.jxust.sspringbootdemo.service.PersonService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
-
- import java.util.List;
-
-
- @RestController
- public class PersonController {
- @Autowired
- PersonRepository personRepository;
- @Autowired
- private PersonService personService;
- @GetMapping(value = "/person")
- private List<Person> personList() {
-
- return personRepository.findAll();
- }
-
- @PostMapping(value = "/person")
- public Person personAdd(@RequestParam("name") String name,@RequestParam("age") Integer age) {
- Person person = new Person();
- person.setName(name);
- person.setAge(age);
-
- return personRepository.save(person);
- }
-
- @GetMapping(value = "/person/{id}")
- public Person personFindOne(@PathVariable("id") Integer id) {
- return personRepository.findById(id).orElse(null);
- }
-
- // @DeleteMapping(value = "/person/{id}")
- // public void personDelete(@PathVariable("id") Integer id) {
- // personRepository.delete(id);
- // }
-
- @PutMapping(value = "/person/{id}")
- public Person personUpdate(@PathVariable("id") Integer id,
- @RequestParam("name") String name,
- @RequestParam("age") Integer age) {
- Person person = new Person();
- person.setId(id);
- person.setName(name);
- person.setAge(age);
- return personRepository.save(person);
- }
-
- @GetMapping(value = "/person/age/{age}")
- public List<Person> personListByAge(@PathVariable("age") Integer age) {
- return personRepository.findByAge(age);
- }
-
- @PostMapping("/person/two")
- public void personTwo() {
- personService.insertTwo();
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。