- 浏览: 518344 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (299)
- Oracle(pl/sql_Erp_Pro*C) (69)
- 设计模式 (4)
- spring (23)
- ext (17)
- apache开源项目应用 (4)
- jquery (16)
- 生活琐事 (8)
- 下载资源 (23)
- mysql (2)
- Eclipse使用积累 (5)
- 报表类(报表/图表) (13)
- php (4)
- Web多彩文本框 (3)
- json (4)
- jqgrid (2)
- ant (2)
- java算法积累 (8)
- EL表达式/JSTL (4)
- poi (3)
- gwt (2)
- 爬网第一步 (2)
- javascript (17)
- Javaweb (8)
- tomcat (1)
- flex (1)
- Java&DB (3)
- J2SE (7)
- linux (3)
- 数据结构 (1)
- dot net (5)
- struts (1)
- ibatis (1)
- log4j (1)
- 项目管理 (1)
- Java native interface(jni,jacob......) (5)
- applet (1)
- VB.net/C#.net/JNI (20)
- css (1)
- Sqlite (1)
- servlet (1)
- REST (1)
最新评论
-
wenhurena:
能不能给一下解压密码roki.work.2017@gmail. ...
Ebs解体新書と学習資料1 -
liutao1600:
楼主写的太好了,每天学习~~
Spring_MVC(6)测试 -
liutao1600:
太好了,每天学习你的文章~~~
Spring_MVC(3)表单页面处理 -
liutao1600:
学习了,太好了
Spring_MVC(2)控制层处理 -
liutao1600:
学习了~~~
Spring_MVC(1)构建简单web应用
Roo是一种 Spring 开发的辅助工具,使用命令行操作来生成自动化项目,操作非常类似于rails
我这里使用spring tool suit来开发一个demo项目
首先新建个spring template project,然后选择template类型为Roo Wep App (based on Roo 1.0.0.RC1)
这样,便会通过roo的命令自动生成一个标准的maven web项目,里面含有最基本的Spring 配置
建好项目后,我们可以在project上运行roo shell
通过hint命令,我们可以很快的了解各种操作提示
首先,设置数据库
install jpa -provider HIBERNATE -database MYSQL
roo会帮你在配置文件applicationContext.xml中配置好了相应的数据源配置,并且在 pom.xml中已经添加jpa和数据库驱动等相关的依赖。
然后新建一个domain
new persistent class jpa -name ~.domain.Employee -testAutomatically
这时roo会帮我们生成Employee类,这时Employee类还没有任何字段,我们可以通过roo shell往里面加入一些字段
- add field string -fieldName name -notNull -sizeMax 200
- add field date jpa -fieldName birth -type java.util.Date
- ......
add field string -fieldName name -notNull -sizeMax 200 add field date jpa -fieldName birth -type java.util.Date ......
最终生成的Employee如下:
- @Entity
- @RooEntity
- @RooJavaBean
- @RooToString
- public class Employee {
- @NotNull
- @Size(max = 200)
- private String name;
- @Temporal(TemporalType.TIMESTAMP)
- private Date birth;
- }
@Entity @RooEntity @RooJavaBean @RooToString public class Employee { @NotNull @Size(max = 200) private String name; @Temporal(TemporalType.TIMESTAMP) private Date birth; }
你会发现,怎么没有get set呢?我们反编译看下编译后的class代码
- // Decompiled by DJ v3.5.5.77 Copyright 2003 Atanas Neshkov Date: 2009-8-8 21:37:43
- // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
- // Decompiler options: packimports(3)
- // Source File Name: Employee.java
- package com.javaeye.domain;
- import java.util.Date;
- import java.util.List;
- import javax.persistence.EntityManager;
- import org.aspectj.runtime.reflect.Factory;
- import org.springframework.beans.factory.annotation.Configurable;
- import org.springframework.beans.factory.aspectj.*;
- // Referenced classes of package com.javaeye.domain:
- // Employee_Roo_ToString, Employee_Roo_Entity, Employee_Roo_JavaBean
- public class Employee
- implements ConfigurableObject
- {
- public Employee()
- {
- org.aspectj.lang.JoinPoint joinpoint1 = Factory.makeJP(ajc$tjp_1, this, this);
- org.aspectj.lang.JoinPoint joinpoint = Factory.makeJP(ajc$tjp_0, this, this);
- if(this != null && getClass().isAnnotationPresent(org/springframework/beans/factory/annotation/Configurable) && AnnotationBeanConfigurerAspect.ajc$if_1((Configurable)getClass().getAnnotation(org/springframework/beans/factory/annotation/Configurable)))
- AnnotationBeanConfigurerAspect.aspectOf().ajc$before$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$1$e854fa65(this);
- if(this != null && getClass().isAnnotationPresent(org/springframework/beans/factory/annotation/Configurable) && (this == null || !getClass().isAnnotationPresent(org/springframework/beans/factory/annotation/Configurable) || !AnnotationBeanConfigurerAspect.ajc$if_1((Configurable)getClass().getAnnotation(org/springframework/beans/factory/annotation/Configurable))) && AbstractDependencyInjectionAspect.ajc$if_0(joinpoint))
- AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);
- Employee_Roo_Entity.ajc$interFieldInit$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$entityManager(this);
- Employee_Roo_Entity.ajc$interFieldInit$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$id(this);
- Employee_Roo_Entity.ajc$interFieldInit$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$version(this);
- if(!AnnotationBeanConfigurerAspect.ajc$if_1((Configurable)getClass().getAnnotation(org/springframework/beans/factory/annotation/Configurable)) && AbstractDependencyInjectionAspect.ajc$if_0(joinpoint1))
- AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);
- }
- public static String ajc$privFieldGet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$name(Employee employee)
- {
- return employee.name;
- }
- public static void ajc$privFieldSet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$name(Employee employee, String s)
- {
- employee.name = s;
- }
- public static Date ajc$privFieldGet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$birth(Employee employee)
- {
- return employee.birth;
- }
- public static void ajc$privFieldSet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$birth(Employee employee, Date date)
- {
- employee.birth = date;
- }
- public static long countEmployees()
- {
- return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$countEmployees();
- }
- public static EntityManager entityManager()
- {
- return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$entityManager();
- }
- public static List findAllEmployees()
- {
- return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$findAllEmployees();
- }
- public static Employee findEmployee(Long long1)
- {
- return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$findEmployee(long1);
- }
- public static List findEmployeeEntries(int i, int j)
- {
- return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$findEmployeeEntries(i, j);
- }
- public void flush()
- {
- Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$flush(this);
- }
- public Date getBirth()
- {
- return Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$getBirth(this);
- }
- public Long getId()
- {
- return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$getId(this);
- }
- public String getName()
- {
- return Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$getName(this);
- }
- public Integer getVersion()
- {
- return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$getVersion(this);
- }
- public void merge()
- { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$merge(this);
- }
- public void persist()
- { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$persist(this);
- }
- public void remove()
- {
- Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$remove(this);
- }
- public void setBirth(Date date)
- {
- Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$setBirth(this, date);
- }
- public void setId(Long long1)
- {
- Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$setId(this, long1);
- }
- public void setName(String s)
- {
- Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$setName(this, s);
- }
- public void setVersion(Integer integer)
- {
- Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$setVersion(this, integer);
- }
- public String toString()
- {
- return Employee_Roo_ToString.ajc$interMethod$com_javaeye_domain_Employee_Roo_ToString$com_javaeye_domain_Employee$toString(this);
- }
- private String name;
- private Date birth;
- public transient EntityManager ajc$interField$com_javaeye_domain$entityManager;
- public Long ajc$interField$com_javaeye_domain_Employee_Roo_Entity$id;
- public Integer ajc$interField$com_javaeye_domain_Employee_Roo_Entity$version;
- private static final org.aspectj.lang.JoinPoint.StaticPart ajc$tjp_0; /* synthetic field */
- private static final org.aspectj.lang.JoinPoint.StaticPart ajc$tjp_1; /* synthetic field */
- static
- {
- Factory factory = new Factory("Employee.java", Class.forName("com.javaeye.domain.Employee"));
- ajc$tjp_0 = factory.makeSJP("initialization", factory.makeConstructorSig("1", "org.springframework.beans.factory.aspectj.ConfigurableObject", "", "", ""), 17);
- ajc$tjp_1 = factory.makeSJP("initialization", factory.makeConstructorSig("1", "com.javaeye.domain.Employee", "", "", ""), 17);
- }
- }
// Decompiled by DJ v3.5.5.77 Copyright 2003 Atanas Neshkov Date: 2009-8-8 21:37:43 // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version! // Decompiler options: packimports(3) // Source File Name: Employee.java package com.javaeye.domain; import java.util.Date; import java.util.List; import javax.persistence.EntityManager; import org.aspectj.runtime.reflect.Factory; import org.springframework.beans.factory.annotation.Configurable; import org.springframework.beans.factory.aspectj.*; // Referenced classes of package com.javaeye.domain: // Employee_Roo_ToString, Employee_Roo_Entity, Employee_Roo_JavaBean public class Employee implements ConfigurableObject { public Employee() { org.aspectj.lang.JoinPoint joinpoint1 = Factory.makeJP(ajc$tjp_1, this, this); org.aspectj.lang.JoinPoint joinpoint = Factory.makeJP(ajc$tjp_0, this, this); if(this != null && getClass().isAnnotationPresent(org/springframework/beans/factory/annotation/Configurable) && AnnotationBeanConfigurerAspect.ajc$if_1((Configurable)getClass().getAnnotation(org/springframework/beans/factory/annotation/Configurable))) AnnotationBeanConfigurerAspect.aspectOf().ajc$before$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$1$e854fa65(this); if(this != null && getClass().isAnnotationPresent(org/springframework/beans/factory/annotation/Configurable) && (this == null || !getClass().isAnnotationPresent(org/springframework/beans/factory/annotation/Configurable) || !AnnotationBeanConfigurerAspect.ajc$if_1((Configurable)getClass().getAnnotation(org/springframework/beans/factory/annotation/Configurable))) && AbstractDependencyInjectionAspect.ajc$if_0(joinpoint)) AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this); Employee_Roo_Entity.ajc$interFieldInit$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$entityManager(this); Employee_Roo_Entity.ajc$interFieldInit$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$id(this); Employee_Roo_Entity.ajc$interFieldInit$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$version(this); if(!AnnotationBeanConfigurerAspect.ajc$if_1((Configurable)getClass().getAnnotation(org/springframework/beans/factory/annotation/Configurable)) && AbstractDependencyInjectionAspect.ajc$if_0(joinpoint1)) AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this); } public static String ajc$privFieldGet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$name(Employee employee) { return employee.name; } public static void ajc$privFieldSet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$name(Employee employee, String s) { employee.name = s; } public static Date ajc$privFieldGet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$birth(Employee employee) { return employee.birth; } public static void ajc$privFieldSet$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$birth(Employee employee, Date date) { employee.birth = date; } public static long countEmployees() { return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$countEmployees(); } public static EntityManager entityManager() { return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$entityManager(); } public static List findAllEmployees() { return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$findAllEmployees(); } public static Employee findEmployee(Long long1) { return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$findEmployee(long1); } public static List findEmployeeEntries(int i, int j) { return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$findEmployeeEntries(i, j); } public void flush() { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$flush(this); } public Date getBirth() { return Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$getBirth(this); } public Long getId() { return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$getId(this); } public String getName() { return Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$getName(this); } public Integer getVersion() { return Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$getVersion(this); } public void merge() { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$merge(this); } public void persist() { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$persist(this); } public void remove() { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$remove(this); } public void setBirth(Date date) { Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$setBirth(this, date); } public void setId(Long long1) { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$setId(this, long1); } public void setName(String s) { Employee_Roo_JavaBean.ajc$interMethod$com_javaeye_domain_Employee_Roo_JavaBean$com_javaeye_domain_Employee$setName(this, s); } public void setVersion(Integer integer) { Employee_Roo_Entity.ajc$interMethod$com_javaeye_domain_Employee_Roo_Entity$com_javaeye_domain_Employee$setVersion(this, integer); } public String toString() { return Employee_Roo_ToString.ajc$interMethod$com_javaeye_domain_Employee_Roo_ToString$com_javaeye_domain_Employee$toString(this); } private String name; private Date birth; public transient EntityManager ajc$interField$com_javaeye_domain$entityManager; public Long ajc$interField$com_javaeye_domain_Employee_Roo_Entity$id; public Integer ajc$interField$com_javaeye_domain_Employee_Roo_Entity$version; private static final org.aspectj.lang.JoinPoint.StaticPart ajc$tjp_0; /* synthetic field */ private static final org.aspectj.lang.JoinPoint.StaticPart ajc$tjp_1; /* synthetic field */ static { Factory factory = new Factory("Employee.java", Class.forName("com.javaeye.domain.Employee")); ajc$tjp_0 = factory.makeSJP("initialization", factory.makeConstructorSig("1", "org.springframework.beans.factory.aspectj.ConfigurableObject", "", "", ""), 17); ajc$tjp_1 = factory.makeSJP("initialization", factory.makeConstructorSig("1", "com.javaeye.domain.Employee", "", "", ""), 17); } }
经过反编译生成的class发现,通过domain类上面的roo注释,自动在类编译时加入get set,甚至我们发现了findAllEmployees,persist,remove,哈,这不是我们梦寐以求的充血模型吗?
原来,roo在为我们创建domain的时候自动为同一个domain创建了4个aspect(.aj files),并在编译期动态为domain切入代码.
4个aspect分别是:
domainName_Roo_Configurable.aj(配置)
domainName_Roo_Entity.aj(加入orm持久)
domainName_Roo_JavaBean.aj(为字段生成get set)
domainName_Roo_ToString.aj(重写toString)
可见,使用roo我们彻底摆脱了在daomain里对各个属性写get set,并且使domain摇身一变为充血。
下一步,就是建Controller了,同样是一条语句
- new controller automatic -formBackingObject ~.domain.Employee -name ~.web.CommentController
new controller automatic -formBackingObject ~.domain.Employee -name ~.web.CommentController
你会发现,EmployeeController,spring mvc的配置以及curd的jsp页面全部生成了
EmployeeController代码如下:
- @RooWebScaffold(automaticallyMaintainView = true, formBackingObject = Employee.class)
- @RequestMapping("/employee/**")
- @Controller
- public class EmployeeController {
- }
@RooWebScaffold(automaticallyMaintainView = true, formBackingObject = Employee.class) @RequestMapping("/employee/**") @Controller public class EmployeeController { }
在这里出现了一行@RooWebScaffold注解,做过rails的人会想,这不是rails里面的scaffold吗?没错,通过@RooWebScaffold注解,EmployeeController自动获得了curd的所有功能。
同样是生成controllerName_Roo_Controller.aj在编译期织入代码
我们来看看生成的EmployeeController_Roo_Controller.aj:
- 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));
- }
- }
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
发表评论
-
cronExpression
2010-08-30 17:57 1188一个Cron-表达式是一个由六至七个字段组成由空格分隔的 ... -
spring任务调度(task)
2010-08-23 13:24 2844spring 任务调度总结参考资料http://www.ibm ... -
spring 任务配置
2010-08-23 10:45 1201xml 代码 <bean id="i ... -
spring3.0注解式声明
2010-08-19 17:39 4369从spring2.5开始,annotation结合BeanPo ... -
spring3.0学习
2010-08-03 16:24 858https://src.springframework.org ... -
Spring mvc 转发、重定向
2010-07-28 16:53 2406spring控制器最后返回一个ModelAndView( ... -
spring api download
2010-07-28 08:43 1175在网上找了好多,都下不下来,要不就是需要注册登录什么的,才能下 ... -
Spring uploadFile
2010-05-02 20:45 2231先让我们来看一段摘自《Spring 2.5 Referen ... -
Spring_MVC(6)测试
2010-04-24 18:48 3722这里将用到以下几个包: 引用 aopalliance-1 ... -
Spring_MVC(5)业务层处理
2010-04-24 18:47 1983这里将用到以下几个包: 引用 aopalliance-1 ... -
Spring_MVC(4)持久层处理
2010-04-24 18:45 1199这里将用到以下几个包: 引用 aopalliance-1 ... -
Spring_MVC(3)表单页面处理
2010-04-24 18:43 3036// 跳转到用户信息页面 ... -
Spring_MVC(2)控制层处理
2010-04-24 18:42 1694言归正传,研究一下注解下的控制层。 我习惯于使用JSTL展示页 ... -
Spring_MVC(1)构建简单web应用
2010-04-24 18:40 1437Java代码 /** * 2010 ... -
spring实现文件上传
2010-04-24 15:15 1615Spring由内置的multipart支持web应用中的文件上 ... -
Spring MVC:使用InternalResourceViewResolver视图解析器
2010-02-24 09:14 2048参考:Sping 2.0.8\docs\MVC-step-by ... -
ibatis+spring控制事务配置
2009-04-05 10:25 1922<bean id="dataSource&qu ... -
转:spring事务控制配置实例
2009-04-03 10:47 3357Spring声明式事务配置的几种方法 在Spring中进 ... -
spring+ibatis+struts事务控制配置
2009-04-03 10:38 1558<?xml version="1.0" ... -
spring+ibatis+struts配置问题
2009-04-01 14:48 1125以下web.xml配置 <?xml version=&q ...
相关推荐
Spring Roo 是一个基于 Java 的开源工具,它简化了 Spring 应用程序的构建过程,通过自动化任务和代码生成,让开发者能够快速地搭建起可扩展的、基于最佳实践的项目结构。 **Spring Roo 的核心特点** 1. **代码生成...
- **提高生产力**:通过自动化生成常见的代码结构,如实体类、控制器等,可以显著提高开发效率。 - **遵循标准 Java 实践**:生成的代码遵循良好的编程习惯和标准,易于维护。 - **易于学习和使用**:提供直观的...
5. **持续集成**:Roo还支持与持续集成工具如Maven和Gradle的集成,方便开发者进行构建、测试和部署流程的自动化。 6. **IDE集成**:Spring Roo可以与Eclipse、IntelliJ IDEA等流行IDE无缝集成,提供便捷的代码补全...
总的来说,Spring ROO是Spring生态体系中的一个重要组成部分,它通过自动化工具和最佳实践,极大地提升了开发效率,降低了企业级应用的开发复杂性。掌握Spring ROO的使用,对于提高开发者的生产力和项目进度具有显著...
总结来说,Spring Roo 1.3.2是Spring框架下的一款强大的开发工具,旨在通过自动化和代码生成加速Java应用的开发流程,同时保持与Spring生态系统的紧密集成,让开发者能更专注于业务逻辑的实现,而非基础设施的搭建。
Roo通过自动化过程,简化了常见的开发任务,如设置项目结构、创建实体类、生成数据库表映射以及创建CRUD操作。本文将深入探讨Spring Roo的核心命令及其在开发过程中的作用。 1. **初始化项目** Spring Roo可以通过...
SpringRoo是Spring框架的扩展,它使用命令行界面(CLI)或集成开发环境(IDE)插件来提供代码生成和自动化功能。它的目标是简化Java应用程序的构建过程,特别适合于Spring Boot应用的早期开发阶段。 二、安装与设置...
Spring Roo是Spring框架家族中的一个开发工具,它旨在加速Java应用程序的开发过程,特别是通过提供命令行接口和集成开发环境(IDE)插件来简化常见的编程任务。标题"spring-roo-1.1.5.RELEASE"指的是Spring Roo的一...
SpringRoo 通过提供一系列自动化代码生成功能,允许开发者在几分钟内创建出完整的企业级应用程序。 **SpringRoo 版本 2.0.0.RC1** 是一个重要的里程碑,标志着 SpringRoo 向更加成熟和强大的方向发展。这一版本在多...
在这个场景中,"spring roo 生成数据库表"指的是使用Spring Roo工具来自动化创建与数据库表对应的Java实体类和数据访问层。 首先,Spring Roo支持多种数据库,包括MySQL、Oracle、PostgreSQL等。在开始之前,你需要...
Spring Roo的核心特性包括自动化代码生成、强大的元数据驱动开发、以及对最佳实践的集成。它通过命令行界面或集成开发环境(IDE)插件提供服务,帮助开发者快速创建项目的结构、实体、控制器和服务层代码。Spring ...
- 自动化构建工具如Maven或Gradle的集成。 - 如何根据需求自定义Roo生成的代码。 总的来说,【os-springroo2-sample_code】项目是一个宝贵的教育资源,适合想要深入了解和使用Spring Roo 2的开发者,他们可以通过此...
Spring Roo是Spring Framework的一个附加工具,它为Java开发者提供了一...这个压缩包提供的资源正是为了帮助开发者快速启动基于Spring的项目,利用Spring Roo的自动化功能和SSH的安全特性来构建高效且安全的Java应用。
Spring Roo提供的不仅仅是自动化工具,还包括了一整套详尽的教程,指导开发者从项目创建、实体设计、集成测试到Web层构建的全过程。通过跟随官方教程,即使是新手也能逐步掌握Roo的使用技巧,最终独立完成复杂的应用...
- 开发效率降低:需要手动编写原本由SpringRoo自动生成的代码。 - 维护成本增加:缺少SpringRoo提供的自动化功能。 **6.3 移除步骤** 移除SpringRoo的步骤包括: - **第一步:推入重构**:将SpringRoo生成的代码...
- **支持持续集成**:与 Maven 和 Ant 等构建工具集成,方便进行自动化构建和部署。 - **丰富的插件生态系统**:Spring Roo 提供了一系列的插件,这些插件可以进一步扩展其功能,满足不同场景的需求。 #### Spring ...
- **快速开发**:Spring Roo 通过自动化大部分常规任务来加速应用程序开发过程,例如创建实体、服务层、控制器以及视图。 - **标准遵循**:生成的应用程序遵循 Spring 最佳实践,使用 Bean Validation (JSR-303) 和 ...
这个"vaadin-springRoo可运行的例子"是一个整合了这两个框架的实际项目,提供了完整的war包和源代码,使得开发者可以深入学习和理解如何在实际开发中结合Vaadin和Spring Roo。 Vaadin是一个开源的Java框架,它允许...
Spring Roo是一个开源工具,它采用基于命令行的交互方式,旨在加速Java应用的开发过程,通过自动化常见任务,使得开发者可以更专注于业务逻辑。这本书详细介绍了Spring Roo的各个方面,包括它的核心概念、工作原理...