程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> junit-JUnit不知道怎麼寫,求大神來一篇,然後我仿照著做啊~~~跪謝

junit-JUnit不知道怎麼寫,求大神來一篇,然後我仿照著做啊~~~跪謝

編輯:編程綜合問答
JUnit不知道怎麼寫,求大神來一篇,然後我仿照著做啊~~~跪謝

@Controller
@RequestMapping("/feeBillClosedController")
public class FeeBillClosedController extends BaseController {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(FeeBillClosedController.class);

@Autowired
private FeeBillClosedServiceI feeBillClosedService;
@Autowired
private SystemService systemService;
private String message;

public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}


/**
 * 已結賬單列表 頁面跳轉
 * 
 * @return
 */
@RequestMapping(params = "feeBillClosed")
public ModelAndView feeBillClosed(HttpServletRequest request) {
    return new ModelAndView("com/ygjt/oms/zj/feebillclosed/feeBillClosedList");
}

/**
 * easyui AJAX請求數據
 * 
 * @param request
 * @param response
 * @param dataGrid
 * @param user
 */

@RequestMapping(params = "datagrid")
public void datagrid(FeeBillClosedEntity feeBillClosed,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
    CriteriaQuery cq = new CriteriaQuery(FeeBillClosedEntity.class, dataGrid);
    //查詢條件組裝器
    cq.like("comName", feeBillClosed.getComName());
    feeBillClosed.setComName(null);
    cq.eq("stat", EnumUtils.PAY_STAT.CKECK.getValue());
    org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, feeBillClosed, request.getParameterMap());
    try{
        String query_addTime_begin = request.getParameter("addTime_begin");
        String query_addTime_end = request.getParameter("addTime_end");
        if (StringUtil.isNotEmpty(query_addTime_begin)) {
            cq.ge("addTime", query_addTime_begin);
        }
        if (StringUtil.isNotEmpty(query_addTime_end)) {
            cq.le("addTime", query_addTime_end);
        }
        String query_closedTime_begin = request.getParameter("closedTime_begin");
        String query_closedTime_end = request.getParameter("closedTime_end");
        if (StringUtil.isNotEmpty(query_closedTime_begin)) {
            cq.ge("closedTime", query_closedTime_begin);
        }
        if (StringUtil.isNotEmpty(query_closedTime_end)) {
            cq.le("closedTime", query_closedTime_end);
        }
    }catch (Exception e) {
        throw new BusinessException(e.getMessage());
    }
    cq.add();
    this.feeBillClosedService.getDataGridReturn(cq, true);
    List<FeeBillClosedEntity> feeBillClosedEntities = dataGrid.getResults();
    for (FeeBillClosedEntity feeBillClosedEntity : feeBillClosedEntities) {
        if (feeBillClosedEntity != null) {
            FeeComEntity feeComEntity = systemService
                    .singleResult("from FeeComEntity where 1=1 AND ID='"
                            + feeBillClosedEntity.getComFkid() + "'");
            if (feeComEntity != null) {
                EcommerceRecordEntity ecommerceRecordEntity = systemService
                        .singleResult("from EcommerceRecordEntity where 1=1 AND ID='"
                                + feeComEntity.getComFkid() + "'");
                if (ecommerceRecordEntity != null) {
                    feeBillClosedEntity.setComName(ecommerceRecordEntity
                            .getEcommerceName());
                }
                feeBillClosedEntity.setContacts(feeComEntity.getContacts());
                feeBillClosedEntity.setPhone(feeComEntity.getPhone());
                systemService.saveOrUpdate(feeBillClosedEntity);
            }
        }
    }
    TagUtil.datagrid(response, dataGrid);
}

/**
 * 刪除已結賬單
 * 
 * @return
 */
@RequestMapping(params = "doDel")
@ResponseBody
public AjaxJson doDel(FeeBillClosedEntity feeBillClosed, HttpServletRequest request) {
    AjaxJson j = new AjaxJson();
    feeBillClosed = systemService.getEntity(FeeBillClosedEntity.class, feeBillClosed.getId());
    message = "已結賬單刪除成功";
    try{
        feeBillClosedService.delete(feeBillClosed);
        systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
    }catch(Exception e){
        e.printStackTrace();
        message = "已結賬單刪除失敗";
        throw new BusinessException(e.getMessage());
    }
    j.setMsg(message);
    return j;
}

/**
 * 批量刪除已結賬單
 * 
 * @return
 */
 @RequestMapping(params = "doBatchDel")
