I am trying to implement this spring application that I got from Github. I am still in the learning process so this might be a basic question. what parameters do I need to pass in the postman body for this update user method? I wrote { "id":1,"password":"1234"} in the postman body but its showing me 400 bad syntax error.
public void updateUser(int id, String parameter, String update)
{
Session session=sessionFactory.openSession();
Transaction tx=session.beginTransaction();
//System.out.print(mail);
List<User_org> userList = userList();
for(User_org i: userList)
{
User_org u= i;
if(u.getId()==id)
{
if(parameter.equalsIgnoreCase("mail"))
{
u.setEmail(update);
session.update(u);
break;
}
if(parameter.equalsIgnoreCase("phone_no"))
{
u.setPhone_num(Integer.parseInt(update));
session.update(u);
break;
}
if(parameter.equalsIgnoreCase("password"))
{
u.setPassword(update);
session.update(u);
break;
}
}
}
session.flush();
tx.commit();
//return id;
}
In controller
public void updateUser(@RequestBody int id,String parameter, String updateToBe)
{
service.updateUser(id,parameter, updateToBe);
}
Create an Entity or DTO with all fields eg.
class User{
int id,
String parameter,
String updateToBe
// getters and setters
}
public void updateUser(@RequestBody User user)
{
service.updateUser(user);
}
From Postman send JSON object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.