ssm(springmvc4+spring4+mybatis3)整合实战-个人博客系统-整合各大框架

ssm框架整合开发实战,这一篇我将介绍如何实现各大框架的整合。

上一篇博客,我介绍了web.xml配置文件,那个文件是项目的核心配置文件,其中其实就包括了整合spring springmvc框架的配置。当然啦,该配置文件还有权限认证安全框架shiro的过滤器配置以及编码过滤器的配置。言归正传,下面就将各大框架的整合配置文件共享出来。

首先是spring、springmvc的配置,spring框架的强大之处在此我就不多说了,起到的作用我就简单说几点吧。

1、其核心部分是IOC与AOP,前者即为所谓的控制反转,用于解决各大组件的依赖问题,也就是解耦的作用;AOP起到监视的作用,俗称面向切面,可以在事务开始前结束后做一层监视;

2、整合hibernate或者mybatis持久层框架,配置事务传播属性,在进行事务操作时起到很好的控制作用(commit,rollback等)。

3、springmvc是spring的一部分,提供的mvc编程模式大大提高了j2EE应用开发的高效性。。。

下面介绍spring的配置applicationContext-spring.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:p="http://www.springframework.org/schema/p"  xmlns:aop="http://www.springframework.org/schema/aop"   xmlns:context="http://www.springframework.org/schema/context"  xmlns:jee="http://www.springframework.org/schema/jee"  xmlns:tx="http://www.springframework.org/schema/tx"  xsi:schemaLocation="    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">    <!-- 数据库连接池 --><!-- 加载配置文件 --><context:property-placeholder location="classpath:jdbc.properties"/><!-- 数据库连接池:阿里的德鲁伊数据库连接池 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"><property name="url" value="${jdbc.jdbcUrl}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><property name="driverClassName" value="${jdbc.driverClass}"/><property name="maxActive" value="${maxActive}"/><property name="minIdle" value="${minIdle}"/></bean><!-- 配置mybatis的sqlSessionFactory --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><!-- 自动扫描mappers.xml文件 --><property name="mapperLocations" value="classpath:com/steadyjack/mappers/*.xml"></property><!-- mybatis配置文件 --><property name="configLocation" value="classpath:mybatis-config.xml"></property></bean><!-- DAO接口所在包名,Spring会自动查找其下的类 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.steadyjack.dao" /><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property></bean><!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!-- 自定义Realm --><bean id="myRealm" class="com.steadyjack.realm.MyRealm"/>  <!-- 安全管理器 --><bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">  <property name="realm" ref="myRealm"/>  </bean>  <!-- Shiro过滤器 --><bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">  <!-- Shiro的核心安全接口,这个属性是必须的 -->  <property name="securityManager" ref="securityManager"/><!-- 身份认证失败,则跳转到登录页面的配置 -->  <property name="loginUrl" value="/login.jsp"/> <!-- Shiro连接约束配置,即过滤链的定义 -->  <property name="filterChainDefinitions">  <value>/login=anon/admin/**=authc</value>  </property></bean>  <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->  <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>  <!-- 开启Shiro注解 --><bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>  <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">  <property name="securityManager" ref="securityManager"/>  </bean>  <!-- 配置事务通知属性 -->  <tx:advice id="txAdvice" transaction-manager="transactionManager">  <!-- 定义事务传播属性 -->  <tx:attributes>  <tx:method name="insert*" propagation="REQUIRED" />  <tx:method name="update*" propagation="REQUIRED" />  <tx:method name="edit*" propagation="REQUIRED" />  <tx:method name="save*" propagation="REQUIRED" />  <tx:method name="add*" propagation="REQUIRED" />  <tx:method name="new*" propagation="REQUIRED" />  <tx:method name="set*" propagation="REQUIRED" />  <tx:method name="remove*" propagation="REQUIRED" />  <tx:method name="delete*" propagation="REQUIRED" />  <tx:method name="change*" propagation="REQUIRED" />  <tx:method name="check*" propagation="REQUIRED" />  <tx:method name="get*" propagation="REQUIRED" read-only="true" />  <tx:method name="find*" propagation="REQUIRED" read-only="true" />  <tx:method name="load*" propagation="REQUIRED" read-only="true" />  <tx:method name="*" propagation="REQUIRED" read-only="true" />  </tx:attributes>  </tx:advice>  <!-- 配置事务切面 -->  <aop:config>  <aop:pointcut id="serviceOperation" expression="execution(* com.steadyjack.service.*.*(..))" />  <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />  </aop:config>  <!-- 自动扫描 --><context:component-scan base-package="com.steadyjack.service" />
</beans>

