-
http://127.0.0.1:8081/girls/5 delete 方式 通过id删除一个女生查看全部
-
http://127.0.0.1:8081/girls/5 put 方式 通过id 修改一个女生信息 注意的是:form-urllencoded查看全部
-
http://127.0.0.1:8081/girls/5 get 请求 通过id来查询一个女生查看全部
-
http://127.0.0.1:8081/girls post key cupSize value F key age value 18查看全部
-
http://127.0.0.1:8081/girls 查询所有女生列表查看全部
-
阿里云maven查看全部
-
application.yml文件 spring: profiles: active: prod jpa: hibernate: ddl-auto: update show-sql: true datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/xdl username: root password: 123456查看全部
-
@RestController @RequestMapping("/hello") public class HelloController { @Autowired private GirlProperties girlProperties; //@RequestMapping(value = "/say",method = RequestMethod.GET) @GetMapping(value = "/say") public String say(@RequestParam(value = "id",required = false,defaultValue = "0") Integer myid){ return "id:"+myid; // return girlProperties.getCupSize(); } }查看全部
-
public interface GirlRepository extends JpaRepository<Girl,Integer> { //通过年龄来查询 public List<Girl> findByAge(Integer age); }查看全部
-
@Service public class GirlService { @Autowired private GirlRepository girlRepository; @Transactional public void insertTwo(){ Girl girlA = new Girl(); girlA.setCupSize("A"); girlA.setAge(18); girlRepository.save(girlA); Girl girlB = new Girl(); girlB.setCupSize("B"); girlB.setAge(19); girlRepository.save(girlB); } }查看全部
-
//更新 @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); } //删除 @DeleteMapping(value = "/girls/{id}") public void girlDelete(@PathVariable("id") Integer id){ girlRepository.delete(id); } //通过年龄来查询 女生列表 @GetMapping(value = "/girls/age/{age}") public List<Girl> girlListByAge(@PathVariable("age") Integer age){ return girlRepository.findByAge(age); } @PostMapping(value = "/girls/two") public void girlTwo(){ girlService.insertTwo(); }查看全部
-
@RestController public class GirlController { @Autowired private GirlRepository girlRepository; @Autowired private GirlService girlService; /** * 查询所有女生列表 * @return */ @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); }查看全部
-
@Service public class GirlService { @Autowired private GirlRepository girlRepository; @Transactional public void insertTwo(){ Girl girlA = new Girl(); girlA.setCupSize("A"); girlA.setAge(18); girlRepository.save(girlA); Girl girlB = new Girl(); girlB.setCupSize("B"); girlB.setAge(19); girlRepository.save(girlB); } }查看全部
-
spring boot controller 注解 @Controller @ResponseBody @RestController @RequestMapping查看全部
-
实体类初始化属性注入时,需要添加两个注解 @Component @ConfigurationProperties(prefix = "girl")查看全部
举报
0/150
提交
取消