簡體   English   中英

如何在郵遞員中為此特定方法傳遞請求參數?

[英]How to pass request parameters in the postman for this particular method?

我正在嘗試實現我從 Github 獲得的這個 spring 應用程序。 我仍在學習過程中,所以這可能是一個基本問題。 對於此更新用戶方法,我需要在郵遞員正文中傳遞哪些參數? 我在郵遞員正文中寫了 { "id":1,"password":"1234"} 但它顯示了 400 個錯誤的語法錯誤。

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;
    }

在控制器中

public void updateUser(@RequestBody int id,String parameter, String updateToBe)
    {

        service.updateUser(id,parameter, updateToBe);
        
    }
    

創建一個包含所有字段的實體或 DTO,例如。

class User{
int id,
String parameter, 
String updateToBe

// getters and setters

}


public void updateUser(@RequestBody User user)
    {

        service.updateUser(user);
        
    }

從 Postman 發送 JSON 對象

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM