MVC模式
public class GoodsAction extends ActionSupport{
private IService service;
private GoodsVO vo;
public GoodsVO getVo() {
return vo;
}
public void setVo(GoodsVO vo) {
this.vo = vo;
}
public IService getService() {
return service;
}
public void setService(IService service) {
this.service = service;
}
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println(“GoodsAction执行了”);
return super.execute();
}
public String addGoods() throws Exception {
// TODO Auto-generated method stub
System.out.println(“addGoods执行了”);
String name=vo.getGoods_name();
double price=vo.getGoods_price();
int number=vo.getGoods_number();
System.out.println(name+price+number);
GoodsVO vo1=new GoodsVO();
vo1.setGoods_name(name);
vo1.setGoods_price(price);
vo1.setGoods_number(number);
service.addGoods(vo1);//出现问题的一行
return SUCCESS;
}
}
——————————————————————————————————————————
一个包下
public interface IService {
public void addGoods(GoodsVO vo);
}
public class Service implements IService{
private SysDao dao;
public SysDao getDao() {
return dao;
}
public void setDao(SysDao dao) {
this.dao = dao;
}
@Override
public void addGoods(GoodsVO vo) {
dao.addTgoods(vo);
}
}
—
dao包
package com.dao;
public interface SysDao {
/**
* 保存或更新指定对象
* @param
* @return
*/
public void addTgoods(Object ob);
}
package com.dao;
import org.springframework.orm.hibernate3.HibernateTemplate;
public class SysDaoImp implements SysDao{
private HibernateTemplate hibernateTemplate;
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
@Override
public void addTgoods(Object ob) {
// TODO Auto-generated method stub
hibernateTemplate.save(ob);
}
}
public class GoodsAction extends ActionSupport{
private IService service;
private GoodsVO vo;
public GoodsVO getVo() {
return vo;
}
public void setVo(GoodsVO vo) {
this.vo = vo;
}
public IService getService() {
return service;
}
public void setService(IService service) {
this.service = service;
}
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println(“GoodsAction执行了”);
return super.execute();
}
public String addGoods() throws Exception {
// TODO Auto-generated method stub
System.out.println(“addGoods执行了”);
String name=vo.getGoods_name();
double price=vo.getGoods_price();
int number=vo.getGoods_number();
System.out.println(name+price+number);
GoodsVO vo1=new GoodsVO();
vo1.setGoods_name(name);
vo1.setGoods_price(price);
vo1.setGoods_number(number);
service.addGoods(vo1);//出现问题的一行
return SUCCESS;
}
}
——————————————————————————————————————————
一个包下
public interface IService {
public void addGoods(GoodsVO vo);
}
public class Service implements IService{
private SysDao dao;
public SysDao getDao() {
return dao;
}
public void setDao(SysDao dao) {
this.dao = dao;
}
@Override
public void addGoods(GoodsVO vo) {
dao.addTgoods(vo);
}
}
—
dao包
package com.dao;
public interface SysDao {
/**
* 保存或更新指定对象
* @param
* @return
*/
public void addTgoods(Object ob);
}
package com.dao;
import org.springframework.orm.hibernate3.HibernateTemplate;
public class SysDaoImp implements SysDao{
private HibernateTemplate hibernateTemplate;
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
@Override
public void addTgoods(Object ob) {
// TODO Auto-generated method stub
hibernateTemplate.save(ob);
}
}
解决方案:40分
你用个int count=hibernateTemplate.save(vo);接受一下,然后输出看看是1还是0