@ResponseBody
public AjaxJson doBatchDel(String ids,HttpServletRequest request){
    AjaxJson j = new AjaxJson();
    message = "已結賬單刪除成功";
    try{
        for(String id:ids.split(",")){
            FeeBillClosedEntity feeBillClosed = systemService.getEntity(FeeBillClosedEntity.class, 
            id
            );
            feeBillClosedService.delete(feeBillClosed);
            systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
        }
    }catch(Exception e){
        e.printStackTrace();
        message = "已結賬單刪除失敗";
        throw new BusinessException(e.getMessage());
    }
    j.setMsg(message);
    return j;
}


/**
 * 添加已結賬單
 * 
 * @param ids
 * @return
 */
@RequestMapping(params = "doAdd")
@ResponseBody
public AjaxJson doAdd(FeeBillClosedEntity feeBillClosed, HttpServletRequest request) {
    AjaxJson j = new AjaxJson();
    message = "已結賬單添加成功";
    try{
        feeBillClosedService.save(feeBillClosed);
        systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
    }catch(Exception e){
        e.printStackTrace();
        message = "已結賬單添加失敗";
        throw new BusinessException(e.getMessage());
    }
    j.setMsg(message);
    return j;
}

/**
 * 更新已結賬單
 * 
 * @param ids
 * @return
 */
@RequestMapping(params = "doUpdate")
@ResponseBody
public AjaxJson doUpdate(FeeBillClosedEntity feeBillClosed, HttpServletRequest request) {
    AjaxJson j = new AjaxJson();
    message = "已結賬單更新成功";
    FeeBillClosedEntity t = feeBillClosedService.get(FeeBillClosedEntity.class, feeBillClosed.getId());
    try {
        MyBeanUtils.copyBeanNotNull2Bean(feeBillClosed, t);
        feeBillClosedService.saveOrUpdate(t);
        systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
    } catch (Exception e) {
        e.printStackTrace();
        message = "已結賬單更新失敗";
        throw new BusinessException(e.getMessage());
    }
    j.setMsg(message);
    return j;
}


/**
 * 已結賬單新增頁面跳轉
 * 
 * @return
 */
@RequestMapping(params = "goAdd")
public ModelAndView goAdd(FeeBillClosedEntity feeBillClosed, HttpServletRequest req) {
    if (StringUtil.isNotEmpty(feeBillClosed.getId())) {
        feeBillClosed = feeBillClosedService.getEntity(FeeBillClosedEntity.class, feeBillClosed.getId());
        if(feeBillClosed!=null)
        {
             FeeComEntity feeComEntity = systemService.singleResult("from FeeComEntity where 1=1 AND ID='"
                            + feeBillClosed.getComFkid() + "'");
             req.setAttribute("FeeComEntityPage", feeComEntity);//企業
            if (feeComEntity != null)
            {
                EcommerceRecordEntity recordEntity = systemService.singleResult("from EcommerceRecordEntity where 1=1 AND ID='"
                                + feeComEntity.getComFkid() + "'");
                req.setAttribute("EcommerceRecordEntityPage", recordEntity);//企業屬性

            }
            FeeInvoiceEntity feeInvoiceEntity=systemService.singleResult("from FeeInvoiceEntity where 1=1 AND BILL_FKID='"
                        + feeBillClosed.getId() + "'");
            if(feeInvoiceEntity!=null)
            {
            req.setAttribute("FeeInvoiceEntityPage", feeInvoiceEntity);//發票
            }

        }
        req.setAttribute("feeBillClosedPage", feeBillClosed);
    }
    return new ModelAndView("com/ygjt/oms/zj/feebillclosed/feeBillClosed-update");
}
/**
 * 已結賬單編輯頁面跳轉
 * 
 * @return
 */
@RequestMapping(params = "goUpdate")
public ModelAndView goUpdate(FeeBillClosedEntity feeBillClosed, HttpServletRequest req) {
    if (StringUtil.isNotEmpty(feeBillClosed.getId())) {
        feeBillClosed = feeBillClosedService.getEntity(FeeBillClosedEntity.class, feeBillClosed.getId());
        req.setAttribute("feeBillClosedPage", feeBillClosed);
    }
    return new ModelAndView("com/ygjt/oms/zj/feebillclosed/feeBillClosed-update");
}

}

最佳回答:


一般junit也不會去測controller層的,spring mvc可以直接跑在tomcat這樣的容器裡面,然後通過浏覽器測試

junit一般是測service層的

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved