zoukankan      html  css  js  c++  java
  • Spring Boot 进阶之Web进阶 学习

    Girl.java中  限制年龄小于18岁
    @Entity
    public class Girl {
    @Id
    @GeneratedValue
    private Integer id;
    private String cupSize;
    @Min(value = 18,message = "未成年少女禁止入内")
    private Integer age;

    public Girl() {
    }

    public Integer getId() {
    return id;
    }

    public void setId(Integer id) {
    this.id = id;
    }

    public String getCupSize() {
    return cupSize;
    }

    public void setCupSize(String cupSize) {
    this.cupSize = cupSize;
    }

    public Integer getAge() {
    return age;
    }

    public void setAge(Integer age) {
    this.age = age;
    }
    }

    在GirlController.java中
       /*
    * 添加一个女生
    * @date 2018/4/20 下午5:44
    * @param [cupSize, age]
    * @return com.example.girl.Girl
    */
    @PostMapping(value = "/add")
    public Girl girlAdd(@Valid Girl girl, BindingResult bindingResult){
    if(bindingResult.hasErrors()){
    System.out.print(bindingResult.getFieldError().getDefaultMessage());
    return null;
    }
    // Girl girl = new Girl();
    girl.setCupSize(girl.getCupSize());
    girl.setAge(girl.getAge());

    return girlReposistory.save(girl);
    }
  • 相关阅读:
    nyist 541最强DE 战斗力
    nyist 231 Apple Tree
    nyist 543 遥 控 器
    nyist 233 Sort it
    nyist 517 最小公倍数
    hdu 1sting
    nyist A+B Problem IV
    nyist 522 Interval
    nyist 117 求逆序数
    nyist 600 花儿朵朵
  • 原文地址:https://www.cnblogs.com/zhcnblog/p/8944231.html
Copyright © 2011-2022 走看看