笔记和代码
你好,请问有课堂笔记和代码吗??
你好,请问有课堂笔记和代码吗??
2018-05-28
package com.imooc; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController public class GirlController { @Autowired private GirlRepository girlRepository; /* * 查询所有女生列表 * */ @GetMapping(value = "/girls") public List<Girl> girlList() { return girlRepository.findAll(); } /** * 添加女生 * * @param cupSize * @param age * @return */ @PostMapping(value = "/girls") public Girl girlAdd(@RequestParam("cupSize") String cupSize, @RequestParam("age") Integer age) { Girl girl = new Girl(); girl.setCupSize(cupSize); girl.setAge(age); return girlRepository.save(girl); } /** * 查询一个女生 * * @param id * @return */ @PostMapping(value = "/girls/{id}") public Girl girlFindOne(@PathVariable("id") Integer id) { return girlRepository.findOne(id); } //更新一个女生 @PutMapping(value = "/girls/{id}") public Girl girlUpdate(@PathVariable("id") Integer id, @RequestParam("cupSize") String cupSize, @RequestParam("age") Integer age) { Girl girl = new Girl(); girl.setId(id); girl.setCupSize(cupSize); girl.setAge(age); return girlRepository.save(girl); } /** * 删除一个女生 * @param id */ @DeleteMapping(value = "/girls/{id}") public void girlUpdate(@PathVariable("id") Integer id) { girlRepository.delete(id); } //通过年龄查询女生列表 @PostMapping(value = "/girls/age/{age}") public List<Girl> girlListByAge(@PathVariable("age") Integer age){ return girlRepository.findByAge(age); } }
举报