SSH全注解开发笔记
来源:互联网 发布:生产流程管理优化论文 编辑:程序博客网 时间:2024/05/13 23:09
SSH全注解开发笔记
一、添加Struts2与Spring注解
使用了Struts2注解后,无需再使用struts.xml了。然而Strut2通过在action中使用伪类,在Spring中定义该Action的Bean的方式,将Service对象注入给了Action。一旦删除了struts.xml,在Spring中定义的Action的Bean,将与Struts2无关。而这个关系,通过Spring的注解可以再次建立
Struts2注解要点:
1、继承的包:@ParentPackage(“struts-default”)
2、Action的多例:@Scope(“prototype”)
3、Action中service的注入
@Autowired
@Qualifier("studentService") //byName方式自动注入
private IStudentService studentService;
@Qualifier("studentService") //byName方式自动注入
private IStudentService studentService;
4、命名空间:@Namespace(“/test”)
Spring注解要点:
1、在Spring配置文件中注册组件扫描的基本包
<!-- 组件扫描器 --> <context:component-scan base-package="com.hk.*"></context:component-scan>
2、在Spring配置文件中开启Spring事务注解驱动
<!-- 事务注解驱动 --> <tx:annotation-driven transaction-manager="transactionManager"/>
3、在Spring配置文件中删除dao、service、action的Bean定义
保留数据源、sessionFactory以及事务管理器的配置
4、删除struts.xml
添加Hibernate的注解
Hibernate注解是替换xx.hbm.xml文件的
1、实体、表名
@Entity@Table(name="student")
2、id的注册
@Id@GeneratedValue(generator="myGenerator")@GenericGenerator(name="myGenerator",strategy="native")private Integer id;
3、删除映射文件
4、在Spring配置文件的SessionFactory定义中,删除映射文件的相关配置mappingResources
5、在Spring配置文件的SessionFactory定义中,添加实体包扫描器
<!-- 配置映射文件所在文件夹 --><!-- <property name="mappingDirectoryLocations" value="classpath:com/hk/beans"/> --><!-- 实体所在包 --><property name="packagesToScan" value="com.hk.beans"/>
附上全部源码:http://pan.baidu.com/s/1pLPSlr9
0 0
- SSH全注解开发笔记
- ssh全注解开发
- SSH全注解式开发
- 全注解SSH
- 全注解SSH
- 全注解SSH
- 全注解SSH
- 全注解SSH
- 全注解SSH
- 全注解整合ssh
- 【JavaEE】SSH全注解
- 零配置,SSH全注解
- SSH全注解代码片段
- ssh全注解框架整合
- SSH笔记-注解开发(1)开发环境搭建
- SSH 注解开发
- SSH注解开发
- SSH注解方式开发
- 使用LRU(last recently used)算法淘汰数据实例(阿里巴巴例题)
- 手机无法打印Log问题
- Java位运算
- ubuntu16 环境配置
- chrome自动进入VM模式无法调试
- SSH全注解开发笔记
- 函数的重写和重载
- Page Object Model (Selenium, Python)(一)
- LoadRunner-Start Web Server端口被占用处理
- geotools创建线文件
- java并发包:概论
- 机器学习----集成学习(Boosting)
- Volley网络请求数据框架
- 项目管理中的拒绝技巧