- 浏览: 327062 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
di1984HIT:
谢谢,写的不错。
使用hector操作Cassandra -
mr_von:
非常感谢!
paoding的分词使用 -
howgoo:
http://www.dhtmlx.com/docs/prod ...
dhtmlxGrid分页与排序 -
青春的、脚步:
谢谢
spring-data-mongodb的MongoTemplate 使用小例子 -
青春的、脚步:
xiaofancn 写道青春的、脚步 写道这个能查询都个值在某 ...
spring-data-mongodb的MongoTemplate 使用小例子
web.xml配置请参考
http://xiaofancn.iteye.com/admin/blogs/986469
applicationContext.xml(我放在了WEB-INF目录下了)
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- annotation on --> <context:annotation-config /> <context:component-scan base-package="org.snailteam"/> <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/db?useUnicode=true&amp;amp;characterEncoding=UTF-8"> </property> <property name="username" value="root"></property> <property name="password" value="123456"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="annotatedClasses"> <list> <value>model.Product</value> </list> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="*" read-only="false" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="allManagerMethod" expression="execution(* org.snailteam.service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" /> </aop:config> </beans>
struts.xml配置可就清爽多了
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <constant name="struts.i18n.encoding" value="UTF-8" /> <constant name="struts.ognl.allowStaticMethodAccess" value="true" /> <constant name="struts.objectFactory" value="spring" /> <constant name="struts.multipart.saveDir" value="d://" /> <constant name="struts.action.extension" value="do,action" /> <!-- 全局变量 --> <package name="global" namespace="/" extends="struts-default"> <global-results> <result name="error">/WEB-INF/pages/error.jsp</result> <result name="index">/index.jsp</result> <result name="adminLogin">/admin/login.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="error" exception="Exception"></exception-mapping> </global-exception-mappings> </package> </struts>
持久层类ProductDaoImpl.java
package org.snailteam.dao; import javax.annotation.Resource; import model.Product; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.stereotype.Repository; @Repository("productDao") public class ProductDaoImpl implements ProductDao { private HibernateTemplate hibernateTemplate; @Resource(name = "hibernateTemplate") public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { this.hibernateTemplate = hibernateTemplate; } public void save(Product p) { this.hibernateTemplate.save(p); } }
业务层ProductServiceImpl.java
package org.snailteam.service; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.annotation.Resource; import model.Product; import org.snailteam.dao.ProductDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @Service("productService") public class ProductServiceImpl implements ProductService{ private ProductDao dao; @Resource(name="productDao") public void setDao(ProductDao dao) { this.dao = dao; } //@Transactional(propagation=Propagation.REQUIRED,readOnly=true) public void add(Product p) { dao.save(p); } @PostConstruct//对象构造之后 public void init(){ } @PreDestroy//对象销毁之前 public void destroy(){ } }
表现层ProductAction.java
package org.snailteam.action; import javax.annotation.Resource; import model.Product; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.snailteam.service.ProductService; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionSupport; @Controller("productBean") @Scope("prototype") @Namespace("/prod") @ParentPackage("global") @Results( { @Result(name = "success", location = "/index.jsp") }) public class ProductAction extends ActionSupport { private static final long serialVersionUID = 1L; private ProductService service; private Product prod; public String add() { service.add(prod); return SUCCESS; } public String execute() throws Exception { // TODO Auto-generated method stub return super.execute(); } @Resource(name = "productService") public void setService(ProductService service) { this.service = service; } public Product getProd() { return prod; } public void setProd(Product prod) { this.prod = prod; } }
测试代码
public class ProductActionTest { public static ProductAction action; @BeforeClass public static void setUpBeforeClass() throws Exception { ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); action = (ProductAction) ac.getBean("productBean"); } @Test public void testSave() throws Exception { action.setProd(new Product("产品介绍信息")); System.out.println(action.add()); } }
发表评论
-
spring cloud gateway 全局过滤器。
2019-03-17 23:11 498spring cloud gateway 网关 ... -
elasticsearch 5.4搜索
2017-05-19 08:37 148@Test public void t ... -
netty简单的操作memcached
2017-04-19 18:59 950pom文件 <dependency> ... -
juc系列-Executor框架
2017-03-20 13:34 672转自 juc系列-Executor框架 什 ... -
ReentrantLock 类
2017-03-19 21:11 11.1 什么是reentrantlock java.u ... -
juc之CountDownLatch、CyclicBarrier和Semaphore例子
2017-03-19 17:23 802import java.util.concurren ... -
netty客户端与服务端例子
2017-03-12 20:07 2774package com.snailteam.nett ... -
freemaker集成spring
2017-02-26 19:00 536<bean id="freeMark ... -
spring集成Hessian插件配置改成自动注入。
2017-02-10 15:39 809原来的配置 <bean name="/ ... -
web开发模版
2017-02-09 14:42 0# Rules reminder: # DEBUG &l ... -
Java多线程
2017-02-04 14:39 495线程状态图 新建状态(New): ... -
hash冲突解决
2017-01-23 18:30 4311、开放地址法有一个公式: m是hash表长度,di ... -
mybatis +spring 分库
2015-04-30 17:56 353<context:component-scan b ... -
Java并发任务处理例子
2014-02-12 16:06 1106public void init() { su ... -
JAVA动态代理模式
2012-10-03 01:01 1159这是我要实现的效果 public static ... -
paoding的分词使用
2012-06-13 21:30 4849paoding下载 http://code.googl ... -
使用spring-hadoop操作hadoop
2012-05-20 02:12 32参考文章 http://blog.springsource. ... -
solr3.5集成paoding和位置搜索及对solrj的使用。
2012-04-28 02:12 1926http://xiaofancn.iteye.com/blog ... -
日期处理DateUtils
2012-03-24 09:47 4760import java.text.SimpleDateF ... -
Cassandra的数据分布情况测试
2012-03-16 15:09 20071、规划种子节点ip和Token值的对应 4个种子 ...
相关推荐
s2sh整合annotation s2sh整合annotation s2sh整合annotation s2sh整合annotation s2sh整合annotation
基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能
S2SH框架基于Annotation整合开发,2011年暑假原创
S2SH 框架基于 Annotation 的整合开发
Struts2 + Hibernate3 + Spring2+Annotation连接MySQL数据库含示例
Struts2SpingHibernate整合学习项目,实现注册功能,用Annotation注入,带jar包,引入工程就能用,用MySql实现,最适合于学习s2sh整合的朋友。千里之行,始于足下,同志们,我们一起努力吧
使用Annotation并对DAO层封装具有分页功能的S2SH整合实例
继《使用Annotation并对DAO层封装具有分页功能的S2SH整合实例》系列后
个人认为由Sun官方支持的EJB规范会越来越流行,此时如果使用基于Annotation的SSH框架很容易转移到Struts+EJB+Spring的项目中,而且使用Annotation,很容易实现0配置,像在这个实例中就一个配置,这样避免了配置文件...
基于annotation整合dwr实现的增删改查项目实战。包括三个项目实战例子
import javax.annotation.Resource; import com.googlecode.jsonplugin.annotations.JSON; import com.lk.service.StudentControl; import com.opensymphony.xwork2.ActionSupport; public class LoginAjaxAction ...
整合S2SH+Freemarker,后台用Spring管理各个bean,Hibernate做数据库持久化,viewer用Freemarker。整合中对Struts2,Hibernate,Spring都采用Annotation进行注解类。
整合S2SH+Freemarker+oscache,后台用Spring管理各个bean,Hibernate做数据库持久化,viewer用Freemarker。整合中对Struts2,Hibernate,Spring都采用Annotation进行注解类。
JQuery1.4.2+Struts2.1.8+JSON0.34+Spring2.5.6+Hibernate3.5+XFire1.2.6整合实例(已上传) 1、JSON0.34使用的是struts2附带的struts2-json-plugin-2.1.8.1.jar 2、db是mysql,名字为test,用户名root,密码空 3、...