0

I was making a rest call to Spring Controller, it failed to got through with BAD request (400 cause , original question Spring Controller 400 (Bad Request))

My Initial rest call parameters were:

categoty: "Game"
itemDescription: "adas"
itemDiscount: 1
itemName: "asdas"
itemPrice: 1
itemQuantity: 1

This failed , but when I changed the parameters as below , it worked:

categoty: "Game"
description: "test1"
discount: 10
name: "Test"
price: 10
quantity: 10

My Persistence POJO class was :

import javax.persistence.*;  

@Entity  
@Table(name= "Item")
public class Item {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="id")
    private int id; 
    private String itemName,itemDescription,categoty;   
    private double itemPrice;
    private float itemDiscount;
    private int itemQuantity;


    public int getId() {  
        return id;  
    }  
    public void setId(int id) {  
        this.id = id;  
    }  

    public int getQuantity() {  
        return itemQuantity;  
    }  
    public void setQuantity(int quantity) {  
        this.itemQuantity = quantity;  
    }  

    public float getDiscount() {  
        return itemDiscount;  
    }  
    public void setDiscount(float discount) {  
        this.itemDiscount = discount;  
    }  

    public double getPrice() {  
        return itemPrice;  
    }  
    public void setPrice(double price) {  
        this.itemPrice = price;  
    }  
    public String getName() {  
        return itemName;  
    }  
    public void setName(String iName) {  
        this.itemName = iName;  
    }  
    public String getDescription() {  
        return itemDescription;  
    }  
    public void setDescription(String desc) {  
        this.itemDescription = desc;  
    }  
    public String getcategoty() {  
        return categoty;  
    }  
    public void setcategoty(String cat) {  
        this.categoty = cat;  
    }  


}

Can someone help me understand why second type of parameters worked , whereas first one didn't (Ideally first one was one to one mapping to properties in persistence class)?

Community
  • 1
  • 1
user3440629
  • 198
  • 9
  • it is the same to getters and setters, it removed the prefix name from all variables, Check these examples [example 1](https://www.jetbrains.com/idea/help/generating-getters-and-setters.html) and [example 2](http://stackoverflow.com/questions/14143528/eclipse-generate-getter-setter-for-domain-objects-and-classmembers-with-m-suff) – Kh.Taheri Mar 08 '15 at 22:32
  • It uses getters/setters. – ema Mar 08 '15 at 22:34

2 Answers2

0

It is the same to getters and setters, it removed the prefix name from all variables, Check the following links:

Community
  • 1
  • 1
Kh.Taheri
  • 946
  • 1
  • 10
  • 25
0

Spring calls the setters of your Entity class. (property quantity --> setQuantity(String) - it doesn't look at the name of your members (e.g. itemQuantity).

But: it is always a good idea to name the setters/getter like your members. You should rename your members to match the getters and setter. That makes it more clear.

Besides that, getcategoty and setcategoty should be renamed to camel-case getCategory and setCategory. BTW: is categoty a typo for category?

Alexander
  • 2,925
  • 3
  • 33
  • 36