总结了一下 struts spring hibernate.
这三个东西
struts 表现层
spring 逻辑层
hibernate持久层spring 通常搁置在【WEB-INF】这个下面,用来操作各种各样的功能,配合javabean ,以及servlet. 主要分为四个层面 运用SSH的情况下:Dao service Hibernate web.这4个简单的层面!
主要用来配置beans.
代码示例:
DAO
<bean id="baseDaoImpl" class="com.dodow.dao.impl.BaseDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="loginDaoImpl" class="com.dodow.actions.login.dao.impl.LoginDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
Hibernate
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8">
</property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="lobHandler">
<ref local="lobHandler" />
</property>
<property name="mappingResources">
<list>
<value>com/dodow/dto/SysUserlist.hbm.xml</value>
<value>com/dodow/dto/SysUserpower.hbm.xml</value>
<value>com/dodow/dto/SysRole.hbm.xml</value>
<value>com/dodow/dto/ZulinInfo.hbm.xml</value>
<value>com/dodow/dto/Todaywork.hbm.xml</value>
<value>com/dodow/dto/Schedule.hbm.xml</value>
<value>com/dodow/dto/Workproject.hbm.xml</value>
</list>
</property>
</bean>
Service
<bean id="loginServiceImpl" class="com.dodow.actions.login.service.impl.LoginServiceImpl">
<property name="baseDao">
<ref bean="baseDaoImpl" />
</property>
<property name="logindao">
<ref bean="loginDaoImpl" />
</property>
</bean>
web
<bean id="bangongAction" class="com.dodow.actions.bangong.BangongAction" scope="prototype">
<property name="bangongService" ref="bangongService"></property>
</bean>
struts 表现层 主要用来表述外面jsp展示到外部的页面 以及做一些处理。包括页面代码也包含struts2的页面代码,其中要配置struts.xml
代码示例:
struts.xml
<struts>
<constant name="struts.multipart.maxSize" value="1099511627776" />
<constant name="struts,devMode" value="true"></constant>
<include file="com/dodow/web/config/struts-login.xml"/>
<include file="com/dodow/web/config/struts-user.xml"/>
</struts>
struts_login.xml
<struts>
<package name="login" extends="struts-default" namespace="/login">
<action name="Login" class="loginAction">
<result name="input">/index.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
struts_user.xml
<package name="user" extends="struts-default" namespace="/system/usermanage">
<action name="user" class="userAction">
<result name="userList">/system/usermanage/userList.jsp</result>
<result name="toAdd">/system/usermanage/adduser.jsp</result>
<result name="addUser" type="redirect">/system/usermanage/user!list.action</result>
</action>
</package> 这个Hibernate 貌似交给Spring 管了。貌似Hibernate 工厂无效了呢!也比较迷惑了。各位高手 需要纠正的 给我纠正一下,这就是我自己的间接,另外有什么提议就说,帮助我学习!
这三个东西
struts 表现层
spring 逻辑层
hibernate持久层spring 通常搁置在【WEB-INF】这个下面,用来操作各种各样的功能,配合javabean ,以及servlet. 主要分为四个层面 运用SSH的情况下:Dao service Hibernate web.这4个简单的层面!
主要用来配置beans.
代码示例:
DAO
<bean id="baseDaoImpl" class="com.dodow.dao.impl.BaseDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="loginDaoImpl" class="com.dodow.actions.login.dao.impl.LoginDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
Hibernate
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8">
</property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="lobHandler">
<ref local="lobHandler" />
</property>
<property name="mappingResources">
<list>
<value>com/dodow/dto/SysUserlist.hbm.xml</value>
<value>com/dodow/dto/SysUserpower.hbm.xml</value>
<value>com/dodow/dto/SysRole.hbm.xml</value>
<value>com/dodow/dto/ZulinInfo.hbm.xml</value>
<value>com/dodow/dto/Todaywork.hbm.xml</value>
<value>com/dodow/dto/Schedule.hbm.xml</value>
<value>com/dodow/dto/Workproject.hbm.xml</value>
</list>
</property>
</bean>
Service
<bean id="loginServiceImpl" class="com.dodow.actions.login.service.impl.LoginServiceImpl">
<property name="baseDao">
<ref bean="baseDaoImpl" />
</property>
<property name="logindao">
<ref bean="loginDaoImpl" />
</property>
</bean>
web
<bean id="bangongAction" class="com.dodow.actions.bangong.BangongAction" scope="prototype">
<property name="bangongService" ref="bangongService"></property>
</bean>
struts 表现层 主要用来表述外面jsp展示到外部的页面 以及做一些处理。包括页面代码也包含struts2的页面代码,其中要配置struts.xml
代码示例:
struts.xml
<struts>
<constant name="struts.multipart.maxSize" value="1099511627776" />
<constant name="struts,devMode" value="true"></constant>
<include file="com/dodow/web/config/struts-login.xml"/>
<include file="com/dodow/web/config/struts-user.xml"/>
</struts>
struts_login.xml
<struts>
<package name="login" extends="struts-default" namespace="/login">
<action name="Login" class="loginAction">
<result name="input">/index.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
struts_user.xml
<package name="user" extends="struts-default" namespace="/system/usermanage">
<action name="user" class="userAction">
<result name="userList">/system/usermanage/userList.jsp</result>
<result name="toAdd">/system/usermanage/adduser.jsp</result>
<result name="addUser" type="redirect">/system/usermanage/user!list.action</result>
</action>
</package> 这个Hibernate 貌似交给Spring 管了。貌似Hibernate 工厂无效了呢!也比较迷惑了。各位高手 需要纠正的 给我纠正一下,这就是我自己的间接,另外有什么提议就说,帮助我学习!
解决方案 »
- 请教各位大虾:如何将B/S系统包装成一个可执行文件?
- 求解!如何在打开jsp页面的同时在 文本框内生成货单号
- J2EE群,68024711(Thinking in J2EE)
- socket 连接到服务器 一台机子不能多连吗???
- java中,在一个类中怎样访问另一个类中的控件属性!
- 怎样去掉JavaApplet的底色???
- 在WEBLOGIC中手配置EJB(不用在JB中配置)怎麼配啊??????
- 关于sql语句的一个问题。
- 【求助贴】 曾经有过在机构培训或者类似经验的前辈帮我解惑一些问题。拜谢进来帮忙的各位。
- Eclipse开发web时,build path的问题。。。。
- 谁能简单阐述一下java开发的主要应用领域
- 关于DES循环解密问题。。采用的是ssh2框架
试想一下,网页流程谁在控制?是struts,不是spring,spring无非就是个工厂,把需要的对象注入到其他对象中而已。真正的表现层应该是struts的逻辑视图,如jsp、freeer、jfreechat、jastreport这些东西
加入spring他就结婚了 被spring管着
加入spring他就结婚了 被spring管着这个理解有创意
spring 逻辑层 ?
我的理解:
spring解耦合struts控制层、表现层
考虑下,当你离开了SSH,还能干啥。
最近很多公司貌似都实现了MVC分离,去研究下。
结果,连xml是怎么自动配置 读写 都不会,这难道是一个程序员应该引以为傲的吗?确实ssh赚钱 很火,但我们得看清楚本质,做一个称职的程序员...不攻击任何人 谢谢!