技术延伸-SSH框架搭建

本文主要简述MAVEN项目SSH(Spring+SpringMVC+Hibernate)框架的搭建:

项目结构:

pom.xml文件

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

4.0.0

com.edison

TSC

0.0.1-SNAPSHOT

war

2.5.10

4.3.8.RELEASE

5.1.7.Final

junit

junit

4.12

test

org.springframework

spring-oxm

$

org.springframework

spring-tx

$

org.springframework

spring-jdbc

$

org.springframework

spring-webmvc

$

org.springframework

spring-aop

$

org.springframework

spring-context-support

$

org.springframework

spring-web

$

org.springframework

spring-test

$

commons-dbcp

commons-dbcp

1.2.2

org.springframework

spring-core

$

org.springframework

spring-web

$

org.springframework

spring-orm

$

struts2-core

$

struts2-spring-plugin

$

org.hibernate

hibernate-core

$

mysql

mysql-connector-java

5.1.42

com.mchange

c3p0

0.9.5

org.aspectj

aspectjweaver

1.8.10

org.slf4j

slf4j-log4j12

1.7.25

commons-fileupload

commons-fileupload

1.3.1

commons-io

commons-io

2.4

commons-codec

commons-codec

1.9

poi

3.17

poi-ooxml

3.17

poi-excelant

3.17

poi-examples

3.17

poi-scratchpad

3.2-FINAL

json-lib

2.4

jdk15

commons-lang3

3.1

commons-beanutils

commons-beanutils

1.8.3

commons-logging

commons-logging

1.1.1

commons-collections

commons-collections

3.2.1

ezmorph

1.0.6

maven-compiler-plugin

3.5.1

1.7

1.7

maven-surefire-plugin

2.19.1

true

3.web.xml文件

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

encodingFilter

true

encoding

UTF-8

encodingFilter

/*

SpringMVC

contextConfigLocation

classpath:applicationContext.xml

1

true

SpringMVC

/

contextConfigLocation

classpath:applicationContext.xml

4.applicationContext.xml 文件

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-4.3.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.xsd">

true

*:表示方法的作用域,*表示所有

*(..):*表示任何方法,(..)表示方法的任何参数

告诉视图解析器,返回的类型为json格式

ModelAndView里的数据变成JSON

-->

5.数据库jdbc.properties 配置文件

jdbc.url=jdbc:mysql://localhost:3306/yqqtptsc?useSSL=true&characterEncoding=UTF-8

jdbc.username=root

jdbc.password=root

6.日志文件配置:log4j.properties

#定义LOG输出级别

log4j.rootLogger=INFO,Console,File

#定义日志输出目的地为控制台

log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.Target=System.out

#可以灵活地指定日志输出格式,下面一行是指定具体的格式

log4j.appender.Console.layout = org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n

#文件大小到达指定尺寸的时候产生一个新的文件

log4j.appender.File = org.apache.log4j.RollingFileAppender

#指定输出目录

log4j.appender.File.File = logs/ssm.log

#定义文件最大大小

log4j.appender.File.MaxFileSize = 10MB

# 输出所以日志,如果换成DEBUG表示输出DEBUG以上级别日志

log4j.appender.File.Threshold = ALL

log4j.appender.File.layout = org.apache.log4j.PatternLayout

log4j.appender.File.layout.ConversionPattern =[%p] [%d][%c]%m%n

上面相关配置文件信息

部分相关Java文件相关代码就不再演示:

import org.springframework.web.bind.annotation.RequestMapping;

/**

* 进入首页,相关报错界面控制层

*

*/

@Controller

public class Welcome {

private static Logger logger=Logger.getLogger(Welcome.class);

@RequestMapping(value={"/","index","index.jsp","index.do","index.*","welcome","welcome.*"})

public String welcome(HttpServletRequest request){

return "index";

}

@RequestMapping(value="/404")

public String notFound(HttpServletRequest request){

logger.info("找不到访问路径:"+request.getRequestURL());

//do something

return "404";

}

}

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20190215G0060X00?refer=cp_1026
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。

扫码关注云+社区

领取腾讯云代金券