我是新学员 有人可以帮助我吗..我遵循了本教程,但仍然收到错误。 我按照每个步骤给出了相同的文件名,变量仍然相同。我犯了什么错误无法克服
https://www.youtube.com/watch?v=YgkTXsqWvno&t=550s&ab_channel=JavaExpress
package com.example.demo.dto;
//import com.example.demo.model.Address;
//import com.example.demo.model.Credential;
//import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.*;
import lombok.*;
import java.io.Serializable;
import java.util.Set;
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Setter
@Getter
public class UserDto implements Serializable {
private static final long serialVersionUID = 1L;
private Integer userId;
private String firstName;
private String lastName;
private String email;
private String phone;
private Set<AddressDto> addressDtos;
@JsonProperty("credential")
@JsonInclude(value = JsonInclude.Include.NON_NULL)
private CredentialDatato credentialDto;
}
package com.example.demo.helper;
import com.example.demo.dto.UserDto;
import com.example.demo.model.Credential;
import com.example.demo.model.User;
import org.springframework.beans.BeanUtils;
//import com.example.demo.model.User;
public interface UserMappingHelper {
public static UserDto map(User user) {
return null;
}
public static User map(UserDto userDto) {
if(userDto == null)
{
return null;
}
User user = new User();
BeanUtils.copyProperties(userDto,user);
if(userDto.getCredentialDto() != null)
{
Credential credential = new Credential();
BeanUtils.copyProperties(userDto.getCredentialDto(),credential);
credential.setUser(user);
user.setCredential(credential);
}
return user;
}
}
这是输出。
C:\Users\User\Downloads\Spring_microservice\demo\src\main\java\com\example\demo\helper\UserMappingHelper.java:23:23
java: cannot find symbol
symbol: method getCredentialDto()
location: variable userDto of type com.example.demo.dto.UserDto
“Java:找不到符号”错误是编译错误。经过研究,我发现正是这一行导致了错误: public static UserDto map(User user) { 返回空值; }。这可能是因为你如何定义它。即使在其他语言中,这样做也可能会出现问题。如果问题仍然存在,请评论,我会再试一次。 干杯。