Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SetCarolie在狗模型中不能应用于()?我做错了什么?_Java_Spring - Fatal编程技术网

Java SetCarolie在狗模型中不能应用于()?我做错了什么?

Java SetCarolie在狗模型中不能应用于()?我做错了什么?,java,spring,Java,Spring,我正在用Java为一个Dog diet应用程序构建后端,在ServiceImplementation中,我试图保存一只新的狗。我有一个狗的模型,它与热量有一对多的关系。卡路里模型有10磅20磅30磅到100磅的狗的字段,热量将根据体重而变化 我和狗有一个多对一的卡路里关系,它是一个数组列表,所以我在列表上循环,然后我做基于狗==特定体重的if语句,然后尝试setcarries().gettenlb()等,Intellij出于某种原因不喜欢它,并给我错误setcalorie无法应用于() 我不知道

我正在用Java为一个Dog diet应用程序构建后端,在ServiceImplementation中,我试图保存一只新的
狗。我有一个狗的模型,它与热量有一对多的关系。卡路里模型有10磅20磅30磅到100磅的狗的字段,热量将根据体重而变化

我和狗有一个多对一的卡路里关系,它是一个数组列表,所以我在列表上循环,然后我做基于狗==特定体重的if语句,然后尝试
setcarries().gettenlb()
等,Intellij出于某种原因不喜欢它,并给我错误
setcalorie
无法应用于()

