路哥教你搭建ssh框架
自己亲手搭建的,保证能运行。
struts2版本2.3.24.1 Spring版本 3.2.0 Hibernate版本3.6.10
先用myeclipse创建web工程
导入三大框架所需要的jar包
先配置web.xml文件
然后再去src下创建struts2的配置文件struts.xml
然后再去src下创建Spring的配置文件applicationContext.xml
xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
再去src下创建hibernate.cfg.xml文件
JPA映射的实体类,和数据库中的表相对应
package com.boco.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity
@Table(name="SMS_MAIL_SINGLETON_FLOW")
public class PersonalFlow implements Serializable {
private String id;// 主键
private String username;// 用户名
private String adminname;// 流程编号
private String weekandtiem;// 周和时间
private String holidays;// 节假日
private String specialday;// 特殊日期
private String overtime;// 超时时间
private String phonename;// 手机号码
private String email;// 邮箱地址
private String phonecontent;// 短信模板内容
private String emailcontent;// 邮箱模板内容
private String sms;// 短信开关
private String mail;// 邮箱开关
@Id
@Column(name="ID")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Column(name="USERNAME")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name="ADMINNAME")
public String getAdminname() {
return adminname;
}
public void setAdminname(String adminname) {
this.adminname = adminname;
}
@Column(name="WEEKANDTIEM")
public String getWeekandtiem() {
return weekandtiem;
}
public void setWeekandtiem(String weekandtiem) {
this.weekandtiem = weekandtiem;
}
@Column(name="HOLIDAYS")
public String getHolidays() {
return holidays;
}
public void setHolidays(String holidays) {
this.holidays = holidays;
}
@Column(name="SPECIALDAY")
public String getSpecialday() {
return specialday;
}
public void setSpecialday(String specialday) {
this.specialday = specialday;
}
@Column(name="OVERTIME")
public String getOvertime() {
return overtime;
}
public void setOvertime(String overtime) {
this.overtime = overtime;
}
@Column(name="PHONENAME")
public String getPhonename() {
return phonename;
}
public void setPhonename(String phonename) {
this.phonename = phonename;
}
@Column(name="EMAIL")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name="PHONECONTENT")
public String getPhonecontent() {
return phonecontent;
}
public void setPhonecontent(String phonecontent) {
this.phonecontent = phonecontent;
}
@Column(name="EMAILCONTENT")
public String getEmailcontent() {
return emailcontent;
}
public void setEmailcontent(String emailcontent) {
this.emailcontent = emailcontent;
}
@Column(name="SMS")
public String getSms() {
return sms;
}
public void setSms(String sms) {
this.sms = sms;
}
@Column(name="MAIL")
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
}
struts2中的action
package com.boco.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.boco.entity.PersonalFlow;
import com.boco.service.Services;
import com.opensymphony.xwork2.Action;
@Controller
@Scope("prototype")
public class Actions {
@Autowired
private Services s;
private PersonalFlow pf;
public Map responseJson;
public Map getResponseJson() {
return responseJson;
}
public void setResponseJson(Map responseJson) {
this.responseJson = responseJson;
}
public PersonalFlow getPf() {
return pf;
}
public void setPf(PersonalFlow pf) {
this.pf = pf;
}
public String addMethod(){
s.addFunction(pf);
return Action.SUCCESS;
}
public void deleteMethod(){
s.deleteFunction(pf);
}
public void modifyMethod(){
s.modifyFunction(pf);
}
public String findAllMethod(){
Map
List
List
package com.boco.dao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import com.boco.entity.PersonalFlow;
@Repository
public class DaosImpl implements Daos {
@Autowired
private HibernateTemplate ht;
public List
List
return list;
}
public void save(PersonalFlow pf) {
ht.save(pf);
}
public void delete(PersonalFlow pf) {
ht.delete(pf);
}
public void update(PersonalFlow pf) {
ht.update(pf);
}
public List
List
return list;
}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
