SSH 详解

一、Struts

1. 注解

  1. @Namespace: 定义命名空间
  2. @Namespace("/broker")
  3. @ParentPackage
  4. @ParentPackage("json-default") //继承 struts2 json 包
  5. @Result : 设置返回资源
  6. // 全局设置返回资源
  7. @Result(
  8. // 返回资源类型为 json
  9. type = "json",
  10. // 设置返回资源的数据变量
  11. params = { "root", "result" }
  12. )
  13. @Action: 定义访问地址和返回资源类型
  14. @Action(value="list", results={@Result(location="list.jsp")})
  15. @Action("broker-user-mate-inventory") // 定义访问地址
  16. @ResultPath

二、Spring

1. 注解

  1. import org.springframework.beans.factory.annotation.Autowired;
  2. import org.springframework.stereotype.Controller;
  3. import org.springframework.stereotype.Service;
  4. import org.springframework.stereotype.Repository;
  5. import org.springframework.stereotype.Component;
  6. import org.springframework.transaction.annotation.Transactional; // 事物注解
  7. @Controller 默认产生的Beanname就是类(UserAction)的第一个字母小写(userAction)。
  8. @Controller("uu"),这样就<action name="user_*" class="uu" method="{1}">
  9. @Controller 用于标注控制层组件(如struts中的action),
  10. @Repository 用于标注数据访问组件,即DAO组件,
  11. @Service 用于标注业务层组件,
  12. @Component 泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。
  13. @Autowired 它对类成员变量、方法及构造函数进行标注,完成自动装配的工作。
  14. 通过 @Autowired 的使用来消除 set get方法。
  15. @Qualifier 的标注对象是成员变量、方法入参、构造函数入参。对于 @Autowired 注解的找不到 bean 做处理
  16. 例如配合使用
  17. @Autowired
  18. @Qualifier("commonProperties")
  19. 单独使用
  20. @Qualifier("commonProperties")
  21. @Transactional spring hibernate 整合时, 用到的事物注解
  22. @SuppressWarnings
  23. @SuppressWarnings("unused")
  24. J2SE 提供的最后一个批注是 @SuppressWarnings。该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默

三、Hibernate

1. 注解

  1. import javax.persistence.Column;
  2. // 注解将一个类声明为一个实体bean(即一个持久化POJO类)
  3. import javax.persistence.Entity;
  4. // 注解定义主键标识符的生成策略
  5. import javax.persistence.GeneratedValue;
  6. import javax.persistence.GenerationType;
  7. import javax.persistence.Id;
  8. import javax.persistence.Table;
  9. @Transient 表示该属性并非一个到数据库表的字段的映射,ORM框架将忽略该属性
  10. @Id 注解主键
  11. @GeneratedValue 字段生成规则
  12. @GeneratedValue(strategy = GenerationType.AUTO)
  13. @Column 注解字段
  14. @Column(name = "city_id", length = 9)