基于Spring---SSH整合,使用SSH编写后台:

User模块层

TreeNode.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="t_vue_tree_node" name="com.spring.ssh.user.entity.TreeNode">
<id name="treenodeid" type="java.lang.Integer" column="tree_node_id">
<generator class="increment"></generator>
</id> <property name="treenodename" type="java.lang.String" column="tree_node_name"></property>
<property name="treenodetype" type="java.lang.Integer" column="tree_node_type"></property>
<property name="parentnodeid" type="java.lang.Integer" column="parent_node_id"></property>
<property name="url" type="java.lang.String" column="url"></property>
<property name="position" type="java.lang.Integer" column="position"></property>
<property name="icon" type="java.lang.String" column="icon"></property>
</class>
</hibernate-mapping>
TreeNode 
 package com.spring.ssh.user.entity;

 import com.spring.ssh.base.entity.BaseEntity;

 public class TreeNode extends BaseEntity {

     private int treenodeid;
private String treenodename;
private int treenodetype;
private int parentnodeid;
private String url;
private int position;
private String icon;
public int getTreenodeid() {
return treenodeid;
}
public void setTreenodeid(int treenodeid) {
this.treenodeid = treenodeid;
}
public String getTreenodename() {
return treenodename;
}
public void setTreenodename(String treenodename) {
this.treenodename = treenodename;
}
public int getTreenodetype() {
return treenodetype;
}
public void setTreenodetype(int treenodetype) {
this.treenodetype = treenodetype;
}
public int getParentnodeid() {
return parentnodeid;
}
public void setParentnodeid(int parentnodeid) {
this.parentnodeid = parentnodeid;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public TreeNode(int treenodeid, String treenodename, int treenodetype, int parentnodeid, String url, int position,
String icon) {
this.treenodeid = treenodeid;
this.treenodename = treenodename;
this.treenodetype = treenodetype;
this.parentnodeid = parentnodeid;
this.url = url;
this.position = position;
this.icon = icon;
}
public TreeNode() { }
@Override
public String toString() {
return "TreeNode [treenodeid=" + treenodeid + ", treenodename=" + treenodename + ", treenodetype="
+ treenodetype + ", parentnodeid=" + parentnodeid + ", url=" + url + ", position=" + position
+ ", icon=" + icon + "]";
} }
User 
 package com.spring.ssh.user.entity;

 import com.spring.ssh.base.entity.BaseEntity;

 public class User extends BaseEntity {
private String uname;
private String upwd;
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getUpwd() {
return upwd;
}
public void setUpwd(String upwd) {
this.upwd = upwd;
}
public User(String uname, String upwd) {
this.uname = uname;
this.upwd = upwd;
}
public User() { }
@Override
public String toString() {
return "User [uname=" + uname + ", upwd=" + upwd + "]";
} }

User.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="t_vue_user" name="com.spring.ssh.user.entity.User">
<id name="uname" type="java.lang.String" column="uname"></id> <property name="upwd" type="java.lang.String" column="pwd"></property>
</class>
</hibernate-mapping>

Dao方法

UserDao 
 package com.spring.ssh.user.dao;

 import java.io.Serializable;
import java.util.List; import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.orm.hibernate5.HibernateCallback; import com.spring.ssh.base.dao.BaseDao;
import com.spring.ssh.base.util.StringUtils;
import com.spring.ssh.user.entity.TreeNode;
import com.spring.ssh.user.entity.User; public class UserDao extends BaseDao { public List<User> list(User user){ return this.getHibernateTemplate().execute(new HibernateCallback<List<User>>() { @Override
public List<User> doInHibernate(Session arg0) throws HibernateException {
Query query = arg0.createQuery("from User");
String uname = user.getUname();
String upwd = user.getUpwd();
if(StringUtils.isNotBlank(uname)&& StringUtils.isNotBlank(upwd)) {
query = arg0.createQuery("from User where uname = :uname and upwd = :upwd ");
query.setParameter("uname", uname);
query.setParameter("upwd", upwd);
}
return query.list();
}
});
} public int add(User user) {
Serializable a = this.getHibernateTemplate().save(user);
int n = 0;
if(StringUtils.isNotBlank(a+"")) {
n=1;
}
return n;
} public List<TreeNode> listNode(){ return this.getHibernateTemplate().execute(new HibernateCallback<List<TreeNode>>() {
@Override
public List<TreeNode> doInHibernate(Session session) throws HibernateException {
return session.createQuery("from TreeNode").list();
}
});
}
}

biz

UserBiz

 package com.spring.ssh.user.biz;

 import java.util.List;

 import com.spring.ssh.user.entity.TreeNode;
import com.spring.ssh.user.entity.User; public interface UserBiz {
public List<User> list(User user);
public int add(User user);
public List<TreeNode> listNode();
UserBizImpl 
 package com.spring.ssh.user.biz.impl;

 import java.util.List;

 import com.spring.ssh.user.biz.UserBiz;
import com.spring.ssh.user.dao.UserDao;
import com.spring.ssh.user.entity.TreeNode;
import com.spring.ssh.user.entity.User; public class UserBizImpl implements UserBiz { private UserDao userDao ; public UserDao getUserDao() {
return userDao;
} public void setUserDao(UserDao userDao) {
this.userDao = userDao;
} @Override
public List<User> list(User user) {
return userDao.list(user);
} @Override
public int add(User user) {
return userDao.add(user);
} @Override
public List<TreeNode> listNode() {
return userDao.listNode();
} }

web

UserAction 
 package com.spring.ssh.user.web;

 import java.util.List;

 import com.spring.ssh.base.web.BaseAction;
import com.spring.ssh.user.biz.UserBiz;
import com.spring.ssh.user.entity.TreeNode;
import com.spring.ssh.user.entity.User;
import com.opensymphony.xwork2.ModelDriven; public class UserAction extends BaseAction implements ModelDriven<User> { private User user = new User(); private UserBiz userBiz ; public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} public String dologin() { List<User> list = userBiz.list(user);
if(list.size()>0) {
System.out.println("登录成功");
}
else {
System.out.println("登录失败,用户名或密码错误");
}
return null;
} public String addUser() { int n = userBiz.add(user);
if(n>0) {
System.out.println("注册成功");
}
else {
System.out.println("注册失败");
} return null;
} public String list() { List<User> list = userBiz.list(user);
for (User user : list) {
System.out.println(user);
} return null;
} public String listNode() {
List<TreeNode> listNode = userBiz.listNode();
for (TreeNode treeNode : listNode) {
System.out.println(treeNode);
} return null;
} public UserBiz getUserBiz() {
return userBiz;
} public void setUserBiz(UserBiz userBiz) {
this.userBiz = userBiz;
} @Override
public User getModel() {
return user;
} }

配置User

spring-user.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
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/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <bean id="userDao" class="com.spring.ssh.user.dao.UserDao" parent="baseDao" ></bean>
<bean id="userBiz" class="com.spring.ssh.user.biz.impl.UserBizImpl" parent="baseBiz" >
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userAction" class="com.spring.ssh.user.web.UserAction" parent="baseAction">
<property name="userBiz" ref="userBiz"></property>
</bean>
</beans>

struts-user.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="user" extends="base" namespace="/user" >
<action name="user_*" class="userAction" method="{1}"></action>
</package>
</struts>

Articles模块层

Articles 
 package com.spring.ssh.articles.entity;

 import com.spring.ssh.base.entity.BaseEntity;

 public class Articles extends BaseEntity {

     private int id;
private String title;
private String body;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public Articles(int id, String title, String body) {
super();
this.id = id;
this.title = title;
this.body = body;
}
public Articles() {
super();
}
@Override
public String toString() {
return "Articles [id=" + id + ", title=" + title + ", body=" + body + "]";
}
}
Dao方法
ArticlesDao 
 package com.spring.ssh.articles.dao;

 import java.io.Serializable;
import java.util.List; import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateCallback; import com.spring.ssh.articles.entity.Articles;
import com.spring.ssh.base.dao.BaseDao;
import com.spring.ssh.base.util.StringUtils; public class ArticlesDao extends BaseDao { public List<Articles> list() { return this.getHibernateTemplate().execute(new HibernateCallback<List<Articles>>() { @Override
public List<Articles> doInHibernate(Session session) throws HibernateException { return session.createQuery("from Articles").list();
}
});
} public int add(Articles articles) { Serializable a = this.getHibernateTemplate().save(articles);
int n = 0;
System.out.println("add增加过后的值:" + a);
if (StringUtils.isNotBlank(a + "")) {
n = 1;
}
return n;
} public int edit(Articles articles) { this.getHibernateTemplate().update(articles); return 1;
} public int delete(Articles articles) { this.getHibernateTemplate().delete(articles); return 1;
} }
ArticlesBiz 
 package com.spring.ssh.articles.biz;

 import java.util.List;

 import com.spring.ssh.articles.entity.Articles;

 public interface ArticlesBiz {
public List<Articles> list();
public int add(Articles articles);
public int edit(Articles articles);
public int delete(Articles articles); }
ArticlesBizImpl 
 package com.spring.ssh.articles.biz.impl;

 import java.util.List;

 import com.spring.ssh.articles.biz.ArticlesBiz;
import com.spring.ssh.articles.dao.ArticlesDao;
import com.spring.ssh.articles.entity.Articles; public class ArticlesBizImpl implements ArticlesBiz { private ArticlesDao articlesDao ; public ArticlesDao getArticlesDao() {
return articlesDao;
} public void setArticlesDao(ArticlesDao articlesDao) {
this.articlesDao = articlesDao;
} @Override
public List<Articles> list() {
return articlesDao.list();
} @Override
public int add(Articles articles) {
return articlesDao.add(articles);
} @Override
public int edit(Articles articles) {
return articlesDao.edit(articles);
} @Override
public int delete(Articles articles) {
return articlesDao.delete(articles);
}
}

web

ArticlesAction 
 package com.spring.ssh.articles.web;

 import java.util.List;

 import com.spring.ssh.articles.biz.ArticlesBiz;
import com.spring.ssh.articles.entity.Articles;
import com.spring.ssh.base.web.BaseAction;
import com.opensymphony.xwork2.ModelDriven; public class ArticlesAction extends BaseAction implements ModelDriven<Articles> { private Articles articles = new Articles(); private ArticlesBiz articlesBiz ; public ArticlesBiz getArticlesBiz() {
return articlesBiz;
} public void setArticlesBiz(ArticlesBiz articlesBiz) {
this.articlesBiz = articlesBiz;
} public String list() {
List<Articles> list = articlesBiz.list();
for (Articles a : list) {
System.out.println(a);
} return null;
} public String add() {
articlesBiz.add(articles); return null;
}
public String edit() {
articlesBiz.edit(articles); return null;
}
public String del() {
articlesBiz.delete(articles); return null;
}
@Override
public Articles getModel() {
return articles;
}
}

配置articles

spring-articles.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
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/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <bean id="articlesDao" class="com.spring.ssh.articles.dao.ArticlesDao" parent="baseDao" ></bean>
<bean id="articlesBiz" class="com.spring.ssh.articles.biz.impl.ArticlesBizImpl" parent="baseBiz" >
<property name="articlesDao" ref="articlesDao"></property>
</bean> <bean id="articlesAction" class="com.spring.ssh.articles.web.ArticlesAction" parent="baseAction" scope="proptype">
<property name="articlesBiz" ref="articlesBiz"></property>
</bean> </beans>

struts-articles.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="articles" extends="base" namespace="/articles">
<action name="/articles_*" class="articlesAction" method="{1}">
</action>
</package>
</struts>

Spring---SSH整合(二)的更多相关文章

  1. SSH整合(二)

    SSH框架实现登录.新闻增删改查.树形菜单 项目结构 pom.xml 网不好不要一次引入太多,容易下不全 <project xmlns="http://maven.apache.org ...

  2. Spring+Quartz 整合二:调度管理与定时任务分离

    新的应用场景:很多时候,我们常常会遇到需要动态的添加或修改任务,而spring中所提供的定时任务组件却只能够通过修改xml中trigger的配置才能控制定时任务的时间以及任务的启用或停止,这在带给我们 ...

  3. spring SSH整合

    1 导入三大框架依赖的包: 2 配置web.xml: 增加spring的OpenSessionInView过滤器让Spring管理Session保证Session在一个完整的请求过程是开着的,要配置S ...

  4. SSH整合二

    结构图 articles模块 实体类Articles.java package com.jt.articles.entity; public class Articles { private Inte ...

  5. Spring(八)SSH整合简述

    一.Spring与Struts2的整合 1.1.整合步骤 1.2.配置web.xml 1.3.配置spring配置文件applicationContext.xml 1.4.配置struts配置文件 1 ...

  6. SSH整合之spring整合hibernate

    SSH整合要导入的jar包: MySQL中创建数据库 create database ssh_db; ssh_db 一.spring整合hibernate带有配置文件hibernate.cfg.xml ...

  7. Spring第四天——SSH整合

    (从整合开始,使用回归使用eclipse) 一.三大框架版本:  struts2 hibernate5 spring4 二.SSH三大框架回顾: Hibernate: ORM思想 核心配置文件: 单独 ...

  8. Spring自学教程-ssh整合(六)

    以下是本人原创,如若转载和使用请注明转载地址.本博客信息切勿用于商业,可以个人使用,若喜欢我的博客,请关注我,谢谢!博客地址 感谢您支持我的博客,我的动力是您的支持和关注!如若转载和使用请注明转载地址 ...

  9. ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存

    ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate  : Hibernate是一个持久层框架,经常访问物理数据库 ...

  10. OSGI企业应用开发(五)使用Blueprint整合Spring框架(二)

    上篇文章中,我们开发了一个自定义的Bundle,接着从网络中下载到Spring和Blueprint的Bundle,然后复制到DynamicRuntime项目下. 需要注意的是,这些Bundle并不能在 ...

随机推荐

  1. torch_02_多项式回归

    """ torch.float64对应torch.DoubleTensor torch.float32对应torch.FloatTensor 将真实函数的数据点能够拟合成 ...

  2. 将Prometheus alerts保存到elasticsearch

    Prometheus产生的告警通常会发送到alertmanager,当使用alertmanager时,其告警信息仅存在于alertmanager的内存中,无法持久化.故实现了小工具,用于将Promet ...

  3. cmd命令和linux命令的区别

    cmd命令和linux命令看起来很相似,都是在一个控制台输入一些特定的指令去完成一些特定的操作.可是用过的朋友就会发现这些指令是有很多不同的,可是到底有什么不同,要说又说不上来,所以要了解一下. cm ...

  4. 你知道Object中有哪些方法及其作用吗?

    一.引言二.Object方法详解1.1.registerNatives()1.2.getClass()1.2.1.反射三种方式:1.3.hashCode()1.4.equals()1.4.clone( ...

  5. JVM 的GC算法和垃圾收集器

    1.标记清除算法 黑色部分代表可回收对象,灰色部分代表存活对象,绿色部分代表未使用的.最基础的收集算法就是标记清除算法如同他名字一样,算法分为"标记"和"清除" ...

  6. Redux-saga-整理

    介绍 在redux中更好的解决异步操作 redux-saga相当于在redux原来的数据流中多了一层,对action进行监听 接收到action时,派发一个任务维护state saga通过Genera ...

  7. pxelinux.0:winboot:网络引导(启动)wim格式的windows PE系统:配置文件写法

    关键:加载wimboot引导模块,并传入参数 todo:通过标准kenerl的append传入启动参数..........todo.todo default menu.c32 label wimboo ...

  8. 浅析libuv源码-node事件轮询解析(1)

    好久没写东西了,过了一段咸鱼生活,无意中想起了脉脉上面一句话: 始终保持自己的竞争力.所以,继续开写! 一般的JavaScript源码看的已经没啥意思了,我也不会写什么xx入门新手教程,最终决定还是啃 ...

  9. C# winform窗体简单保存界面控件参数到xml

    引用网上的 XMLHelper 地址 :https://www.cnblogs.com/chnboy/archive/2009/04/02/1427652.html 稍做修改 using System ...

  10. 深入解析 Go 中 Slice 底层实现

    原文: https://halfrost.com/go_slice/   切片是 Go 中的一种基本的数据结构,使用这种结构可以用来管理数据集合.切片的设计想法是由动态数组概念而来,为了开发者可以更加 ...