我想用spring框架向我的数据库发送一个对象。这是我在控制器中的代码:
@PostMapping("/createBarangByJson")
public ResponseEntity<?> createBarangByJson(@RequestBody RequestUser body)
{
Integer cDet = crudService.simpleCreateByJson(body);
return ResponseEntity.ok(cDet);
}
}
我已经为请求类创建了setter getter,下面是我在daoimpl中的代码:
@Override
public Integer simpleCreateByJson(RequestUser reqUser)
{
String sql = "INSERT INTO public.jualbeli(nama_barang, kuantitas, harga, tanggal, created_by) VALUES (?,?,?,?,?)";
Integer result = jdbcTemplate.update(sql, reqUser.getNama_barang(), Integer.parseInt(reqUser.getKuantitas()), Integer.parseInt(reqUser.getHarga()), reqUser.getTanggal(), reqUser.getCreated_by());
return result;
}
但当我发送数据时:
[
{
"nama_barang": "buku",
"kuantitas": "17",
"harga": "500000",
"tanggal": "2020-08-01",
"created_by": "adit"
}
]
错误是:
"timestamp": 1615207817069,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException"
有人知道怎么了吗?
1条答案
按热度按时间uubf1zoe1#
您正在发送一个json数组:
你得把
你也应该要求
而不是