加入jdbc配置jdbc.properties:

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/db_blog?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=123456#最大连接池数量
maxActive=10#最小连接池数量
minIdle=2

日志配置log4j.properties:

log4j.rootLogger=DEBUG, Console  #Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n  log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG  

mybatis配置文件mybatis-config.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> spring-mvc.xml<!-- 别名 --><typeAliases><package name="com.steadyjack.entity"/></typeAliases></configuration>

最后是springmvc的配置文件:

<?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:aop="http://www.springframework.org/schema/aop"   xmlns:context="http://www.springframework.org/schema/context"  xmlns:jee="http://www.springframework.org/schema/jee"  xmlns:tx="http://www.springframework.org/schema/tx"  xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  http://www.springframework.org/schema/mvc   http://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">    <mvc:annotation-driven/><!-- 静态资源配置 --><mvc:resources mapping="/static/**" location="/static/"/><!-- 视图解析器 --><bean id="viewResolver"  class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/" /><property name="suffix" value=".jsp"></property></bean><!-- 多文件上传处理器 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="defaultEncoding" value="UTF-8"/>  <!-- 即1024*1024*10字节 = 10m --><property name="maxUploadSize" value="10485760"/></bean><!-- 使用注解的包,包括子集 --><context:component-scan base-package="com.steadyjack.controller" />
</beans>  

上面介绍的配置文件中:其实shiro的配置可以单独拿出来的(在这里我就偷懒了)。上面配置文件的内容我已经做了注释了,已看便可知。如果有问题,可以加入后面提供的群讨论。

最后,当然是建立包结构,如下图,大伙就自己建 了:

最后,我就把本系统涉及的各个实体类的代码贴出来吧(其实就是JavaBean了,可以自己建表然后mybatis逆向工程自己生成--至于如何生成,可以看我的博客:mybatis逆向工程)

首先是Blog.java:

