标签:
当基于Crystal的静态Portlet开发完成后,在与后台服务联调前,还需要将Portlet转换成基于测试数据的动态Portlet。具体步骤如下:
创建测试数据项目:
根据api实现相关服务的实现类,但方法内部只需返回设计的测试数据即可,如下:
@Service public class ApplicationManager implements ApplicationService { /* (non-Javadoc) * @see com.gsoft.portlet.uum.application.ApplicationService#list() */ @Override public List<Application> list() { List<Application> list = new ArrayList<Application>(); for(int i = 0; i < 20; i++){ Application app = new Application(); app.setId(new Long(i)); app.setName("Name " + i); app.setCode("code " + i); app.setUrl("http://localhsot/" + i); app.setDisabled(i %3 == 0 ? true : false); list.add(app); } return list; } /* (non-Javadoc) * @see com.gsoft.portlet.uum.application.ApplicationService#getById(java.lang.Long) */ @Override public Application getById(Long id) { Application app = new Application(); app.setId(10L); app.setName("Name 10"); app.setCode("code 10"); app.setUrl("http://localhsot/10"); return app; } }
修改静态Portlet项目为动态测试Portlet:
修改src/main/java下相应Portlet类,调用远程api及测试数据服务,返回测试数据;
@Controller public class ApplicationManagementPortlet extends AbstractCrystalPortlet { @Resource private AuthSystemService authSystemService; @RequestMapping public String view(Model model, RenderRequest request) { List<AuthSystemDto> result = authSystemService.finaAllAuthSystemList(); request.setAttribute("result", result); return "view"; } @RequestMapping(params = "action=add") public String view4add(Model model, @Param String rediract) { model.addAttribute("rediract", rediract); return "add"; } @RequestMapping(params = "action=edit") public String view4edit(Model model, @RequestParam String rediract,@RequestParam Long id) { model.addAttribute("rediract", rediract); AuthSystemDto authSystemDto = authSystemService.findOne(id); model.addAttribute("system", authSystemDto); return "add"; } @RequestMapping(params = "action=del") public String delete(Model model, RenderRequest request, @RequestParam Long id) { authSystemService.deleteAuthSystem(id); return "pop_up_success"; } @RequestMapping(params = "action=editState") public String editState(Model model, RenderRequest request, @RequestParam Long id,@RequestParam String state) { AuthSystemDto authSystemDto = new AuthSystemDto(); authSystemDto.setId(id); if(StringUtils.equals(UserRepConstants.UserRepState.DISABLE, state)) { authSystemDto.setState(UserRepConstants.UserRepState.ENABLE); } else { authSystemDto.setState(UserRepConstants.UserRepState.DISABLE); } authSystemService.updateAuthSystemState(authSystemDto ); return "pop_up_success"; } @RequestMapping(params = "action=save") public String save(Model model, @ModelAttribute("authSystem")AuthSystemDto authSystem, @RequestParam String rediract){ if(StringUtils.isEmpty(authSystem.getState())) { authSystem.setState("1"); } if(authSystem.getId() == null) { authSystemService.saveAuthSystem(authSystem); }else { authSystemService.updateAuthSystem(authSystem); } model.addAttribute("rediract", rediract); return "pop_up_success"; } @RequestMapping(params = "action=check") public ModelAndView checkDupCode(Model model, RenderRequest request, @RequestParam Long id,@RequestParam String code) throws JsonProcessingException { AuthSystemDto system = new AuthSystemDto(); system.setCode(code); system.setId(id); Boolean exists = authSystemService.existsAuthSystemCode(system); Map<String, Object> result = new HashMap<String, Object>(); result.put("success", Boolean.TRUE); result.put("data", exists); return ajax(result); } }
发布动态测试Portlet,并做相应调试。
开发Portlet第二步:如何将Crystal静态Portlet转变成基于测试数据的动态Portlet?
标签:
原文地址:http://www.cnblogs.com/jytx/p/5466813.html