网站建设资讯

NEWS

网站建设资讯

怎么快速搭建一个SSM框架

怎么快速搭建一个SSM框架?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

创新互联是专业的绛县网站建设公司,绛县接单;提供成都做网站、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行绛县网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

一、我用的是idea

二、首先创建一个maven项目,结构如下:

怎么快速搭建一个SSM框架

三、开始写配置文件

怎么快速搭建一个SSM框架

pom文件


 4.0.0
 com.xxx.demo
 ssm
 war
 1.0-SNAPSHOT
 ssm Maven Webapp
 http://maven.apache.org

 
  UTF-8
  UTF-8
  
  4.2.6.RELEASE

  
  3.2.8

  
  5.1.29

  
  1.7.18
  1.2.17
 


 
  
  
   jstl
   jstl
   1.2
  

  
   javax
   javaee-api
   7.0
  

  
  
   junit
   junit
   4.11
   
   test
  

  
  
   org.springframework
   spring-core
   ${spring.version}
  
  
   org.springframework
   spring-web
   ${spring.version}
  
  
   org.springframework
   spring-oxm
   ${spring.version}
  
  
   org.springframework
   spring-tx
   ${spring.version}
  
  
   org.springframework
   spring-jdbc
   ${spring.version}
  
  
   org.springframework
   spring-webmvc
   ${spring.version}
  
  
   org.springframework
   spring-context
   ${spring.version}
  
  
   org.springframework
   spring-aspects
   4.3.8.RELEASE
  
  
   org.springframework
   spring-context-support
   ${spring.version}
  
  
   org.springframework
   spring-aop
   ${spring.version}
  

  
   org.springframework
   spring-test
   ${spring.version}
  

  
  
   org.mybatis
   mybatis
   ${mybatis.version}
  

  
  
   org.mybatis
   mybatis-spring
   1.2.2
  

  
  
   mysql
   mysql-connector-java
   ${mysql-driver.version}
  
  
  
   com.alibaba
   druid
   1.1.3
  

  
  
   com.alibaba
   fastjson
   1.1.41
  

  
  
   log4j
   log4j
   ${log4j.version}
  
  
   org.slf4j
   slf4j-api
   ${slf4j.version}
  
  
   org.slf4j
   slf4j-log4j12
   ${slf4j.version}
  

  
  
  
   org.codehaus.jackson
   jackson-mapper-asl
   1.9.13
  
  
  
   com.fasterxml.jackson.core
   jackson-core
   2.8.0
  
  
  
   com.fasterxml.jackson.core
   jackson-databind
   2.8.0
  

  
   commons-fileupload
   commons-fileupload
   1.3.1
  

  
   commons-io
   commons-io
   2.4
  

  
   commons-codec
   commons-codec
   1.9
  
  
   org.aspectj
   aspectjweaver
   1.8.10
  
 
 
  ssm
 

db.properties

db.Driver=com.mysql.jdbc.Driver
db.Url=jdbc:mysql://localhost:3306/myuser?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull 
db.username=root
db.password=xxxxxxxxxxxxx

#定义初始连接数
db.initialSize=1 
#定义最大连接数
db.maxActive=20 
#定义最大空闲
db.maxIdle=20 
#定义最小空闲
db.minIdle=1 
#定义最长等待时间
db.maxWait=60000
#使用非公平锁
db.useUnfairLock=true
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
db.timeBetweenEvictionRunsMillis=60000
#配置一个连接在池中最小生存的时间,单位是毫秒
db.minEvictableIdleTimeMillis=300000

db.validationQuery=SELECT 'x'
#申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
db.testWhileIdle=true
#申请连接时执行validationQuery检测连接是否有效
db.testOnBorrow=false
#归还连接时执行validationQuery检测连接是否有效
db.testOnReturn=false
#打开PSCache,并且指定每个连接上PSCache的大小
db.poolPreparedStatements=true
db.maxOpenPreparedStatements=20
#配置监控统计拦截的filters,去掉后监控界面sql无法统计
db.filters=start

