ssm项目_cms项目系列(一)——SSM框架搭建

点击蓝色程序员的时光 ”关注我 ,标注星标”,及时阅读最新技术文章

c9e51803bd0bf6511beb6f1a910cf179.png


写在前面:

小伙伴儿们,大家好!今天给大家分享一个SSM项目实战系列——cms系统;

第一篇是SSM框架搭建,后续会持续更新,敬请期待!

思维导图:

6c3e51547e06129bf8fb6e6eeecaa5d6.png

1,配置文件引入

1.1,创建Maven项目,添加依赖;

pom.xml文件:

<dependencies>
    -- 添加

这里有的jar包还需要我们手动导入:

003035db3c73e50ac837e032f0faecb2.png

导入之后记得添加jar包:d21a8a17e06c25271cefb6fc56d0c3e1.png

1.2,Resources资源文件;

我们在main目录下新建两个文件夹,分别是java和resources,并把cms标记为Sources目录,resources标记为Resources目录;

59217e1bb23f5428df1ff21f3befeb2e.png

导入5个配置文件:分别是Spring,SpringMVC,MyBatis和日志相关的配置文件;

ManagerMapper.xml(注意文件路径):

xml version="1.0" encoding="UTF-8" ?>
DOCTYPE 

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: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">    <bean id="dataSource"class="com.alibaba.druid.pool.DruidDataSource"><property name="url" value="jdbc:mysql://localhost:3306/db_cms?useUnicode=true&characterEncoding=UTF-8"/><property name="username" value="root"/><property name="password" value="123456"/>bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="mapperLocations" value="classpath:com/java/mappers/*.xml">property><property name="configLocation" value="classpath:mybatis-config.xml">property>bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.java.dao" /><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory">property>bean><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" />bean><bean id="myRealm" class="com.java.realm.MyRealm"/>  <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">  <property name="realm" ref="myRealm"/>  bean>  <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">    <property name="securityManager" ref="securityManager"/>  <property name="loginUrl" value="/login.jsp"/>   <property name="filterChainDefinitions">  <value>
    /login=anon
    /admin/**=authcvalue>  property>bean>    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>  <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.java.service.*.*(..))" />  <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />  aop:config>  <context:component-scan base-package="com.java.service" />beans>

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-config.xml:

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

spring-mvc.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"  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.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">    <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"/>  <property name="maxUploadSize" value="10000000"/>bean><context:component-scan base-package="com.java.controller" />beans>  

2,创建数据库;

创建数据库db_cms,并加上一张表t_manager:

74853a562fcf4b7af8de802c08bf91f4.png


我们添加一条数据进去即可;

3,项目结构搭建;

4dc360efa9e7d88a91b8c580eed71939.png

dao数据访问层:ManagerDao接口:

package com.cms.dao;/**
 * 管理员Dao接口
 * @author user
 *
 */public interface ManagerDao {
}

这里要对应上文的ManagerMapper.xml文件,形成映射,这是MyBatis核心文件;

entity实体层:Manager实体类:

package com.cms.entity;/**
 * 管理员实体
 * @author user
 *
 */public class Manager {private Integer id; // 编号private String userName; // 用户名private String password; // 密码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;
    }
}

这里就是一个与数据库表t_manager相对应的实体类;还有与mybatis-config.xml相对应,里面的别名就是实体层;

service事务层:ManagerService接口:

package com.cms.service;/**
 * 管理员Service接口
 * @author user
 *
 */public interface ManagerService {
}

ManagerServiceImpl实现类:

package com.cms.service.impl;import javax.annotation.Resource;import org.springframework.stereotype.Service;import com.cms.dao.ManagerDao;import com.cms.service.ManagerService;/**
 * 管理员Service实现类
 * @author user
 *
 */@Service("managerService")public class ManagerServiceImpl implements ManagerService{@Resourceprivate ManagerDao managerDao;
}

这属于事务层,通过继承具体实现该类;

controller控制层:ManagerController类:

package com.cms.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.cms.service.ManagerService;/**
 * 管理员Controller层
 * @author user
 *
 */@Controller@RequestMapping("/manager2")public class ManagerController {@Resourceprivate ManagerService managerService;
}

具体的控制层,先搭个框架;

Shiro认证层:自定义MyRealm类:

package com.cms.realm;import org.apache.shiro.authc.AuthenticationException;import org.apache.shiro.authc.AuthenticationInfo;import org.apache.shiro.authc.AuthenticationToken;import org.apache.shiro.authz.AuthorizationInfo;import org.apache.shiro.realm.AuthorizingRealm;import org.apache.shiro.subject.PrincipalCollection;/**
 * 自定义Reaml
 * @author user
 *
 */public class MyRealm extends AuthorizingRealm{@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {// TODO Auto-generated method stubreturn null;
    }@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {// TODO Auto-generated method stubreturn null;
    }
}

4,框架测试;

我们在配置完tomcat环境之后,将cms项目导入进去,运行即可;

ea652bd048384cebf3d217d708f0b6b7.png


当运行出现index.jsp文件的内容时,表示SSM框架已经搭建成功了!


好了,今天就先分享到这里了,下期继续给大家带来cms项目实战后续内容!更多干货、优质文章,欢迎关注我的原创技术公众号~

69798fbab72e77a158e99c40f7272bf2.png

来都来了,点个赞支持一下呗

e841f27e826559fb701d521fa444984b.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、项目简介 本项目是一套基于SSM实现的影院订票系统 或 影院售票系统 或 在线电影订票平台,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者。 包含:项目源码、项目文档、数据库脚本、软件工具等,该项目附带全部源码可作为毕设使用。 项目都经过严格调试,确保可以运行! 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 二、技术实现 后台框架:Spring、SpringMVC、MyBatis UI界面:BootStrap、jQuery 、JSP ​数据库:MySQL 三、系统功能 系统分为前台订票和后台管理: 1. 前台订票 用户注册、用户登录、查看电影列表、分类查看 电影搜索、查看电影详情、发表电影评价 在线订票、在线支付、个人中心、查看订单 2. 后台管理 管理员管理:新增、查看列表、编辑、删除、查询 用户信息管理:查看列表、删除、查询 新闻公告管理:新增、查看列表、编辑、删除、查询 电影类型管理:新增、查看列表、编辑、删除、查询 城市信息管理:新增、查看列表、编辑、删除、查询 影院信息管理:新增、查看列表、编辑、删除、查询 电影信息管理:新增、查看列表、编辑、删除、查询 订单信息管理:查看列表、编辑、删除、查询 电影评价管理:查看列表、删除、查询 详见:https://edu.csdn.net/course/detail/31925
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值