package com.steadyjack.entity;import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;/*** title:Blog.java* description:博客实体* time:2017年1月15日 下午9:22:23* author:debug-steadyjack*/
public class Blog implements Serializable {private static final long serialVersionUID = 1L;private Integer id; // 编号private String title; // 博客标题private String summary; // 摘要private Date releaseDate; // 发布日期private Integer clickHit; // 查看次数private Integer replyHit; // 回复次数private String content; // 博客内容private String keyWord; // 关键字 空格隔开private String contentNoTag; // 博客内容 无网页标签 (Lucene分词用)private BlogType blogType; // 博客类型private Integer blogCount; // 博客数量 非博客实际属性,主要是 根据发布日期归档查询博客数量用private String releaseDateStr; // 发布日期字符串 只取年和月private List<String> imagesList=new LinkedList<String>(); // 博客里存在的图片 主要用于前端列表展示显示缩略图public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getSummary() {return summary;}public void setSummary(String summary) {this.summary = summary;}public Date getReleaseDate() {return releaseDate;}public void setReleaseDate(Date releaseDate) {this.releaseDate = releaseDate;}public Integer getClickHit() {return clickHit;}public void setClickHit(Integer clickHit) {this.clickHit = clickHit;}public Integer getReplyHit() {return replyHit;}public void setReplyHit(Integer replyHit) {this.replyHit = replyHit;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public String getContentNoTag() {return contentNoTag;}public void setContentNoTag(String contentNoTag) {this.contentNoTag = contentNoTag;}public BlogType getBlogType() {return blogType;}public void setBlogType(BlogType blogType) {this.blogType = blogType;}public Integer getBlogCount() {return blogCount;}public void setBlogCount(Integer blogCount) {this.blogCount = blogCount;}public String getReleaseDateStr() {return releaseDateStr;}public void setReleaseDateStr(String releaseDateStr) {this.releaseDateStr = releaseDateStr;}public String getKeyWord() {return keyWord;}public void setKeyWord(String keyWord) {this.keyWord = keyWord;}public List<String> getImagesList() {return imagesList;}public void setImagesList(List<String> imagesList) {this.imagesList = imagesList;}}

然后是Blogger.java:

package com.steadyjack.entity;/*** title:Blogger.java* description:博主实体* time:2017年1月15日 下午9:25:23* author:debug-steadyjack*/
public class Blogger {private Integer id; // 编号private String userName; // 用户名private String password; // 密码private String nickName; // 昵称private String sign; // 个性签名private String proFile; // 个人简介private String imageName; // 博主头像public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getNickName() {return nickName;}public void setNickName(String nickName) {this.nickName = nickName;}public String getSign() {return sign;}public void setSign(String sign) {this.sign = sign;}public String getProFile() {return proFile;}public void setProFile(String proFile) {this.proFile = proFile;}public String getImageName() {return imageName;}public void setImageName(String imageName) {this.imageName = imageName;}}

接着是BlogType.java:

package com.steadyjack.entity;import java.io.Serializable;/*** title:BlogType.java* description: 博客类型实体* time:2017年1月15日 下午9:25:32* author:debug-steadyjack*/
public class BlogType implements Serializable{/*** */private static final long serialVersionUID = 1L;private Integer id;  // 编号private String typeName; // 博客类型名称private Integer blogCount; // 数量private Integer orderNo; // 排序  从小到大排序显示public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getTypeName() {return typeName;}public void setTypeName(String typeName) {this.typeName = typeName;}public Integer getBlogCount() {return blogCount;}public void setBlogCount(Integer blogCount) {this.blogCount = blogCount;}public Integer getOrderNo() {return orderNo;}public void setOrderNo(Integer orderNo) {this.orderNo = orderNo;}}

然后是Comment.java:

package com.steadyjack.entity;import java.util.Date;/*** title:Comment.java* description: 评论实体* time:2017年1月15日 下午9:25:41* author:debug-steadyjack*/
public class Comment {private Integer id; // 编号private String userIp; // 用户IPprivate String content; // 评论内容private Blog blog; // 被评论的博客private Date commentDate; // 评论日期private Integer state; // 审核状态  0 待审核 1 审核通过 2 审核未通过public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUserIp() {return userIp;}public void setUserIp(String userIp) {this.userIp = userIp;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public Blog getBlog() {return blog;}public void setBlog(Blog blog) {this.blog = blog;}public Date getCommentDate() {return commentDate;}public void setCommentDate(Date commentDate) {this.commentDate = commentDate;}public Integer getState() {return state;}public void setState(Integer state) {this.state = state;}
}

接着是Link.java:

package com.steadyjack.entity;/*** title:Link.java* description:友情链接实体* time:2017年1月15日 下午9:25:58* author:debug-steadyjack*/
public class Link {private Integer id; // 编号private String linkName; // 链接名称private String linkUrl; // 链接地址private Integer orderNo; // 排序序号 从小到大排序public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getLinkName() {return linkName;}public void setLinkName(String linkName) {this.linkName = linkName;}public String getLinkUrl() {return linkUrl;}public void setLinkUrl(String linkUrl) {this.linkUrl = linkUrl;}public Integer getOrderNo() {return orderNo;}public void setOrderNo(Integer orderNo) {this.orderNo = orderNo;}
}

最后是PageBean.java:

package com.steadyjack.entity;/*** title:PageBean.java* description:分页Model类* time:2017年1月15日 下午9:26:23* author:debug-steadyjack*/
public class PageBean {private int page; // 第几页private int pageSize; // 每页记录数private int start;  // 起始页public PageBean(int page, int pageSize) {super();this.page = page;this.pageSize = pageSize;}public int getPage() {return page;}public void setPage(int page) {this.page = page;}public int getPageSize() {return pageSize;}public void setPageSize(int pageSize) {this.pageSize = pageSize;}public int getStart() {return (page-1)*pageSize;}
}

具体各个实体的属性以及作用我都已经说清楚了!

如果有相关问题:如想找我付费开发其他功能,讨论其中相关问题等等,可以来以下两群找我,我叫debug!

Java开源技术交流:583522159    个人QQ:1948831260

ssm(springmvc4+spring4+mybatis3)整合实战-个人博客系统-整合各大框架相关推荐

  1. Node项目实战开发-博客系统

    Nodejs项目实战开发-博客系统(已完结) 个人博客系统 欢迎访问我的博客~ MaXiaoYu's Bolg 前言: 开发技术 技术 版本 Node ^14.3.0 ejs ^3.1.3 expre ...

  2. 从零开始,搭建博客系统MVC5+EF6搭建框架(1),EF Code frist、实现泛型数据仓储以及业务逻辑

