最近学习了struts2+spring+hibernate,写了基于MVC的CURD,在这里给新学struts2的朋友们一点小分享

第一步:添加strut2的包,

第二步:添加hibernate框架支持

第三步:添加spring框架支持

第四步:逆向表。

第五步:在web.xml中添加如下代码

 

ssh2的基于MVC的curd(带事务)<filter>
ssh2的基于MVC的curd(带事务)        
<filter-name>encodingFilter</filter-name>
ssh2的基于MVC的curd(带事务)        
<filter-class>
ssh2的基于MVC的curd(带事务)            org.springframework.web.filter.CharacterEncodingFilter
ssh2的基于MVC的curd(带事务)        
</filter-class>
ssh2的基于MVC的curd(带事务)        
<init-param>
ssh2的基于MVC的curd(带事务)            
<param-name>encoding</param-name>
ssh2的基于MVC的curd(带事务)            
<param-value>utf-8</param-value>
ssh2的基于MVC的curd(带事务)        
</init-param>
ssh2的基于MVC的curd(带事务)    
</filter>
ssh2的基于MVC的curd(带事务)    
<filter-mapping>
ssh2的基于MVC的curd(带事务)        
<filter-name>encodingFilter</filter-name>
ssh2的基于MVC的curd(带事务)        
<url-pattern>/*</url-pattern>
ssh2的基于MVC的curd(带事务)    
</filter-mapping>
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)    
<filter>
ssh2的基于MVC的curd(带事务)        
<filter-name>struts2</filter-name>
ssh2的基于MVC的curd(带事务)        
<filter-class>
ssh2的基于MVC的curd(带事务)            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
ssh2的基于MVC的curd(带事务)        
</filter-class>
ssh2的基于MVC的curd(带事务)    
</filter>
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)    
<filter-mapping>
ssh2的基于MVC的curd(带事务)        
<filter-name>struts2</filter-name>
ssh2的基于MVC的curd(带事务)        
<url-pattern>/*</url-pattern>
ssh2的基于MVC的curd(带事务)    
</filter-mapping>
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)    
<context-param>
ssh2的基于MVC的curd(带事务)        
<param-name>contextConfigLocation</param-name>
ssh2的基于MVC的curd(带事务)        
<param-value>
ssh2的基于MVC的curd(带事务)            /WEB-INF/classes/applicationContext.xml
ssh2的基于MVC的curd(带事务)        
</param-value>
ssh2的基于MVC的curd(带事务)    
</context-param>
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)    
<listener>
ssh2的基于MVC的curd(带事务)        
<listener-class>
ssh2的基于MVC的curd(带事务)            org.springframework.web.context.ContextLoaderListener
ssh2的基于MVC的curd(带事务)        
</listener-class>
ssh2的基于MVC的curd(带事务)    
</listener>

 

第六步: 修改applicationContext.xml

 

ssh2的基于MVC的curd(带事务)<?xml version="1.0" encoding="UTF-8"?>
ssh2的基于MVC的curd(带事务)
<beans xmlns="http://www.springframework.org/schema/beans"
ssh2的基于MVC的curd(带事务)    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
ssh2的基于MVC的curd(带事务)    xmlns:tx
="http://www.springframework.org/schema/tx"
ssh2的基于MVC的curd(带事务)    xsi:schemaLocation
="
ssh2的基于MVC的curd(带事务)       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
ssh2的基于MVC的curd(带事务)       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
ssh2的基于MVC的curd(带事务)       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"
>
ssh2的基于MVC的curd(带事务)    
<bean id="sessionFactory"
ssh2的基于MVC的curd(带事务)        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
ssh2的基于MVC的curd(带事务)        
<property name="configLocation" value="classpath:hibernate.cfg.xml">
ssh2的基于MVC的curd(带事务)        
</property>
ssh2的基于MVC的curd(带事务)    
</bean>
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)    
<!-- 配置事务管理器 -->
ssh2的基于MVC的curd(带事务)    
<bean id="transactionManager"
ssh2的基于MVC的curd(带事务)        class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
ssh2的基于MVC的curd(带事务)        
<property name="sessionFactory">
ssh2的基于MVC的curd(带事务)            
<ref local="sessionFactory" />
ssh2的基于MVC的curd(带事务)        
</property>
ssh2的基于MVC的curd(带事务)    
</bean>
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)    
<!-- 配置事务特性 -->
ssh2的基于MVC的curd(带事务)    
<tx:advice id="txAdvice" transaction-manager="transactionManager">
ssh2的基于MVC的curd(带事务)        
<tx:attributes>
ssh2的基于MVC的curd(带事务)            
<tx:method name="*" propagation="REQUIRED" />
ssh2的基于MVC的curd(带事务)        
</tx:attributes>
ssh2的基于MVC的curd(带事务)    
</tx:advice>
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)    
<!-- 配置那些类的方法进行事务管理 -->
ssh2的基于MVC的curd(带事务)    
<aop:config>
ssh2的基于MVC的curd(带事务)        
<aop:pointcut id="allManagerMethod" expression="execution (* service.*.*(..))" />
ssh2的基于MVC的curd(带事务)        
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
ssh2的基于MVC的curd(带事务)    
</aop:config>

 

第七步:添加struts.xml文件

 

这样配置ssh2的操作就基本上到位了

下面开始编写代码

InsertUserinfo类的代码如下:

 

ssh2的基于MVC的curd(带事务)package controller;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import service.UserinfoService;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)

 DeleteUserinfo的代码如下:

 

ssh2的基于MVC的curd(带事务)package controller;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import org.springframework.transaction.annotation.Propagation;
ssh2的基于MVC的curd(带事务)
import org.springframework.transaction.annotation.Transactional;
ssh2的基于MVC的curd(带事务)
}

 

UpdateUserinfo的代码如下:

 

ssh2的基于MVC的curd(带事务)package controller;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import orm.Userinfo;
ssh2的基于MVC的curd(带事务)
import service.AllService;
ssh2的基于MVC的curd(带事务)

 

SaveUpdateUserinfo的代码如下:

 

ssh2的基于MVC的curd(带事务)package controller;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import orm.Userinfo;
ssh2的基于MVC的curd(带事务)

 

ListUserinfo的代码如下:

 

ssh2的基于MVC的curd(带事务)package controller;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import java.util.ArrayList;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import org.springframework.transaction.annotation.Propagation;
ssh2的基于MVC的curd(带事务)
import org.springframework.transaction.annotation.Transactional;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)

 

service层的UserinfoService的代码如下

 

 

ssh2的基于MVC的curd(带事务)package service;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import java.util.ArrayList;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import org.springframework.transaction.annotation.Propagation;
ssh2的基于MVC的curd(带事务)
import org.springframework.transaction.annotation.Transactional;
ssh2的基于MVC的curd(带事务)
ssh2的基于MVC的curd(带事务)
import orm.AllDAO;
ssh2的基于MVC的curd(带事务)
import orm.Userinfo;
ssh2的基于MVC的curd(带事务)

最后部署项目的时候记得删掉arm2.23的炸包。ssh2的基于MVC的curd(带事务)

 

主要代码如上。

想要详细代码的可以点击下载或留言

第一篇技术文章,希望大家多多支持ssh2的基于MVC的curd(带事务)

 

ssh2CURD下载

 

 

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2021-06-16
  • 2022-12-23
猜你喜欢
  • 2022-03-09
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-01-17
相关资源
相似解决方案