package com.gansu.controller;
import com.gansu.pojo.Person;
import com.gansu.service.PersonReposity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/person")
public class PersonController {
@Autowired
PersonReposity personReposity;
@GetMapping("/getPersonName/{name}")
public Person getPersonName(@PathVariable("name") String name){
// return personReposity.getPersonName(name);
return personReposity.getPersonNameYuan(name);
}
@GetMapping("/findByNameContaining/{name}")
public List
findByNameContaining(@PathVariable("name") String name){
// List personList = personReposity.findByNameContaining(name);
List personList = personReposity.getPersonNameM(name);
return personList;
}
@GetMapping("/findPersonByNameAndAge/{name}/{age}")
public Person findPersonByNameAndAge(@PathVariable("name") String name,@PathVariable("age")Integer age){
return personReposity.findByNameAndAge(name,age);
}
@PostMapping("/addPerson")
public String addPerson(@RequestBody Person person){
personReposity.save(person);
return "addPerson-ok";
}
@GetMapping("/findPerson")
public List findPerson(){
return personReposity.findAll();
}
@GetMapping("/findPersonById/{id}")
public Optional findPersonById(@PathVariable("id") Long id){
return personReposity.findById(id);
}
@PutMapping("/updatePersonById/{id}")
public String updatePersonById(@PathVariable("id") Long id,@RequestBody Person person){
person.setId(id);
personReposity.saveAndFlush(person);
return "updatePersonById-ok";
}
@DeleteMapping("/deletePersonById/{id}")
public String deletePersonById(@PathVariable("id") Long id){
personReposity.deleteById(id);
return "deletePersonById-ok";
}
}