[英]How to fixed error 500 in postman from a post request?
我想知道是否有人对我从下面的 postman 得到的这个错误有任何见解:
{
"timestamp": "2022-12-29T07:59:00.313+0000",
"status": 500,
"error": "Internal Server Error",
"message": "could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement",
"path": "/v1/personal/add"
}
这是我的 Controller Class:
个人控制器.java
@PostMapping("/add")
public ResponseEntity <PersonalResponseDto> addPersonalInfo (@RequestBody final PersonalRequestDetailsDto personalRequestDetailsDto){
PersonalResponseDto dto = personalService.addPersonalInformation(personalRequestDetailsDto);
return ResponseEntity.ok(dto);
}
这是我的服务 Class:
个人服务.java
public PersonalResponseDto addPersonalInformation(PersonalRequestDetailsDto personalRequestDetailsDto){
PersonalEntity personalEntity = personalMapper.toEntity(personalRequestDetailsDto);
PersonalEntity saveInfo = personalRepository.save(personalEntity);
return personalMapper.toDto(saveInfo);
}
这是我的实体 class:
@Data
@ComponentScan("personal")
@NoArgsConstructor
@Table(name = "student_personal_information")
@Entity
public class PersonalEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", nullable = false)
private Long id;
@Column(name = "lastname", columnDefinition = "CLOB")
private String lastname;
@Column(name = "firstname", columnDefinition = "CLOB")
private String firstname;
@Column(name = "middleinitial")
private String middleinitial;
@Column(name = "age")
private Integer age;
@Column(name = "image")
private Byte image;
}
对于我在 postman 中出现上述错误的原因,我将不胜感激。
谢谢你。
我想添加一个将存储到数据库的信息,但出现错误。
这是我的请求 DTO:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PersonalRequestDetailsDto implements Serializable {
private static final long serialVersionUID = -7175623352146349491L;
@NotEmpty
private String lastname;
@NotNull
private String firstname;
@NotEmpty
private String middleinitial;
@NotNull
private Integer age;
}
附录:根据这里一位评论者的建议,我了解到这里的主要问题是我在图像栏下的实体。
这是我得到的错误:
column "image" is of type bytea but expression is of type smallint Hint: You will need to rewrite or cast the expression.
请问,我到底应该在我的实体中声明什么数据类型来解决这个问题?
理想情况下,在将文件上传到单独的图像存储后,您应该只在数据库中保存图像的路径。
使图像类型为字符串。
我通常将图像保存为文件并将详细信息保存在数据库中。 但是,如果您仍想将其保存在数据库中,则可以按如下方式更改:
@Lob
@Column(name = "image")
private byte[] image;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.