zx527291227 2012-09-15 19:44
浏览 284
已采纳

rapid-framework 中Action中的Manager调用问题?

最近在使用rapid-framework快速脚手架,生成后的代码有些看不懂。

列如:BasedataAction 中调用basedataManager 中的update方法但basedataManager中并没有实现update方法而是继承BaseManager类
现在奇怪的是为什么BasedataAction 能直接使用BaseManager中的方法求解???

[code="java"]
/*

package com.zldigital.mobilevoice.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.org.rapid_framework.beanutils.BeanUtils;
import cn.org.rapid_framework.web.scope.Flash;

import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.zldigital.mobilevoice.dao.*;
import com.zldigital.mobilevoice.model.*;
import com.zldigital.mobilevoice.service.*;
import com.zldigital.mobilevoice.vo.query.*;

/**

public class BasedataAction extends BaseStruts2Action implements Preparable,ModelDriven{
//默认多列排序,example: username desc,createTime asc
protected static final String DEFAULT_SORT_COLUMNS = null;

//forward paths
protected static final String QUERY_JSP = "/pages/Basedata/query.jsp";
protected static final String LIST_JSP= "/pages/Basedata/list.jsp";
protected static final String CREATE_JSP = "/pages/Basedata/create.jsp";
protected static final String EDIT_JSP = "/pages/Basedata/edit.jsp";
protected static final String SHOW_JSP = "/pages/Basedata/show.jsp";
//redirect paths,startWith: !
protected static final String LIST_ACTION = "!/pages/Basedata/list.do";

private BasedataManager basedataManager;

private Basedata basedata;

java.lang.String id = null;

private String[] items;

public void prepare() throws Exception {



    if (isNullOrEmptyString(id)) {
        basedata = new Basedata();
    } else {
        basedata = (Basedata)basedataManager.getById(id);
    }
}

/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,注意大小写 */
public void setBasedataManager(BasedataManager manager) {
    this.basedataManager = manager;
}   

public Object getModel() {
    return basedata;
}

public void setDatacode(java.lang.String val) {
    this.id = val;
}

public void setItems(String[] items) {
    this.items = items;
}

/** 执行搜索 */
public String list() {
    BasedataQuery query = newQuery(BasedataQuery.class,DEFAULT_SORT_COLUMNS);

    Page page = basedataManager.findPage(query);
    savePage(page,query);
    return LIST_JSP;
}

/** 查看对象*/
public String show() {
    return SHOW_JSP;
}

/** 进入新增页面*/
public String create() {
    return CREATE_JSP;
}

/** 保存新增对象 */
public String save() {

    basedataManager.save(basedata);
    Flash.current().success(CREATED_SUCCESS); //存放在Flash中的数据,在下一次http请求中仍然可以读取数据,error()用于显示错误消息
    return LIST_ACTION;
}

/**进入更新页面*/
public String edit() {
    return EDIT_JSP;
}

/**保存更新对象*/
public String update() {
    basedataManager.update(this.basedata);
    Flash.current().success(UPDATE_SUCCESS);
    return LIST_ACTION;
}

/**删除对象*/
public String delete() {
    for(int i = 0; i < items.length; i++) {
        Hashtable params = HttpUtils.parseQueryString(items[i]);
        java.lang.String id = new java.lang.String((String)params.get("datacode"));
        basedataManager.removeById(id);
    }
    Flash.current().success(DELETE_SUCCESS);
    return LIST_ACTION;
}

}

[/code]

[code="java"]

/*

package com.zldigital.mobilevoice.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.zldigital.mobilevoice.dao.*;
import com.zldigital.mobilevoice.model.*;
import com.zldigital.mobilevoice.service.*;
import com.zldigital.mobilevoice.vo.query.*;

/**

@Service
@Transactional
public class BasedataManager extends BaseManager{

private BasedataDao basedataDao;
/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
public void setBasedataDao(BasedataDao dao) {
    this.basedataDao = dao;
}
public EntityDao getEntityDao() {
    return this.basedataDao;
}

@Transactional(readOnly=true)
public Page findPage(BasedataQuery query) {
    return basedataDao.findPage(query);
}

}

[/code]

[code="java"]

package javacommon.base;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Transactional;
/**

  • @author badqiu
    */
    @Transactional
    public abstract class BaseManager {

    protected Log log = LogFactory.getLog(getClass());

    protected abstract EntityDao getEntityDao();

    @Transactional(readOnly=true)
    public E getById(PK id) throws DataAccessException{
    return (E)getEntityDao().getById(id);
    }

    @Transactional(readOnly=true)
    public List findAll() throws DataAccessException{
    return getEntityDao().findAll();
    }

    /** 根据id检查是否插入或是更新数据 */
    public void saveOrUpdate(E entity) throws DataAccessException{
    getEntityDao().saveOrUpdate(entity);
    }

    /** 插入数据 */
    public void save(E entity) throws DataAccessException{
    getEntityDao().save(entity);
    }

    public void removeById(PK id) throws DataAccessException{
    getEntityDao().deleteById(id);
    }

    public void update(E entity) throws DataAccessException{
    getEntityDao().update(entity);
    }

    @Transactional(readOnly=true)
    public boolean isUnique(E entity, String uniquePropertyNames) throws DataAccessException {
    return getEntityDao().isUnique(entity, uniquePropertyNames);
    }

}

[/code]

  • 写回答

1条回答 默认 最新

  • jinnianshilongnian 2012-09-15 20:10
    关注

    A继承B 能自动复用B类里的public/protected方法 复用

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle
  • ¥15 2024年全国大学生数据分析大赛A题:直播带货与电商产品的大数据分析 问题5. 请设计一份优惠券的投放策略,需要考虑优惠券的数量、优惠券的金额、投放时间段和投放商品种类等因素。求具体的python代码
  • ¥15 有人会搭建生鲜配送自营+平台的管理系统吗
  • ¥15 用matlab写代码
  • ¥30 motoradmin系统的多对多配置
  • ¥15 求组态王串口自定义通信配置方法或代码?
  • ¥15 实验 :UML2.0 结构建模
  • ¥20 用vivado写数字逻辑实验报告撰写,FPGA实验