首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

运用Spring Roo ,感受ROR式的开发

2012-11-13 
使用Spring Roo ,感受ROR式的开发?package com.javaeye.webprivileged aspect EmployeeController_Roo_Co

使用Spring Roo ,感受ROR式的开发

?

package com.javaeye.web; privileged aspect EmployeeController_Roo_Controller { @org.springframework.web.bind.annotation.RequestMapping(value = "/employee", method = org.springframework.web.bind.annotation.RequestMethod.POST) public java.lang.String EmployeeController.create(@org.springframework.web.bind.annotation.ModelAttribute("employee") com.javaeye.domain.Employee employee, org.springframework.validation.BindingResult result) { if (employee == null) throw new IllegalArgumentException("A employee is required"); for(javax.validation.ConstraintViolation<com.javaeye.domain.Employee> constraint : javax.validation.Validation.buildDefaultValidatorFactory().getValidator().validate(employee)) { result.rejectValue(constraint.getPropertyPath(), null, constraint.getMessage()); } if (result.hasErrors()) { return "employee/create"; } employee.persist(); return "redirect:/employee/" + employee.getId(); } @org.springframework.web.bind.annotation.RequestMapping(value = "/employee/form", method = org.springframework.web.bind.annotation.RequestMethod.GET) public java.lang.String EmployeeController.createForm(org.springframework.ui.ModelMap modelMap) { modelMap.addAttribute("employee", new com.javaeye.domain.Employee()); return "employee/create"; } @org.springframework.web.bind.annotation.RequestMapping(value = "/employee/{id}", method = org.springframework.web.bind.annotation.RequestMethod.GET) public java.lang.String EmployeeController.show(@org.springframework.web.bind.annotation.PathVariable("id") java.lang.Long id, org.springframework.ui.ModelMap modelMap) { if (id == null) throw new IllegalArgumentException("An Identifier is required"); modelMap.addAttribute("employee", com.javaeye.domain.Employee.findEmployee(id)); return "employee/show"; } @org.springframework.web.bind.annotation.RequestMapping(value = "/employee", method = org.springframework.web.bind.annotation.RequestMethod.GET) public java.lang.String EmployeeController.list(org.springframework.ui.ModelMap modelMap) { modelMap.addAttribute("employees", com.javaeye.domain.Employee.findAllEmployees()); return "employee/list"; } @org.springframework.web.bind.annotation.RequestMapping(method = org.springframework.web.bind.annotation.RequestMethod.PUT) public java.lang.String EmployeeController.update(@org.springframework.web.bind.annotation.ModelAttribute("employee") com.javaeye.domain.Employee employee, org.springframework.validation.BindingResult result) { if (employee == null) throw new IllegalArgumentException("A employee is required"); for(javax.validation.ConstraintViolation<com.javaeye.domain.Employee> constraint : javax.validation.Validation.buildDefaultValidatorFactory().getValidator().validate(employee)) { result.rejectValue(constraint.getPropertyPath(), null, constraint.getMessage()); } if (result.hasErrors()) { return "employee/update"; } employee.merge(); return "redirect:/employee/" + employee.getId(); } @org.springframework.web.bind.annotation.RequestMapping(value = "/employee/{id}/form", method = org.springframework.web.bind.annotation.RequestMethod.GET) public java.lang.String EmployeeController.updateForm(@org.springframework.web.bind.annotation.PathVariable("id") java.lang.Long id, org.springframework.ui.ModelMap modelMap) { if (id == null) throw new IllegalArgumentException("An Identifier is required"); modelMap.addAttribute("employee", com.javaeye.domain.Employee.findEmployee(id)); return "employee/update"; } @org.springframework.web.bind.annotation.RequestMapping(value = "/employee/{id}", method = org.springframework.web.bind.annotation.RequestMethod.DELETE) public java.lang.String EmployeeController.delete(@org.springframework.web.bind.annotation.PathVariable("id") java.lang.Long id) { if (id == null) throw new IllegalArgumentException("An Identifier is required"); com.javaeye.domain.Employee.findEmployee(id).remove(); return "redirect:/employee"; } @org.springframework.web.bind.annotation.InitBinder public void EmployeeController.initBinder(org.springframework.web.bind.WebDataBinder binder) { binder.registerCustomEditor(java.util.Date.class, new org.springframework.beans.propertyeditors.CustomDateEditor(new java.text.SimpleDateFormat("yyyy-M-d"), false)); } } ?这样,Controller里不用写一行代码,就自动拥有了curd,而且,最新的roo使用了spring3.0,还支持了rest?
好了,就这么简单,一个domain,一个Controller,我们就可以发布到tomcat中运行了。?
不到5分钟,我们就可以生成了一个可运行的项目,是不是很有ror式的感觉啊?赶快来试试吧

热点排行