问题描述
- JUnit不知道怎么写,求大神来一篇,然后我仿照着做啊~~~跪谢
- @Controller
@RequestMapping(""/feeBillClosedController"")
public class FeeBillClosedController extends BaseController {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(FeeBillClosedController.class);@Autowiredprivate FeeBillClosedServiceI feeBillClosedService;@Autowiredprivate 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 feeBillClosedHttpServletRequest 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"")@ResponseBodypublic 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"")@ResponseBodypublic AjaxJson doBatchDel(String idsHttpServletRequest 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"")@ResponseBodypublic 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"")@ResponseBodypublic 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层的
解决方案二:
谢谢大神指导!。。。可以跑去和开发说,这个不需要测了
解决方案三:
一般junit也不会去测controller层的,spring mvc可以直接跑在tomcat这样的容器里面,然后通过浏览器测试
junit一般是测service层的
时间: 2024-10-29 19:20:32