Java 类有两个同名的属性
我有两节课。现在我有了数据库访问权限,希望获得潜在客户价值。使用springrest+JDBCJava 类有两个同名的属性,java,xml,spring,rest,jaxb,Java,Xml,Spring,Rest,Jaxb,我有两节课。现在我有了数据库访问权限,希望获得潜在客户价值。使用springrest+JDBC @XmlRootElement(name="newlead") public class NewLead { private String FIRSTNAME; private int LEADID; public String getFIRSTNAME() { return FIRSTNAME; } public void
@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”)
公共类NewLeadList{
@XmlElement(必需=true)
public List allLeads=new ArrayList();
@XmlElement(必需=false)
公共列表getData(){
返回所有线索;
}
公共无效设置数据(列表数据){
this.allLeads=数据;
}
}
我的控制器
@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;
}
@Controller//将由
@RequestMapping(“/lead”)//将由(更具体地说是由其组件之一-RequestMappingHandlerMapping)检测
公共类领班控制员{
@资源(name=“newLeadService”)
私有com.varazo.service.NewLeadService NewLeadService;
//对“/”的请求应调用此方法
@RequestMapping(value=“/newLeads”,method=RequestMethod.GET,headers=“Accept=application/xml,application/json”)
public@ResponseBody NewLeadList getNewLead(){
//在这里呼叫服务
NewLeadList结果=新建NewLeadList();
setData(newLeadService.getAll());
System.out.println(“**********************LeadController正在检索所有人员***”+结果+“****是*******************”);
返回结果;
}
我越来越喜欢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>
0
0
0
0
0
0
0
但是我需要每个Lead值都带有firstname和id值。这里有什么问题?你能展示你的新LeadService代码吗?对于开始映射的人,你可以在字段或getter上放一个JAXB注释,但你不应该混用,因为JAXB可能会对使用什么(字段或属性访问)感到困惑@Denium这也不起作用@user3487063服务:public List getAll(){//logger.debug(“检索所有人”);lList=leadDAOImplObj.listNewLeads();System.out.println(“服务内返回==”+lList);返回lList;}和DAO类中:public List listNewLeads(){//JdbcTemplate select=newjdbctemplate(数据源);返回jdbcTemplate.query(“从llead LIMIT 15中选择LEADID,FIRSTNAME”,new LeadRowMapper());您确定您的NewLead对象有fiirstname吗?Petar,是的,我确定。@XmlRootElement(name=“NewLead”)公共类NewLead{/@XmlAttribute(name=“FIRSTNAME”)私有字符串FIRSTNAME;/@XmlAttribute(name=“LEADID”)private int-LEADID;public String getFIRSTNAME(){return FIRSTNAME;}public int-getLEADID(){return LEADID;}public void setFIRSTNAME(String FIRSTNAME){this.FIRSTNAME=FIRSTNAME;}public void setLEADID(int-LEADID){this.LEADID=LEADID;}
</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>