packagecom.cy.coo.li;importjava.util.List;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.DeleteMapping;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.PostMapping;importorg.springframework.web.bind.annotation.PutMapping;importorg.springframework.web.bind.annotation.RequestParam;importorg.springframework.web.bind.annotation.RestController;
@RestControllerpublic classManContent {
@AutowiredprivatemanInterface manl;
@AutowiredprivatemanService mans;/** 查询所有人的数据*/@GetMapping(value= "/man")/** List指的是集合.<>是泛型,里面指定了这个集合中存放的是什么数据. List代表把Man类中的信息的对象都在里面了*/
public Listmanlist() {returnmanl.findAll();
}/** 添加*/@PostMapping(value= "/man")//@RequestParam获取参数
/** 因为save返回的时添加进去的对象,所以返回类型就是这个对象*/
public Man manAdd(@RequestParam("cupSize") String cupSize, @RequestParam("age") Integer age) {
Man man= newMan();
man.setCupSize(cupSize);
man.setAge(age);returnmanl.save(man);
}//查询
@GetMapping(value = "/man/{id}")//因为
public Man manFindOne(@PathVariable("id") Integer id) {
System.out.println(id);returnmanl.findOne(id);
}//更新
@PutMapping(value="/man{id}")public Man manUpdata(@RequestParam(value = "id") Integer id,
@RequestParam("cupSize") String cupSize, @RequestParam("age") Integer age){
Man manll=newMan();
manll.setId(id);
manll.setAge(age);
manll.setCupSize(cupSize);returnmanl.save(manll);
}//删除
@DeleteMapping(value="/man{id}")public void manDelete(@RequestParam("id") Integer id){//因为delete的返回值为null所以就是没得1返回值
manl.delete(id);
}//通过年龄查询
@GetMapping(value="/man/age/{age}")public List manListAge(@PathVariable("age") Integer age){returnmanl.findByAge(age);
}
@PostMapping(value="/man/two")public voidmanTwo(){
mans.InsertTwo();
}
}