log4j.properties

log4j.rootLogger=DEBUG,CONSOLE,FILEOUT 
log4j.addivity.org.apache=true 

# CONSOLE 打印到控制台
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 
log4j.appender.Threshold=DEBUG 
log4j.appender.CONSOLE.Target=System.out 
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 
log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH\:mm\:ss} \:%m%n 

#
# FILEOUT 打印到 D\:\\report.log
log4j.appender.FILEOUT=org.apache.log4j.RollingFileAppender 
log4j.appender.FILEOUT.File=D\:\\report.log 
log4j.appender.FILEOUT.layout=org.apache.log4j.PatternLayout 
log4j.appender.fileout.MaxFileSize=100000KB 

log4j.appender.FILEOUT.Append=true 
#log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d \u2013 %c -%-4r [%t] %-5p %c %x \u2013 %m%n
log4j.appender.FILEOUT.layout.ConversionPattern=[%-5p]_%d{yyyy-MM-dd HH\:mm\:ss} \:%m%n

UserMapper.xml配置

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



 
  
  
  
 
 

sp-mybatis配置

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


 
 

 

 
 
  
  
  
  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
 

 
 
  
  
 

 
 
  
  
 


sp-service.xml

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



 
 

sp-trans.xml配置

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


 
 
  
 


 
 

 
 
  
   
   
   
   
   
   
   
   
   
   
   
   

   
   
   
   
   

   
  
 
 
  
  
 


 
 
 
 
  
   
    com.ssm.service.*
   
  
 
 
  
 

Springmvc配置

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

 
 
 

 
 

 
 
  
  
 

 
 
  
  
  
  
  
  
 


web.xml配置




 Archetype Created Web Application


 
  log4jConfigLocation
  classpath:log4j.properties
 

 
  contextConfigLocation
  classpath:spring/sp-*.xml
 

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

 

 
 
  org.springframework.web.context.ContextLoaderListener
 


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

 
  springmvc
  /
 

 
 
  15
 

然后基本框架已经配置好了,剩下的就是写java代码了

Controller

package com.ssm.controller;

import com.ssm.pojo.User;
import com.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author: hsj
 * @Date: 2017/9/15
 * @Description :
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

 @Resource
 private UserService userService;

 @RequestMapping(value = "user")
 @ResponseBody
 public User getUser(int userId){
  return userService.findUserById(userId);
 }
}

Service

package com.ssm.service;

import com.ssm.pojo.User;
import org.springframework.stereotype.Service;

/**
 * @author: hsj
 * @Date: 2017/9/15
 * @Description :
 */
public interface UserService {
 User findUserById(int userId);
}

ServiceImpl

package com.ssm.service.impl;

import com.ssm.dao.UserDao;
import com.ssm.pojo.User;
import com.ssm.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: hsj
 * @Date: 2017/9/15
 * @Description :
 */
@Service
public class UserServiceImpl implements UserService {

 @Resource
 private UserDao userDao;

 public User findUserById(int userId) {
  return userDao.seleceUserById(userId);
 }
}

pojo

package com.ssm.pojo;

/**
 * @author: hsj
 * @Date: 2017/9/18
 * @Description :这是一个User实体类
 */
public class User {
 private int id;
 private String username;
 private String password;

 public int getId() {
  return id;
 }

 public void setId(int 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;
 }

 @Override
 public String toString() {
  return "User{" +
    "id=" + id +
    ", username='" + username + '\'' +
    ", password='" + password + '\'' +
    '}';
 }
}

dao

package com.ssm.dao;

import com.ssm.pojo.User;
import org.springframework.stereotype.Repository;

/**
 * @author: hsj
 * @Date: 2017/9/15
 * @Description :
 */

@Repository
public interface UserDao {
 User seleceUserById(int userId);
}

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。


网站栏目:怎么快速搭建一个SSM框架
分享网址:http://cdweb.net/article/jesjjo.html