Spring boot使用save()方法執(zhí)行更新時,沒有指定的字段在數(shù)據(jù)庫顯示為null,什么原因,請指教@PutMapping(value?=?"/stu/{id}")
public?Student?stuUpdate(@PathVariable("id")?Integer?id,
?????????????????????????@RequestParam("name")?String?name,
?????????????????????????@RequestParam("age")?Integer?age)?{
????Student?student?=?new?Student();
????student.setId(id);
????student.setName(name);
????student.setAge(age);
????return?stuRepository.save(student);
}@Id
@GeneratedValue
private?Integer?id;
private?String?name;
private?Integer?age;
private?String?size;
1 回答

cxxyjsj
TA貢獻(xiàn)119條經(jīng)驗 獲得超22個贊
save時沒有給size賦值,導(dǎo)致把數(shù)據(jù)庫值更新為null。
可以先根據(jù)id獲取到Student對象,然后把name,age設(shè)置到這個對象中,然后再調(diào)用save方法
添加回答
舉報
0/150
提交
取消