English 中文(简体)
专利类型没有定义。
原标题:The method getType() is undefined for the type Ingredient
package tacos.web;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import java.lang.reflect.Field;
import lombok.extern.slf4j.Slf4j;
import tacos.Ingredient;
import tacos.Ingredient.Type;
import tacos.Taco;

@Slf4j
@Controller
@RequestMapping("/design")
@SessionAttributes("tacoOrder")
public class DesignTacoController {

@ModelAttribute
public void addIngredientsToModel(Model model) {
        List<Ingredient> ingredients = Arrays.asList(
          new Ingredient("FLTO", "Flour Tortilla", Type.WRAP),
          new Ingredient("COTO", "Corn Tortilla", Type.WRAP),
          new Ingredient("GRBF", "Ground Beef", Type.PROTEIN),
          new Ingredient("CARN", "Carnitas", Type.PROTEIN),
          new Ingredient("TMTO", "Diced Tomatoes", Type.VEGGIES),
          new Ingredient("LETC", "Lettuce", Type.VEGGIES),
          new Ingredient("CHED", "Cheddar", Type.CHEESE),
          new Ingredient("JACK", "Monterrey Jack", Type.CHEESE),
          new Ingredient("SLSA", "Salsa", Type.SAUCE),
          new Ingredient("SRCR", "Sour Cream", Type.SAUCE)
        );

        Type[] types = Ingredient.Type.values();
        for (Type type : types) {
          model.addAttribute(type.toString().toLowerCase(),
              filterByType(ingredients, type));
        }
}
  @GetMapping
  public String showDesignForm(Model model) {
    model.addAttribute("taco", new Taco());
    return "design";
  }

  private Iterable<Ingredient> filterByType(
      List<Ingredient> ingredients, Type type) {
    return ingredients
              .stream()
              .filter(x -> x.getType().equals(type))
              .collect(Collectors.toList());
  }

}

我正在通过《春季》第6版行动。 在过滤ByType方法中,P.getType()显示了错误。

The method getType() is undefined for the type Ingredient

我认为这是因Lombok造成的错误,但我也安装了这个错误。 我还进口了包裹。 外地,但仍有错误。

package tacos;

import lombok.Data;


@Data
public class Ingredient {
 public Ingredient(String string, String string2, Type wrap) {
        // TODO Auto-generated constructor stub
    }

private final String id = "";
 private final String name = "";
 private final Type type = null;
 
 public  enum Type {
     WRAP, PROTEIN, VEGGIES, CHEESE, SAUCE
 }
}

上述班级为非专利班级。

最佳回答

Seems You are not the first person who face with this issue https://coderanch.com/t/730026/java/lombok

In addIngredientsToModel of class DesignTacoController the flagged error is "The constructor Ingredient(String, String, Ingredient.Type) is undefined". Also, in method filterByType the flagged error is "The method getType() is undefined for the type Ingredient". It zappears that lombok is just not working. But I have lombok in the pom:

答复:

Just adding Lombok as a dependency does not make Eclipse recognize it, you ll need a plugin for that. See https://www.baeldung.com/lombok-ide for instructions on installing Lombok into Eclipse (and IntelliJ for those who prefer it).

问题回答

It is not problem of lombok. It is because there is no getType() function in Ingredient class. Add getType() funtion will fix the problem.

public class Ingredient {
  
  private final String id;
  private final String name;
  private final Type type;
  
  public Ingredient(String id, String name, Type type) {
        this.id = id;
        this.name = name;
        this.type = type;
      }
  
  public enum Type {
    WRAP, PROTEIN, VEGGIES, CHEESE, SAUCE
  }
  
  *public Type getType() {
      return this.type;
  }*

}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签