ssh纯注解配置文件配置例子
描述
applicationContext.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: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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 使用 annotation -->
<context:annotation-config />
<!-- 使用 annotation 自动注册bean,并检查@Controller, @Service, @Repository注解已被注入 -->
<context:component-scan base-package="project" />
<!-- 数据源配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 需要修改的配置地方 mysql -->
<property name="url" value="jdbc:mysql://localhost:3306/javawebxx_blog?characterEncoding=UTF-8" />
<property name="username" value="root" />
<property name="password" value="root" />
<!-- 以下默认即可 --> <property name="filters" value="stat" />
<property name="maxActive" value="80" />
<property name="initialSize" value="1" />
<property name="maxWait" value="60000" />
<property name="minIdle" value="1" />
<property name="timeBetweenEvictionRunsMillis" value="3000" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x' FROM DUAL" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
</bean>
<!--hibernate映射 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- <property name="mappingLocations"> <list><value>classpath*:xml/*.hbm.xml</value></list>
</property> -->
<property name="packagesToScan" value="project.*" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="current_session_context_class">thread</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:ehcache.xml</prop>
<prop key="hibernate.jdbc.use_scrollable_resultset">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" ></ref>
</property>
</bean>
<bean id="baseTxProxy" abstract="true" lazy-init="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
</bean>
<bean id="dao" parent="baseTxProxy">
<property name="target">
<bean class="project.support.MyHibernateDaoSupport" />
</property>
</bean>
</beans>
一个Action配置例子:
package project.action;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.struts2.convention.annotation.Namespace;
import com.opensymphony.xwork2.ModelDriven;
import project.ServiceDao.BlogService;
import project.model.Blog;
/**
* @author https://www.javawebxx.com javaweb学习网
* 备注:>ssm框架ssh框架springmvc框架搭建下载javaweb学习网
*/
@InterceptorRefs({@InterceptorRef(value = "exception", params = { "logEnabled", "true","logLevel", "Error" }), @InterceptorRef("defaultStack") })
@Namespace("/admin/blog")
public class BlogAction extends BaseActionSupport implements ModelDriven{
private static final long serialVersionUID = 1L;
@Autowired
private BlogService blogService;
private Blog blog;
@Action(value="frame",results = {@Result(name="frame",location="../../admin/blog/frame.jsp")})
public String frame() {
return "frame";
}
@Action(value="list",results = {@Result(name="list",location="../../admin/blog/list.jsp")})
public String list() {
List list = blogService.getListBean(request,blog);
request.setAttribute("list", list);
return "list";
}
@Action(value="edit",results = {@Result(name="edit",location="../../admin/blog/edit.jsp")})
public String edit() {
if (blog != null &&blog.getId()!=null) {
Blog s = blogService.get(blog.getId());
request.setAttribute("map", s);
}
// flList
List flList = db.queryForList("select * from t_fenlei ");
request.setAttribute("flList", flList);
return "edit";
}
@Action(value="editSave")
public void editSave() throws IOException {
//String title = getValString(request, "title");
//String headPic = getValString(request, "headPic");
//String content = getValString(request, "content");
//String showDate = getValString(request, "showDate");
//Integer status = getValInteger(request, "status");
//String px = getValString(request, "px");
//String abc = getValString(request, "abc");
//String types = getValString(request, "types");
//Integer cNum = getValInteger(request, "cNum");
//Integer pNum = getValInteger(request, "pNum");
//String istj = getValString(request, "istj");
String method = request.getParameter("method");
if(blog.getId()==null){
String content = blog.getContent();
System.out.println(content);
}else{
}
blogService.saveOrUpdate(blog);
renderMsg(true, "");
}
@Action(value="editDelete")
public void editDelete() throws IOException {
blogService.delete(blog.getId());
renderMsg(true, "");
}
public Blog getModel() {
if (null == blog) {
return blog = new Blog();
}
return blog;
}
}
javawebxx.com由javaweb学习网所有 网站地图 备案号:苏ICP备17055254号-1
留言