基于maven搭建一个ssm的web项目的详细图文教程

1:使用idea建立一个web项目

基于maven搭建一个ssm的web项目的详细图文教程_第1张图片

2:引入pom依赖


 4.0.0
 com.frame
 ssm
 0.0.1-SNAPSHOT
 war

 
  UTF-8
  5.2.8.RELEASE
  1.8.13
  2.9.1
  1.2.3
 

 
  
  
   commons-fileupload
   commons-fileupload
   1.3.3
  
  
   commons-io
   commons-io
   2.5
  
  
   org.apache.commons
   commons-lang3
   3.6
  

  
  
   org.springframework
   spring-aspects
   ${spring.framework.version}
  
  
   org.springframework
   spring-context
   ${spring.framework.version}
  
  
   org.springframework
   spring-jdbc
   ${spring.framework.version}
  
  
   org.springframework
   spring-webmvc
   ${spring.framework.version}
  
  
   org.springframework
   spring-context-support
   ${spring.framework.version}
  

  
  
   org.aspectj
   aspectjweaver
   ${aspectj.version}
  
  
   org.aspectj
   aspectjrt
   ${aspectj.version}
  

  
  
   org.mybatis
   mybatis
   3.5.5
  
  
   org.mybatis
   mybatis-spring
   1.3.1
  

  
  
   com.alibaba
   druid
   1.1.9
  

  
  
   mysql
   mysql-connector-java
   5.1.46
  

  
  
   com.fasterxml.jackson.core
   jackson-databind
   2.11.1
  

  
  
   javax.servlet
   javax.servlet-api
   3.1.0
  

  
  
   javax.servlet
   jstl
   1.2
  

  
  
   ch.qos.logback
   logback-classic
   ${logback.version}
  

  
   org.projectlombok
   lombok
   1.18.12
   provided
  

  
  
  
  ch.qos.logback
  logback-classic
  1.1.11
 
 
  org.logback-extensions
  logback-ext-spring
  0.1.1
 
 
  org.slf4j
  jcl-over-slf4j
  1.7.25
 
 

 
  
   
    org.apache.maven.plugins
    maven-compiler-plugin
    3.8.1
    
     1.8
     1.8
    
   
  
 

3: 在src/main新建java和resource文件夹

1:将java文件夹marked directory as source root
2:将resource新建resource文件夹

4:在resource新建以下文件

基于maven搭建一个ssm的web项目的详细图文教程_第2张图片

5:spring配置文件applicationContent.xml配置




  
  

  
  
  
    
    
    
    
    
  
  
  
    
    
      
        classpath:mapper/*Mapper.xml
      
    
  
  
  
    
  

  
  
    
  
  
  
    
      
      
      
      
    
  
  
  
    
    
  
  
  

6:springMVC配置文件




  
  
    
    
    
    
  

  
  
  
  
  
    
      
        
        
          
            
              text/html; charset=UTF-8
              application/json;charset=UTF-8
            
          
        
        
        
          
            
              text/html; charset=UTF-8
              application/json;charset=UTF-8
            
          
        
      
    
  

7:jdbc.properties配置文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
jdbc.username=axin
jdbc.password=19950925

8:log4j.properties配置文件

log4j.rootLogger=DEBUG,stdout
log4j.logger.com.mchange.v2 = INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n

9:logback.xml配置文件



  
   
   
   
   
   

  
  
    
      %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method\(\):%L -%msg%n
    
  

  
  
    ${log.base}/${log.moduleName}.log
    
    
      ${log.base}/archive/${log.moduleName}_all_%d{yyyy-MM-dd}.%i.log.zip
      
      
      
        ${log.max.size}
      
    
    
    
      %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method\(\):%L -%msg%n
    
  

  
  
    ${log.base}/${log.moduleName}_other.log
    
      ${log.base}/archive/${log.moduleName}_other_%d{yyyy-MM-dd}.%i.log.zip
      
      
        ${log.max.size}
      
    
    
      %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{56}.%method\(\):%L -%msg%n
    
  

  
  
    ${log.base}/${log.moduleName}_err.log
    
      ${log.base}/archive/${log.moduleName}_err_%d{yyyy-MM-dd}.%i.log.zip
      
      
        ${log.max.size}
      
    
    
      %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{56}.%method\(\):%L - %msg%n
    
    
    
      ERROR
      ACCEPT
      DENY
    
  

  
  
  
  
    0
    256
    true
    
  

  
    0
    256
    true
    
  

  
  
    
    
    
    
  
  
    
  

  
    
  
  
  
     
    
    
  

10 mappera.xml配置




  
    
    
    
    
    
    
  
  

配置webapp下的文件 web.xml的配置



 ssm

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

 
 
  springMVC
  org.springframework.web.servlet.DispatcherServlet
  
   contextConfigLocation
   classpath:conf/spring-mvc.xml
  
  1
 
 
  springMVC
  /
 

 
 
 
  contextConfigLocation
  classpath:conf/applicationContext.xml
 
 
 
  org.springframework.web.context.ContextLoaderListener
 

 
  logbackConfigLocation
  classpath:log/logback.xml
 
 
  ch.qos.logback.ext.spring.web.LogbackConfigListener
 


 
 
  jsp/index.jsp
 

hello.jsp



Hello axin! ${aaa}

java案例

基于maven搭建一个ssm的web项目的详细图文教程_第3张图片

DemoController.java

package com.ssm.demo.controller;


import com.ssm.demo.entity.User;
import com.ssm.demo.service.DemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class DemoController {

  @Resource
  private DemoService demoService;

  private static final Logger LOG = LoggerFactory.getLogger(DemoController.class);

  @RequestMapping("/hello")
  public User hello() {
    LOG.info("输出日志");
    User test = demoService.test();
    return test;
  }
}

User.java

package com.ssm.demo.entity;

import lombok.*;

@ToString
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class User {
  private int id;
  private String name;
}

DemoService.java

package com.ssm.demo.service;

import com.ssm.demo.entity.User;

public interface DemoService {
    User test();
}

DemoServiceImpl.java

package com.ssm.demo.service.impl;


import com.ssm.demo.entity.User;
import com.ssm.demo.service.DemoService;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service("demoService")
public class DemoServiceImpl implements DemoService {

  @Autowired
  private SqlSessionTemplate sqlSessionTemplate;

  // mybatis sql模板的命名空间
  private static final String NAMESPACE = "com.frame.mapper.DemoMapper";

  @Override
  public User test() {
    return (User)sqlSessionTemplate.selectOne(NAMESPACE + ".getTest");
  }
}

配置tomcat

基于maven搭建一个ssm的web项目的详细图文教程_第4张图片

选择tomcat Server

基于maven搭建一个ssm的web项目的详细图文教程_第5张图片

配置好项目的application context,即访问路径

基于maven搭建一个ssm的web项目的详细图文教程_第6张图片

启动tomcat

基于maven搭建一个ssm的web项目的详细图文教程_第7张图片

访问

输入:http://localhost:8080/ssm/

基于maven搭建一个ssm的web项目的详细图文教程_第8张图片

输入:http://localhost:8080/ssm/hello

基于maven搭建一个ssm的web项目的详细图文教程_第9张图片

总结

到此这篇关于基于maven搭建一个ssm的web项目的详细图文教程的文章就介绍到这了,更多相关maven搭建ssm的web项目内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(基于maven搭建一个ssm的web项目的详细图文教程)