CRM系统

客户

dao层

@Repository
public class CustomerDaoImpl implements ICustomerDao {

    @Autowired
    private HibernateTemplate template;//注入模板,方便开发

    @Override
    public int save(Customer customer) {
        return (int) template.save(customer);
    }

    @Override
    public List findByExample(Customer example, int pageNum) {
        return template.findByExample(example, (pageNum - 1) * Const.PAGE_SIZE, Const.PAGE_SIZE);
    }

    @Override
    public int count(Customer cust) {
        List list = template.findByExample(cust);
        return list.size();
    }
}

service层

@Service
public class CustomerServiceImpl implements ICustomerService {
    @Autowired
    private ICustomerDao customerDao;

    public Page findByExample(Customer customer, int pageNum) {
        //查询客户
        List list = customerDao.findByExample(customer, pageNum);
        // 总条数
        int count = customerDao.count(customer);
        //封装成page
        return new Page(list, pageNum, count);
    }
}

action层

@Namespace("/") //名称空间
@ResultPath("/jsp/customer") //在所有的地址前面添加前缀
@Component //spring创建action
@Scope("prototype") //多例,action都是多例的
public class CustomerAction implements ModelDriven {//模型驱动封装对象
    @Autowired
    private ICustomerService customerService;

    private Customer customer = new Customer();//模型驱动一对要手动创建对象

    private int pageNum = 1;//当前页数,默认是首页

    //配置action
    @Action(value = "list", results = { @Result(name = "success", location = "list.jsp") })
    public String list() throws IOException {
        Page page = customerService.findByExample(customer, pageNum);
        ActionContext.getContext().put("page", page);//将结果放到域对象中
        return null;
    }

    //set、get方法

}

applicationContext.xml


    
    

    
    
        
        
        
        
    
    
    
        
        
        
            
                org.hibernate.dialect.MySQL5InnoDBDialect
                true
                true
                update
            
        
    

    
    
        
    
    
    

    
        
    

web.xml


        contextConfigLocation
        classpath:spring/applicationContext.xml
    
    
        org.springframework.web.context.ContextLoaderListener
    


    
        OpenSessionInViewFilter
        org.springframework.orm.hibernate5.support.OpenSessionInViewFilter
    
    
        OpenSessionInViewFilter
        /*
    

    
        struts2
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    

    
        struts2
        /*
    

你可能感兴趣的:(CRM系统)