使用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?