Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter3 save taco get a errot #120

Open
ljygod opened this issue Sep 2, 2022 · 1 comment
Open

Chapter3 save taco get a errot #120

ljygod opened this issue Sep 2, 2022 · 1 comment

Comments

@ljygod
Copy link

ljygod commented Sep 2, 2022

when i insert taco to table,get this error
java.lang.IllegalArgumentException: Can not set java.lang.String field com.example.tacocloud.domain.Ingredient.id to java.lang.String

@javaswing
Copy link

@ljygod
You need create the Class, in web package

/**
 * 根据ID转换为对象
 */
@Component
public class IngredientByIdConverter implements Converter<String, Ingredient> {
    private IngredientRepository ingredientRepo;

    @Autowired
    public IngredientByIdConverter(IngredientRepository ingredientRepo) {
        this.ingredientRepo = ingredientRepo;
    }

    @Override
    public Ingredient convert(String id) {
        return ingredientRepo.findById(id);
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants