文章目录
spring mvc 日志开启
1.log4j 配置修改logger.org.springframework.web日志级别,打印详细web 请求/响应日志信息
log4j配置:
log4j.logger.org.springframework.web=debug
logback配置:
<logger name="org.springframework.web" level="DEBUG" />
控制台响应显示:
[时间:2017-02-09 04:54:13] [级别:DEBUG] [类:org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor] [消息:Written [{status=500, success=false, msg=验证码不正确,请重新输入}] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@6e5ea41d]]
这样在开发时候就不用每次去浏览器控制台查看,后台到底响应的什么数据内容。test updateddd
spring mvc get数组查询注意
如果是List 必须加@RequestParam否则无法注入
前端请求

后端写法
// 可以接受请求
@GetMapping("/testArray1")
public String testArray1(String[] array) throws BusinessException {
return MessageEnum.HELLO_ERROR.simpleInfo();
}
// 可以接受请求
@GetMapping("/testArray11")
public String testArray11(@RequestParam String[] array) throws BusinessException {
return MessageEnum.HELLO_ERROR.simpleInfo();
}
// 不能接收请求
@GetMapping("/testArray2")
public String testArray2(List<String> list) throws BusinessException {
return MessageEnum.HELLO_ERROR.simpleInfo();
}
// 可以接受请求
@GetMapping("/testArray22")
public String testArray22(@RequestParam List<String> list) throws BusinessException {
return MessageEnum.HELLO_ERROR.simpleInfo();
}
log4j.properties常用配置
log4j.rootLogger=debug,stdout
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}] [级别\:%p] [类\:%c] [消息\:%m] %n
maven tomcat:run
maven插件配置
<!--插件管理-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- tomcat7插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<uriEncoding>${project.build.sourceEncoding}</uriEncoding>
</configuration>
</plugin>
</plugins>
</build>
运行项目
tomcat7:run

启动报错注意
启动报错servlet-api 可能会冲突 修改scope为provided (注意可能有多个servlet, 全项目搜索)
<!--ServletAPI依赖包-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
相关参考:https://blog.51cto.com/u_12203282/6000583
本文介绍如何在SpringMVC中配置log4j以获取详细的Web请求及响应日志信息,并讨论了使用GET方法进行数组查询时需要注意的问题。
6104

被折叠的 条评论
为什么被折叠?



