SSH applicationContext.xml中不能找到setter的错误
myeclipse做的SSH,为什么applicationContext.xml中还显示不能找到setter的错误,我已经在service和action里添加了啊。app...
myeclipse做的SSH,为什么applicationContext.xml中还显示不能找到setter的错误,我已经在service和action里添加了啊。
applicationContext.xml:
<!-- 修改 StudentsDAO引用sessionFactory,添加service 引用DAO ,添加action引用service-->
<bean id="IStudentsDAO" class="com.yourcompany.dao.StudentsDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="IStudentsService" class="com.yourcompany.service.StudentsService">
<property name="IStudentsDAO" ref="IStudentsDAO" >
</property>
</bean>
<bean id="InsertstudentAction" class="com.yourcompany.struts.action.InsertstudentAction">
<property name="IStudentsService" ref="IStudentsService" >
</property>
</bean>
</beans>
⑴StudentsService.java:
package com.yourcompany.service;
import com.yourcompany.dao.IStudentsDAO;
import com.yourcompany.po.Students;
public class StudentsService {
private IStudentsDAO istudentsdao;
public void insertstudents(Students s)
{
istudentsdao.save(s);
}
public Students getStudents(Integer id)
{
return istudentsdao.findById(id);
}
public IStudentsDAO getIstudentsdao() {
return istudentsdao;
}
public void setIstudentsdao(IStudentsDAO istudentsdao) {
this.istudentsdao = istudentsdao;
}
}
⑵InsertStudentAction.java:
public class InsertstudentAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
private IStudentsService istudentsservice;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm insertstudentForm = (DynaActionForm) form;// TODO Auto-generated method stub
Integer id=(Integer) insertstudentForm.get("id");
String name=(String) insertstudentForm.get("name");
String age=(String) insertstudentForm.get("age");
Students s=new Students();
s.setId(id);
s.setName(name);
s.setAge(age);
Students stufromDB=istudentsservice.getStudents(id);
if(!id.equals(stufromDB))
{
istudentsservice.insertstudents(s);
return mapping.findForward("success");
}
else
return mapping.findForward("fail");
}
public IStudentsService getIstudentsservice() {
return istudentsservice;
}
public void setIstudentsservice(IStudentsService istudentsservice) {
this.istudentsservice = istudentsservice;
}
} 展开
applicationContext.xml:
<!-- 修改 StudentsDAO引用sessionFactory,添加service 引用DAO ,添加action引用service-->
<bean id="IStudentsDAO" class="com.yourcompany.dao.StudentsDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="IStudentsService" class="com.yourcompany.service.StudentsService">
<property name="IStudentsDAO" ref="IStudentsDAO" >
</property>
</bean>
<bean id="InsertstudentAction" class="com.yourcompany.struts.action.InsertstudentAction">
<property name="IStudentsService" ref="IStudentsService" >
</property>
</bean>
</beans>
⑴StudentsService.java:
package com.yourcompany.service;
import com.yourcompany.dao.IStudentsDAO;
import com.yourcompany.po.Students;
public class StudentsService {
private IStudentsDAO istudentsdao;
public void insertstudents(Students s)
{
istudentsdao.save(s);
}
public Students getStudents(Integer id)
{
return istudentsdao.findById(id);
}
public IStudentsDAO getIstudentsdao() {
return istudentsdao;
}
public void setIstudentsdao(IStudentsDAO istudentsdao) {
this.istudentsdao = istudentsdao;
}
}
⑵InsertStudentAction.java:
public class InsertstudentAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
private IStudentsService istudentsservice;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm insertstudentForm = (DynaActionForm) form;// TODO Auto-generated method stub
Integer id=(Integer) insertstudentForm.get("id");
String name=(String) insertstudentForm.get("name");
String age=(String) insertstudentForm.get("age");
Students s=new Students();
s.setId(id);
s.setName(name);
s.setAge(age);
Students stufromDB=istudentsservice.getStudents(id);
if(!id.equals(stufromDB))
{
istudentsservice.insertstudents(s);
return mapping.findForward("success");
}
else
return mapping.findForward("fail");
}
public IStudentsService getIstudentsservice() {
return istudentsservice;
}
public void setIstudentsservice(IStudentsService istudentsservice) {
this.istudentsservice = istudentsservice;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询