    前言      文章开始,我说过我要用我自学的技术,来搭建一个博客系统,也希望大家给点意见,另外我很感谢博客园的各位朋友们,对我那篇算是自我阶段总结文章的评论,在里面能看出有很多种声音,有支持的我的朋 ...

  3. 基于SSM+Shiro+Druid+MongoDB+MySQL的开源博客系统

    开源地址:https://github.com/shuaijunlan/Autumn-Framework 在线DEMO:https://shuaijunlan.cn/autumn-blog

  4. 重磅回归-SSM整合进阶项目实战之个人博客系统

    历经一个多月的重新设计,需求分析以及前后端开发,终于有了一定的输出:我自己实现的spring4+springmvc+mybatis3整合的进阶项目实战-个人博客系统 已然完成了,系统采用mvc三层模式 ...

  5. 基于ssm的生活故事分享交流博客系统

    基于SSM的生活故事分享交流博客系统 摘要 随着互联网技术的快速发展,无论是人们的生活还是工作,互联网技术都带来了很多的方便,人们通过互联网技术不仅能够提高工作效率还能够降低出错的几率.由于目前很多生 ...

  6. 基于spring boot2的个人博客系统

    welcome rodert 需要项目请直接到文章末尾获取 简介 基于spring boot2.mybatis.bootstrap开发的个人博客系统.下面做了功能和相关技术的描述,适合初学spring ...

  7. beego框架 golang web项目-个人博客系统

    beego框架 golang web项目-个人博客系统 beego个人博客系统功能介绍 首页 分页展示博客 博客详情 评论 文章专栏 分类导航 资源分享 时光轴点点滴滴 关于本站 后台管理 登录 系统 ...

  8. 从零开始开发SSM项目-博客系统实战

    一.项目包含功能 使用SSM框架开发一个博客系统,包含的功能大致有: 1.用户注册与激活,激活方式通过邮件激活 2.用户的登录和退出,包括账号登录.手机快捷登录和qq第三方登录 3.用户账号登录和注册 ...

  9. 基于ssm的个人博客系统的设计与实现(含源文件)

    欢迎添加微信互相交流学习哦! 项目源码:https://gitee.com/oklongmm/biye 进入二十一世纪,以Internet为核心的现代网络积水和通信技术已经得到了飞速的发展和广泛的应用 ...

最新文章

  1. const int * 、int * const、int const* 、const int a(){ } 和int a()const { }的区别和联系
  2. opencv入门 - 显示图像学习总结
  3. jzoj3085. 图的计数
  4. OpenCV学习之Mat::at()理解
  5. 解决WP7的32位图像渐变色色阶问题
  6. PHP gd库 验证码
  7. mysql查看执行计划任务_学习计划 mysql explain执行计划任务详解
  8. 矩阵乘法的本质(线性空间篇,知乎:马同学)
  9. 幼儿园的孩子怎么才可以锻炼其自理能力呢?
  10. 在本地测试一次成功的AJAX请求
  11. 2019年数维杯数学建模A题 我国省际生态环境与经济交互状况的综合评价求解全过程文档及程序
  12. 概率论与数理统计学习笔记(1)——t检验与P值
  13. 微软笔试题 回忆(回文方面)
  14. 当当卓越京东商城货物配送流程揭秘
  15. 大数据人工智能技术全攻略(一)
  16. TopoJSON格式规范说明
  17. 分享图片+文字到微信朋友圈
  18. alpine 使用国内源
  19. 微信h5分享图标没有展示
  20. ROSMoveit中机械臂的点动(Jog)实现

热门文章

  1. 修改app的默认设置(包括修改默认launcher)
  2. 电脑u盘启动盘制作工具
  3. item_search_coupon - 京东优惠券查询接口,京东优惠券查询API接口接入方案
  4. 劳动合同法等25项新法规元旦起实施
  5. 解决华硕笔记本重装win10无背景灯快捷键问题
  6. 英雄联盟无限红蓝,自动躲技能最牛,c++源代码分享!
  7. 浏览器插件就能完成接口调试,无须下载
  8. 海鸥表表带太长了怎么拆_海鸥手表表带 海鸥手表怎么换表带
  9. 语音识别基本概念 II
  10. 土木工程学c语言用啥电脑,学土木类专业需要用笔记本电脑吗?如果需要,什么样的配置合适?...