Class有两个同名的属性

时间:2014-09-22 18:14:23

标签: java xml spring rest jaxb

我有两节课。现在我有数据库访问权限,希望获得Lead值。使用Spring REST + JDBC。

@XmlRootElement(name="newlead")
public class NewLead {

     private String FIRSTNAME;

     private int LEADID;

     public String getFIRSTNAME() {
         return FIRSTNAME;
     }

     public void setFIRSTNAME(String FIRSTNAME) {
         this.FIRSTNAME = FIRSTNAME;
     }

     public int getLEADID() {
         return LEADID;
     }

     public void setLEADID(int LEADID) {
         this.LEADID = LEADID;
     }
}

@XmlRootElement(name="newLeads")
public class NewLeadList {

    @XmlElement(required = true)
    public List<NewLead> allLeads = new ArrayList<NewLead>();

    @XmlElement(required = false)
    public List<NewLead> getData() {
        return allLeads;
    }

    public void setData(List<NewLead> data) {
        this.allLeads = data;
    }
}

我的控制器

@Controller                 // Will be detected by <context:component-scan>
@RequestMapping("/lead")    // Will be detected by <mvc:annotation-driven> (more specifically by one of its component - RequestMappingHandlerMapping)
public class LeadController {

     @Resource(name="newLeadService")
     private com.varazo.service.NewLeadService newLeadService;

    // This method should be called for requests to "/"  
     @RequestMapping(value = "/newLeads", method = RequestMethod.GET, headers="Accept=application/xml,application/json")
     public @ResponseBody NewLeadList getNewLead() {
         // Call service here
         NewLeadList result = new NewLeadList();
         result.setData(newLeadService.getAll());
         System.out.println("*********************LeadController Retrieving all persons ***"+result+"***yes*************"); 
         return result;
     }

我正在获取像

这样的xml
</allLeads>
<allLeads>
<LEADID>0</LEADID>
</allLeads>
<allLeads>
<LEADID>0</LEADID>
</allLeads>
<allLeads>
<LEADID>0</LEADID>
</allLeads>
<allLeads>
<LEADID>0</LEADID>
</allLeads>
<data>
<LEADID>0</LEADID>
</data>
<data>
<LEADID>0</LEADID>
</data>
<data>
<LEADID>0</LEADID>
</data>
<data>

但我需要使用firstname和id值的每个Lead值。这有什么问题?

0 个答案:

没有答案