资讯专栏INFORMATION COLUMN

SSM框架整合

twohappy / 2804人阅读

摘要:整合项目结构导入版本号相关包相关包相关包相关包数据库连接池集成标准标签库日志相关包单元测试相关包里面为空开发环境下,日志级别设置

ssm整合项目结构

Maven导入jar

pom.xml




    4.0.0

    cn.scitc
    Test
    1.0-SNAPSHOT
    war


    
        UTF-8
        
        4.3.8.RELEASE
    

    
        
        
            org.springframework
            spring-core
            ${spring.version}
        
        
            org.springframework
            spring-aop
            ${spring.version}
        
        
            org.springframework
            spring-web
            ${spring.version}
        
        
            org.springframework
            spring-webmvc
            ${spring.version}
        
        
            org.springframework
            spring-jdbc
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        

        
        
            org.aspectj
            aspectjrt
            1.8.0
        
        
            org.aspectj
            aspectjweaver
            1.8.0
        

        
        
            org.mybatis
            mybatis
            3.3.0
        
        
        
            mysql
            mysql-connector-java
            8.0.15
        
        
        
            com.alibaba
            druid
            1.0.20
        

        
        
            org.mybatis
            mybatis-spring
            1.2.3
        

        
        
            javax.servlet
            jstl
            1.2
        

        
        
            log4j
            log4j
            1.2.17
        
        
            org.slf4j
            slf4j-api
            1.7.21
        

        
        
            junit
            junit
            4.11
            test
        
    
    
        Test
    

Mybatis

sqlMapConfig.xml里面为空

db.properties

jdbc.url=jdbc:mysql://localhost:3306/bigData1701?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.user=user
jdbc.password=123

log4j.properties

# Global logging configuration
#开发环境下,日志级别设置为DEBUG,生产环境info或者error
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
Spring

applicationContext-dao.xml




    
    
    
    
        
        
        
        
    

    
    
        
        
        
        
        
        
        
    

    
    
        
        
    

applicationContext-service.xml



    
    

applicationContext-transaction.xml




    
    
        
        
    
    
        
            
        
    

    
    
        
    
Springmvc

springmvc.xml



    
    
    
    
    
    
        
        
    
web.xml

web.xml配置如下代码



    
    
        contextConfigLocation
        classpath:spring/applicationContext-*.xml
    
    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
    
    
        encodingFilter
        /*
    

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

配置完成,编写代码测试

pojo

package cn.scitc.test.pojo;

import java.util.Date;

public class Student {
    private Integer id;
    private String name;
    private Date birthday;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
}

StudentMapper

public interface StudentMapper {
    List queryStudentAll();
}

StudentMapper.xml




    

StudentService

public interface StudentService {
    List queryStudentAll();
}

StudentServiceImpl

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List queryStudentAll() {
        return studentMapper.queryStudentAll();
    }
}

StudentController

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/query")
    public String query(Model model) {
        List studentList =  studentService.queryStudentAll();
        model.addAttribute("studentList",studentList);
        return "test";
    }
}

jsp页面显示



        
id name birthday

注意导入的标签库为:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>  //fmt会报错

运行测试成功:

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/77635.html

相关文章

  • 从零开始搭建SSM框架(Spring + Spring MVC + Mybatis)

    摘要:打开,,选中,然后再选中,输入项目的和,指定等配置,修改,打开项目,添加一些必要的目录,最终项目框架目录图如下修改文件,指定各依赖和插件的版本等信息在标签里面管理各依赖的版本号添加项目依赖管理依赖配置好之后,开始整合。 最近在回顾和总结一些技术,想到了把之前比较火的 SSM 框架重新搭建出来,作为一个小结,同时也希望本文章写出来能对大家有一些帮助和启发,因本人水平有限,难免可能会有一些...

    MiracleWong 评论0 收藏0
  • Maven多模块项目搭建+整合SSM框架

    摘要:继承作用就是避免配置重复,对于子项目来说应该关心父项目是怎么样配置的。聚合字面理解就是聚在一起合作完成工作,就是将子模块聚集起来完成相应的项目需求父工程的搭建项目结构在父工程中,主要负责完成依赖的版本管理,并不是实际的依赖。 从大二开始就一直关注segmentFault,在问题专区帮忙回答一些自己知晓的问题;在写这篇文章之前我一直会在朋友圈发一些自己遇到的问题以及解决办法,这是第一次写...

    liaosilzu2007 评论0 收藏0
  • ssm框架整合

    ssm整合 开发环境ide,mysql数据库,Spring+SpringMVC+Mybatis,tomcat8.5,jdk使用的是1.7版本。 第一步:导入jar包 Spring+ SpringMVC + MyBatis + Mybatis-spring整合包 AOP联盟+织入 + c3p0 数据库连接池 + MySQL连接驱动 + jstl 链接:https://pan.baidu.com/...

    Simon_Zhou 评论0 收藏0

发表评论

0条评论

twohappy

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<