我有一个控制器,在其中定义了PostMapping方法来创建新广告,如下所示:
apiService.createPatient
当我尝试使用像这样的邮递员上的原始请求时:
.286
.model small
.stack 100h
writeString macro string, length, x, y, color
mov ah, 13h
mov al, 0
mov bh, 0
mov bl, color
lea bp, string
mov cx, length
mov dl, x
mov dh, y
int 10h
endm
draw_box_outline macro x_fin,y_fin,x_ini,y_ini
local col_draw,row_draw,row_rev,col_rev
mov cx,x_ini
mov dx,y_ini
mov ah,0ch
mov al,1111b
int 10h
col_draw:
inc cx
int 10h
cmp cx,x_fin
jb col_draw
row_draw:
inc dx
int 10h
cmp dx,y_fin
jb row_draw
row_rev:
dec cx
int 10h
cmp cx,x_ini
ja row_rev
col_rev:
dec dx
int 10h
cmp dx,y_ini
ja col_rev
endm
.data
msg db "Select Number of Player/s$"
msg1 db "1$"
;box parameters
b1_col_ini equ 50
b1_row_ini equ 110
b1_col_fin equ 90
b1_row_fin equ 150
b2_col_ini equ 130
b2_row_ini equ 110
b2_col_fin equ 170
b2_row_fin equ 150
b3_col_ini equ 210
b3_row_ini equ 110
b3_col_fin equ 250
b3_row_fin equ 150
.code
org 100h
main proc far
mov ax,@data
mov ds,ax
mov es,ax
mov ah,0h
mov al,13h
mov bh,0
int 10h
writeString msg,25,7,10,1111b
draw_box_outline b1_col_fin,b1_row_fin,b1_col_ini,b1_row_ini
draw_box_outline b2_col_fin,b2_row_fin,b2_col_ini,b2_row_ini
draw_box_outline b3_col_fin,b3_row_fin,b3_col_ini,b3_row_ini
writeString msg,25,7,10,1111b
;implement cursor press and detection
;implement cursor hide
mov ax,4c00h
int 21h
main endp
end main
我收到以下响应:创建用户实例存在问题:
@PostMapping
public ResponseEntity<?> registerAd(@RequestBody DonationAd ad){
repository.save(ad);
return ResponseEntity.accepted().body(new ApiResponse(true,"sucess"));
}
知道同样的方法也可以使用postMan完美地处理表单数据
这是用户类:
{
"title":"lalal",
"description":"lalallalalal",
"user":2,
"images":[8,17],
"state":"BAD",
"adress":"textextextetextetxt"
}
这是扩展抽象类Advertisement的DoantionAd:
{
"timestamp": "2018-12-27T14:51:30.465+0000",
"status": 400,
"error": "Bad Request",
"message": "JSON parse error: Cannot construct instance of `com.betroc.model.User` (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (2); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.betroc.model.User` (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (2)\n at [Source: (PushbackInputStream); line: 4, column: 8] (through reference chain: com.betroc.model.DonationAd[\"user\"])",
"path": "/api/donationAds"}
然后进行修饰:
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
@Size(max = 40)
private String name;
@NotBlank
@Size(max = 15)
private String username;
@NaturalId
@NotBlank
@Size(max = 40)
@Email
private String email;
@JsonIgnore
@NotBlank
@Size(max = 100)
private String password;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "user_roles",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
private Set<Role> roles = new HashSet<>();
private boolean enabled;
public User() {
}
public User(String name, String username, String email, String password) {
this.name = name;
this.username = username;
this.password = password;
this.email = email;
this.enabled = false;
}
//getters ans setters
}
答案 0 :(得分:0)
如果您尝试使用此json:
{
"title":"lalal",
"description":"lalallalalal",
"user":{
"id":2
},
"state":"BAD",
"address":"textextextetextetxt"
}
您可以在其中添加其他属性