Struts2.3+Spring4.0
本例之通过Action调Service,Service掉Dao实现(主要掌握思想,注意Date的注入,以及javaBean的前台显示)
StudentAction-->StudentService-->StudentDao-->Student
Student.java
package cn.itcast.domain;import java.util.Date;public class Student {private Integer id;private String name;private String sex;private Date birthday;public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}@Overridepublic String toString() {return "Student [id=" + id + ", name=" + name + ", sex=" + sex+ ", birthday=" + birthday + "]";}}
StudentDao.java
package cn.itcast.dao; import cn.itcast.domain.Student; public class StudentDao {private Student student;public Student getStudent() {return student;}public void setStudent(Student student) {this.student = student;}}
StudentService.java
package cn.itcast.service;import cn.itcast.dao.StudentDao; import cn.itcast.domain.Student;public class StudentService {private StudentDao studentDao;public StudentDao getStudentDao() {return studentDao;}public void setStudentDao(StudentDao studentDao) {this.studentDao = studentDao;}public Student getStudent() {return studentDao.getStudent();} }
StudentAction.java
package cn.itcast.web.action; import cn.itcast.domain.Student; import cn.itcast.service.StudentService; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class StudentAction extends ActionSupport {private static final long serialVersionUID = 1L;private StudentService studentService;public StudentService getStudentService() {return studentService;}public void setStudentService(StudentService studentService) {this.studentService = studentService;}@Overridepublic String execute() throws Exception {Student student = studentService.getStudent();System.out.println(student);ActionContext.getContext().getSession().put("student", student);return super.execute();} }
struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"> <struts><constant name="struts.devMode" value="false" /><constant name="struts.objectFactory" value="spring" /><package name="default" namespace="/" extends="struts-default"><action name="spring" class="StudentAction"><result name="success">/spring1.jsp</result><result name="error">/error.jsp</result></action></package> </struts>
applicationContext2.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd"><!-- 配置Action --><bean id="StudentAction" class="cn.itcast.web.action.StudentAction"scope="prototype"><property name="studentService" ref="studentService" /></bean><bean id="studentService" class="cn.itcast.service.StudentService"scope="prototype"><property name="studentDao" ref="studentDao" /></bean><bean id="studentDao" class="cn.itcast.dao.StudentDao" scope="prototype"><property name="student" ref="student" /></bean><bean id="dateFormat" class="java.text.SimpleDateFormat"><constructor-arg value="yyyy-MM-dd" /></bean><bean id="student" class="cn.itcast.domain.Student" scope="prototype"><property name="id" value="100" /><property name="name" value="陈新卫" /><property name="sex" value="男" /><property name="birthday"><bean factory-bean="dateFormat" factory-method="parse"> <!--注意此处通过dateFormat的parse方法把Date日期格式化,如果直接注入,而不经转换,则注入不成功,会保错。--> <constructor-arg value="1992-03-13" /> </bean> </property> </bean> </beans>
spring1.jsp
<%@ page language="java" import="cn.itcast.domain.*"contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Spring1</title> </head> <body><h1>Student Info by Spring!</h1><table><tr><td colspan="2">Student Info</td></tr><tr><td>id</td><!--注意前台显示bean属性的方法--><td><input type="text" value="${student.id}" /></td></tr><tr><td>name</td><td><input type="text" value="${student.name}" /></td></tr><tr><td>sex</td><td><input type="text" value="${student.sex}" /></td></tr><tr><td>sex</td><td><input type="text" value="${student.birthday}" /></td></tr></table> </body> </html>
welcome.jsp
<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加图书</title> </head> <body><a href="/SS1/spring">显示</a> </body> </html>
转载于:https://www.cnblogs.com/jianfengyun/p/3719665.html
Struts2.3+Spring4.0相关推荐
- [转]Struts2.3.16.1+Hibernate4.3.4+Spring4.0.2 框架整合
原文地址:http://blog.csdn.net/ycb1689/article/details/22928519 最新版Struts2+Hibernate+Spring整合 目前为止三大框架最新版 ...
- 项目ITP(五) spring4.0 整合 Quartz 实现任务调度
2014-05-16 22:51 by Jeff Li 前言 系列文章:[传送门] 项目需求: 二维码推送到一体机上,给学生签到扫描用. 然后须要的是 上课前20分钟 .幸好在帮带我的学长做 p2p ...
- SpringMVC之Controller查找(Spring4.0.3/Spring5.0.4源码进化对比)
0 摘要 本文从源码层面简单讲解SpringMVC的处理器映射环节,也就是查找Controller详细过程 1 SpringMVC请求流程 Controller查找在上图中对应的步骤1至2的过程 Sp ...
- spring4.0之三:@RestController
spring4.0重要的一个新的改进是@RestController注解,它继承自@Controller注解.4.0之前的版本,Spring MVC的组件都使用@Controller来标识当前类是一个 ...
- Spring4.0之四:Meta Annotation(元注解)
Spring框架自2.0开始添加注解的支持,之后的每个版本都增加了更多的注解支持.注解为依赖注入,AOP(如事务)提供了更强大和简便的方式.这也导致你要是用一个相同的注解到许多不同的类中去.这篇文章介 ...
- Spring4.0编程式定时任务配置
看过很多定时调度的配置,大多使用XML配置,觉得比较麻烦,也比较老套.这里介绍一种基于spring4.0注解编程式配置定时任务,简单清晰,使用方便.. 至于引入spring相关jar这里不多说,直接切 ...
- Spring 4.x框架中的新特性---Spring4.0框架的新功能和改善
2004年Spring框架首次发布,然后陆续发布了一些重要的版本:Spring2.0提供XML命名空间和AspectJ的支持:Spring2.5包含了注释驱动配置:Spring3.0在框架基础代码中引 ...
- Struts2版本2.0升2.3.37
项目环境: jdk1.6 + tomcat6 + orcale 框架: Struts2+Spring+ibatis 需求:Struts2 版本是2.0版 升级到2.3.37版本 第一步:下载strut ...
- Myeclipse10下搭建SSH框架(图解)Struts2.1+Spring3.0+Hibernate3.3
一.建立一个Web Project ①点击File→New→Web Project 新建一个Web工程. ②在Project Name中输入项目名ssh,在J2EE Specificatio ...
最新文章
- 汇编语言系统调用过程
- PHP入门 1 phpstudy安装与配置站点
- 敏捷过程、极限编程和SCRUM的关系
- 【HDU】1084 What Is Your Grade? (结构体 sort)
- 重温ES6核心概念和基本用法
- Android消息推送完美解决方案全析
- leetcode C++ 4. 寻找两个有序数组的中位数 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log
- NSDictionary 、 NSMutableDictionary
- SAP Analytics Cloud里避免类型为个数的measure出现小数点
- matlab程序中,如何解决矢量长度必须相同的问题
- Android之Animation动画的介绍及用法
- oracle视图不能创建,ORACLEsoctt不能创建视图
- oracle8i数据库修复,用ORACLE8i修复数据库坏块的三种方法
- 苹果电脑上几款不错的图片编辑工具
- 华为手机自带的双系统模式,你知道吗?一部手机当两部使用
- vue路由守卫以及用法
- uipath对SAP的抓取
- 【华人学者风采】Ting Xu 加州大学伯克利分校
- python中复数表达形式_在Python中实现复数比较?
- 车间制造管理系统(上)
热门文章
- Ember.js系列文章
- python中删除列表中的空元素以及如何读取excel中的数据
- asp.net采用OLEDB方式导入Excel数据时提示:未在本地计算机上注册Microsoft.Jet.OLEDB.4.0 提供程序...
- Ubuntu8.10安装Netbeans6.7中文乱码解决方案
- IT人的理性、激情与爱情
- java封装省市区三级json格式,2016中国省市区三级联动json格式.pdf
- 源码解读Mybatis List列表In查询实现的注意事项
- PERL 语言中的q,qw,qr,qx,qq......符号用法总结
- java canvas 画图片_[Java教程][HTML5] Canvas绘制简单图片
- java中char占的二进制,java数据类型与二进制详细介绍