栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

基于SSM框架的电影售票网站——项目搭建

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于SSM框架的电影售票网站——项目搭建

项目名称:基于SSM框架的电影售票网站

开发工具:

  • JDK8
  • MySQL 、Navicat
  • Maven
  • Postman
  • IDEA

前台:JQuery + thymeleaf

后台:Spring + SpringMVC + MyBatis

在搭建项目之前,先简单回顾一下ssm各框架的作用:

  1. Spring是一个轻量级的控制反转(IoC)和面向切面(AoP)的容器框架
  2. SpringMVC分离了控制器、模型对象、分派器以及处理程序对象的角色
  3. MyBatis使用XML或注解用于配置和原始映射,将接口和Java对象映射成数据库记录

---------------------------------------------------------------------------------------------------------------------------------

1、准备数据库

2、新建Maven项目

补充项目结构

 使用IDEA连接数据库

配置Tomcat环境

 导入依赖

 
    
      junit
      junit
      4.12
      test
    
    

    
    
      javax.servlet
      javax.servlet-api
      3.1.0
      provided
    

    
      org.springframework
      spring-webmvc
      4.3.7.RELEASE
    

    
      org.springframework
      spring-web
      4.3.7.RELEASE
    

    
      org.springframework
      spring-context
      4.3.7.RELEASE
    

    
      org.springframework
      spring-core
      4.3.7.RELEASE
    

    
      org.springframework
      spring-jdbc
      4.3.7.RELEASE
    

    
      org.springframework
      spring-beans
      4.3.7.RELEASE
    

    
      org.springframework
      spring-context-support
      4.3.7.RELEASE
    

    
      org.springframework
      spring-expression
      4.3.7.RELEASE
    

    
      org.springframework
      spring-test
      4.3.7.RELEASE
    

    
    
      org.springframework
      spring-aspects
      4.3.7.RELEASE
    

    
      log4j
      log4j
      1.2.14
    

    
    
      org.projectlombok
      lombok
      1.18.12
      provided
    

    
    
      org.mybatis
      mybatis
      3.4.5
    

    
    
      mysql
      mysql-connector-java
      5.1.47
    

    
    
      org.mybatis
      mybatis-spring
      1.3.0
    

    
    
      com.alibaba
      druid
      1.1.10
    

    
    
      com.google.code.gson
      gson
      2.2.4
    

    
    
      org.thymeleaf
      thymeleaf
      3.0.9.RELEASE
    

    
      org.thymeleaf
      thymeleaf-spring4
      3.0.9.RELEASE
    
  

  
    
      
        src/main/resources
        
          ***.xml
        
        true
      
      
        src/main/java
        
          ***.xml
        
        true
      
    
    
      
        org.apache.tomcat.maven
        tomcat7-maven-plugin
        2.2
      
    
  

整合SSM框架

新建 jdbc.properties 数据库连接信息文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/test_ssm_movie?characterEncoding=utf-8&useSSL=false
jdbc.username=root
jdbc.password=root

新建 applicationContext.xml 配置文件




    
    

    
    

    
    
        
        
        
        
    

    
    
        
        
        
        
        
        
    

    
    
        
        
    

    
    
        
        
    

    
    

新建 springmvc.xml 配置文件




    
    

    
    
        
        
        
        
        
        
        
        
        
        
    

    
    
        
    

    
    
        
        
        
    

    
    

    
    

新建 jdbc.properties 日志文件

log4j.rootLogger=OFF, 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

配置 web.xml 配置文件




  Archetype Created Web Application

  
  
    contextConfigLocation
    classpath:applicationContext.xml
  

  
  
  
    characterEncodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
      encoding
      UTF-8
    
  
  
    characterEncodingFilter
    /*
  


  
  
    org.springframework.web.context.ContextLoaderListener
  

  
  
    DispatcherServlet
    org.springframework.web.servlet.DispatcherServlet
    
    
      contextConfigLocation
      classpath:springmvc.xml
    
    
    1
  
  
    DispatcherServlet
    
    
    /
  


测试MyBatis

实现简单登录功能测试

// 登录方法接口
public interface AdminMapper {

    Admin login(Admin admin); // 登录

}


    // 登录功能映射语句
    
        select * from admin where account=#{account} and admin_pwd=#{admin_pwd} and is_delete=1
    

测试类

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class TestMyBatis {
    @Autowired
    AdminService adminService;

    @Test
    public void testLogin(){
        Admin admin = new Admin();
        admin.setAccount("qguicai");
        admin.setAdmin_pwd("123");
        Admin loginAdmin = adminService.login(admin);
        System.out.println(loginAdmin == null?"登录失败":"登录成功");
    }
}

 登录成功,说明数据配置没问题!可以进行下一步

测试Spring、SpringMVC

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    AdminMapper adminMapper;

    @Override
    public Admin login(Admin admin) {
        return adminMapper.login(admin);
    }
}
@Controller
public class AdminController {

    @Autowired
    AdminService adminService;

    @ResponseBody
    @RequestMapping(value = "/admin_login",method = RequestMethod.POST)
    public CommonResult login(Admin admin, HttpSession session) throws IOException {
        CommonResult result = null;    
        Admin loginAdmin = adminService.login(admin);
        if (loginAdmin != null ){
             result = new CommonResult(200,"登录成功!");
        }else{
            result = new CommonResult(500,"账号或密码错误!");
        }       
        return result;
    }
}

使用PostMan进行接口测试

测试通过项目搭建完成!~~~ 2022.6.2

搭建完成的项目结构

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/946654.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号