我不知道发生了什么事


    @Entity
    @Table(name = "dogs")
    public class Dog {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private long dogid;
    
        private int weight;
    
        private String name;
    
        @OneToOne(mappedBy = "dog", cascade = CascadeType.ALL, orphanRemoval = true)
        @PrimaryKeyJoinColumn
        private Fat fat;
    
        @OneToMany(mappedBy = "dog", cascade = CascadeType.ALL, orphanRemoval = true)
        @JsonIgnoreProperties(value = "dog",allowSetters = true)
        private List<Calorie> calorie = new ArrayList<>();
    
        @OneToOne(mappedBy = "dog",cascade = CascadeType.ALL,orphanRemoval = true)
        @PrimaryKeyJoinColumn
        private Vegetable vegetable;
    
        @OneToOne(mappedBy = "dog",cascade = CascadeType.ALL,orphanRemoval = true)
        @PrimaryKeyJoinColumn
        private Protein protein;
    
        @OneToMany(mappedBy = "dog",cascade = CascadeType.ALL,orphanRemoval = true)
        @JsonIgnoreProperties(value="dog",allowSetters = true)
        private List<Mineral> minerals = new ArrayList<>();
    
        @OneToMany(mappedBy = "dog", cascade = CascadeType.ALL,orphanRemoval = true)
        @JsonIgnoreProperties(value = "dog",allowSetters = true)
        private List<Vitamin>vitamins = new ArrayList<>();
    
        @OneToMany(mappedBy = "dog",cascade = CascadeType.ALL,orphanRemoval = true)
        @JsonIgnoreProperties(value = "dog",allowSetters = true)
        private List<AminoAcid> aminoacids = new ArrayList<>();
    
        @OneToMany(mappedBy = "dog",cascade = CascadeType.ALL,orphanRemoval = true)
        @JsonIgnoreProperties(value = "dog",allowSetters = true)
        private List<FattyAcid> fattyacids = new ArrayList<>();
    
    
        public Dog() {
        }
    
        public Dog(int weight, String name, Fat fat, Calorie calorie, Vegetable vegetable, Protein protein) {
            this.weight = weight;
            this.name = name;
            this.fat = fat;
            this.vegetable = vegetable;
            this.protein = protein;
        }
    
        public Long getDogid() {
            return dogid;
        }
    
        public void setDogid(Long dogid) {
            this.dogid = dogid;
        }
    
        public int getWeight() {
            return weight;
        }
    
        public void setWeight(int weight) {
            this.weight = weight;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public Fat getFat() {
            return fat;
        }
    
        public void setFat(Fat fat) {
            this.fat = fat;
        }
    
        public void setDogid(long dogid) {
            this.dogid = dogid;
        }
    
      
    
        public Vegetable getVegetable() {
            return vegetable;
        }
    
        public void setVegetable(Vegetable vegetable) {
            this.vegetable = vegetable;
        }
    
        public Protein getProtein() {
            return protein;
        }
    
        public void setProtein(Protein protein) {
            this.protein = protein;
        }
    
        public List<Mineral> getMinerals() {
            return minerals;
        }
    
        public void setMinerals(List<Mineral> minerals) {
            this.minerals = minerals;
        }
    
        public List<Vitamin> getVitamins() {
            return vitamins;
        }
    
        public void setVitamins(List<Vitamin> vitamins) {
            this.vitamins = vitamins;
        }
    
        public List<AminoAcid> getAminoacids() {
            return aminoacids;
        }
    
        public void setAminoacids(List<AminoAcid> aminoacids) {
            this.aminoacids = aminoacids;
        }
    
        public List<FattyAcid> getFattyacids() {
            return fattyacids;
        }
    
        public void setFattyacids(List<FattyAcid> fattyacids) {
            this.fattyacids = fattyacids;
        }
    
        public List<Calorie> getCalorie() {
            return calorie;
        }
    
        public void setCalorie(List<Calorie> calorie) {
            this.calorie = calorie;
        }
    
    }
    
    ```
    @Entity
    @Table(name = "calories")
    public class Calorie {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private long id;
        private String tenlb;
    
        private String twentylb;
        private String thirtylb;
        private String fortylb;
        private String fiftylb;
        private String sixtylb;
        private String seventylb;
        private String eightylb;
        private String ninetylb;
        private String hundredlb;
    
        @ManyToOne()
        @JoinColumn(name = "dogid",nullable = false)
        @JsonIgnoreProperties(value = "calories",allowSetters = true)
        private Dog dog;
    
        public Calorie() {
        }
    
        public Calorie(String tenlb, String twentylb, String thirtylb, String fortylb, String fiftylb, String sixtylb, String seventylb, String eightylb, String ninetylb, String hundredlb, Dog dog) {
            this.tenlb = tenlb;
            this.twentylb = twentylb;
            this.thirtylb = thirtylb;
            this.fortylb = fortylb;
            this.fiftylb = fiftylb;
            this.sixtylb = sixtylb;
            this.seventylb = seventylb;
            this.eightylb = eightylb;
            this.ninetylb = ninetylb;
            this.hundredlb = hundredlb;
            this.dog = dog;
        }
    
        public long getId() {
            return id;
        }
    
        public void setId(long id) {
            this.id = id;
        }
    
        public String getTenlb() {
            return tenlb;
        }
    
        public void setTenlb(String tenlb) {
            this.tenlb = tenlb;
        }
    
        public String getTwentylb() {
            return twentylb;
        }
    
        public void setTwentylb(String twentylb) {
            this.twentylb = twentylb;
        }
    
        public String getThirtylb() {
            return thirtylb;
        }
    
        public void setThirtylb(String thirtylb) {
            this.thirtylb = thirtylb;
        }
    
        public String getFortylb() {
            return fortylb;
        }
    
        public void setFortylb(String fortylb) {
            this.fortylb = fortylb;
        }
    
        public String getFiftylb() {
            return fiftylb;
        }
    
        public void setFiftylb(String fiftylb) {
            this.fiftylb = fiftylb;
        }
    
        public String getSixtylb() {
            return sixtylb;
        }
    
        public void setSixtylb(String sixtylb) {
            this.sixtylb = sixtylb;
        }
    
        public String getSeventylb() {
            return seventylb;
        }
    
        public void setSeventylb(String seventylb) {
            this.seventylb = seventylb;
        }
    
        public String getEightylb() {
            return eightylb;
        }
    
        public void setEightylb(String eightylb) {
            this.eightylb = eightylb;
        }
    
        public String getNinetylb() {
            return ninetylb;
        }
    
        public void setNinetylb(String ninetylb) {
            this.ninetylb = ninetylb;
        }
    
        public String getHundredlb() {
            return hundredlb;
        }
    
        public void setHundredlb(String hundredlb) {
            this.hundredlb = hundredlb;
        }
    
        public Dog getDog() {
            return dog;
        }
    
        public void setDog(Dog dog) {
            this.dog = dog;
        }
    ```  public Dog save(Dog dog) {
            Dog newDog = new Dog();
            if (dog.getDogid() != 0) {
                dogrepos.findById(dog.getDogid())
                        .orElseThrow(() -> new ResourceNotFoundException("Dog Id" + dog.getDogid() + "not found"));
                newDog.setDogid(dog.getDogid());
            }
            newDog.setName(dog.getName());
            newDog.setWeight(dog.getWeight());
            newDog.setFat(dog.getFat());
            newDog.setProtein(dog.getProtein());
            newDog.setVegetable(dog.getVegetable());
    
            newDog.getAminoacids().clear();
            for (AminoAcid a : dog.getAminoacids()) {
                newDog.getAminoacids()
                        .add(new AminoAcid(a.getArginine(),
                                a.getHistidine(),
                                a.getIsoleucine(),
                                a.getLysine(),
                                a.getMethcysteine(),
                                a.getMethionine(),
                                a.getPhenaltyrosine(),
                                a.getThreonine(),
                                a.getTryptophan(),
                                a.getValine(),
                                a.getLeucine(), newDog));
            }
    
            for (Calorie c : dog.getCalorie()) {
                if (dog.getWeight() == 10) {
                    newDog.setCalorie().getTenlb();
    
                }
                if (newDog.getWeight() == 20) {
                    newDog.setCalorie().getTwentylb();
    
                }
                if (newDog.getWeight() == 30) {
                    newDog.getCalorie()
    
                }
                if (newDog.getWeight() == 40) {
                    newDog.setCalorie(getFortylb());
                }
            }
            if (newDog.getWeight() == 50) {
                newDog.setCalorie().getFiftylb();
            }
            if (newDog.getWeight() == 60) {
                newDog.setCalorie().getSixtylb();
            }
            if (newDog.getWeight() == 70) {
                newDog.setCalorie().getSeventylb();
            }
            if (newDog.getWeight() == 80) {
                newDog.setCalorie().getEightylb();
            }
            if (newDog.getWeight() == 90) {
                newDog.setCalorie().getNinetylb()
            } if (newDog.getWeight() == 100) {
                newDog.setCalorie().getHundredlb();
            }


@实体
@表(name=“dogs”)
公家犬{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私人长狗;
私有整数权重;
私有字符串名称;
@OneTONE(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@PrimaryKeyJoinColumn
私人脂肪;
@OneToMany(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@JsonIgnoreProperties(value=“dog”,allowSetters=true)
私有列表卡路里=新ArrayList();
@OneTONE(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@PrimaryKeyJoinColumn
私人蔬菜;
@OneTONE(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@PrimaryKeyJoinColumn
私有蛋白;
@OneToMany(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@JsonIgnoreProperties(value=“dog”,allowSetters=true)
私有列表矿物=新ArrayList();
@OneToMany(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@JsonIgnoreProperties(value=“dog”,allowSetters=true)
private list=new ArrayList();
@OneToMany(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@JsonIgnoreProperties(value=“dog”,allowSetters=true)
私有列表氨基酸=新ArrayList();
@OneToMany(mappedBy=“dog”,cascade=CascadeType.ALL,orphan=true)
@JsonIgnoreProperties(value=“dog”,allowSetters=true)
私有列表fattyacids=newarraylist();
公犬(){
}
公犬(体重、品名、脂肪、卡路里、蔬菜、蛋白质){
重量=重量;
this.name=名称;
这个。脂肪=脂肪;
这个。蔬菜=蔬菜;
这个。蛋白质=蛋白质;
}
公共长getDogid(){
返回道;
}
公共无效setDogid(长dogid){
this.dogid=dogid;
}
公共整数getWeight(){
返回重量;
}
公共空隙设定重量(内部重量){
重量=重量;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共脂肪{
返回脂肪;
}
公共无效setFat(Fat){
这个。脂肪=脂肪;
}
公共无效setDogid(长dogid){
this.dogid=dogid;
}
公共蔬菜{
还菜;
}
公共蔬菜(蔬菜){
这个。蔬菜=蔬菜;
}
公共蛋白质{
返回蛋白;
}
公共空间蛋白质(蛋白质){
这个。蛋白质=蛋白质;
}
公开名单{
返回矿物;
}
公共矿物(列出矿物){
矿物=矿物;
}
公共列表{
返回维生素;
}
公共维生素(列出维生素){
维生素=维生素;
}
公开列表获取氨基酸(){
返回氨基酸;
}
公共氨基酸(列出氨基酸){
这是。氨基酸=氨基酸;
}
公共列表getFattyacids(){
返回脂肪酸;
}
公共无效设置FATTYACID(列表FATTYACID){
this.fattyacids=fattyacids;
}
公共列表getCalorie(){
返回热量;
}
公共空间设置卡路里(列出卡路里){
这个。卡路里=卡路里;
}
}
```
@实体
@表(name=“卡路里”)
公共级卡路里{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私人长id;
私有字符串十磅;
私人字符串20磅;
私人字符串三十磅;
私有字符串fortylb;
私有字符串fiftylb;
私有字符串六十磅;
私有字符串七元b;
私人字符串八磅;
私有字符串ninetylb;
私有字符串百分位;
@ManyToOne()
@JoinColumn(name=“dogid”,nullable=false)
@JsonIgnoreProperties(value=“carries”,allowSetters=true)
私家狗;
公共卡路里(){
}
公共卡路里(十磅、二十磅、三十磅、四十磅、五十磅、六十磅、七十磅、八十磅、九十磅、一百磅、狗狗){
这个。十磅=十磅;
this.twentylb=twentylb;
this.thirtylb=thirtylb;
this.fortylb=fortylb;
这个。fif