补充:
- 【SpringMVC学习05】SpringMVC中的参数绑定总结
https://blog.csdn.net/eson_15/article/details/51718633 - 【SpringMVC学习06】SpringMVC中的数据校验
https://blog.csdn.net/eson_15/article/details/51725470 - SpringMVC重要注解(一)@ExceptionHandler和@ResponseStatus
https://blog.csdn.net/lovesomnus/article/details/73188823 - SpringMVC重要注解(二)@ControllerAdvice
https://blog.csdn.net/w372426096/article/details/78429141 - 借助@RequestParam实现上传文件绑定
https://blog.csdn.net/lovesomnus/article/details/78850688 - 【SpringMVC学习08】SpringMVC中实现文件上传
https://blog.csdn.net/eson_15/article/details/51736495
@ResponseBody
@ExceptionHandler(value = { BindException.class })
public Ret handleBindValidException(HttpServletRequest request, BindException c) {
List<ObjectError> errors = c.getBindingResult().getAllErrors();
StringBuffer errorMsg = new StringBuffer();
for (ObjectError error : errors) {
errorMsg.append(error.getDefaultMessage()).append(";");
}
String errorMsgStr = errorMsg.toString();
log.warn("参数校验错误,请求url为: {},参数错误详情: {}", request.getRequestURL().toString(), errorMsgStr);
return Ret.fail401();
}
@ExceptionHandler
@ResponseBody
public Ret handle(HttpServletRequest request, MethodArgumentNotValidException c) {
List<ObjectError> errors = c.getBindingResult().getAllErrors();
StringBuffer errorMsg = new StringBuffer();
for (ObjectError error : errors) {
errorMsg.append(error.getDefaultMessage()).append(";");
}
String errorMsgStr = errorMsg.toString();
log.warn("参数校验错误,请求url为: {},参数错误详情: {}", request.getRequestURL().toString(), errorMsgStr);
return Ret.fail401();
}
@ResponseBody
@ExceptionHandler(value = { ConstraintViolationException.class })
public Ret handleMethodValidException(HttpServletRequest request, ConstraintViolationException c) {
log.warn("参数校验错误,请求url为: {},参数错误详情: {}", request.getRequestURL().toString(), c.getMessage());
return Ret.fail401();
}
@ResponseBody
@ExceptionHandler(value = { MissingServletRequestParameterException.class })
public Ret handleRequestParameterMissValidException(HttpServletRequest request,
MissingServletRequestParameterException c) {
log.warn("参数不全错误,请求url为: {},参数错误详情: {}", request.getRequestURL().toString(), c.getMessage());
return Ret.fail401();
}
1. web.xml
- 编码过滤
- mvc核心DispatcherServlet
- mvc配置文件位置
- mvc拦截请求
- Druid核心Servlet
- druid请求路径
- druid请求过滤,并排除静态资源
- druid过滤路径
2. db.properties
3. log4j.properties
log4j.rootLogger=INFO,console,dailyFile
#dailyFile,rollingFile,logFile
log4j.additivity.org.apache=true
# 控制台(console)
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Threshold=DEBUG
log4j.appender.console.ImmediateFlush=true
log4j.appender.console.Target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] %m%n
# 日志文件(logFile)
log4j.appender.logFile=org.apache.log4j.FileAppender
log4j.appender.logFile.Threshold=INFO
log4j.appender.logFile.ImmediateFlush=true
log4j.appender.logFile.Append=true
log4j.appender.logFile.File=P:/log/log4j.log
log4j.appender.logFile.layout=org.apache.log4j.PatternLayout
log4j.appender.logFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] %m%n
# 滚动文件(rollingFile)
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.Threshold=INFO
log4j.appender.rollingFile.ImmediateFlush=true
log4j.appender.rollingFile.Append=true
log4j.appender.rollingFile.File=P:/log/log4j.log
log4j.appender.rollingFile.MaxFileSize=200KB
log4j.appender.rollingFile.MaxBackupIndex=50
log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] %m%n
# 定期滚动日志文件(dailyFile)
log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.dailyFile.Threshold=INFO
log4j.appender.dailyFile.ImmediateFlush=true
log4j.appender.dailyFile.Append=true
log4j.appender.dailyFile.File=P:/log/log4j.log
log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd
log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout
log4j.appender.dailyFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] %m%n
4. applicationContext.xml
- 命名空间
- 事务注解扫描
- spring bean自动装配扫描
- 获取db.properties文件内容
- 多druid dataSource配置
- dao层bean自动注入
- dao层接口扫描
- 多数据源sqlSessionFactory配置
- mapper.xml扫描
- 配置多数据源事务管理器、事务管理行为、事务切入点
5. spring-mvc.xml
- mvc命名空间
- 自动注入controller bean
- 静态资源视图解析器
- 视图资源解析
- @RequestMapping RequestMappingHandlerMapping
-
请求返回字符串编码
-
JSON转换器编码 MappingJackson2HttpMessageConventer
-
上传文件配置
-
借助@RequestParam实现上传文件绑定
https://blog.csdn.net/lovesomnus/article/details/78850688
6. Mybatis.xml
*7. Mapper.xml
- 一个一对多映射
- 关联查询多list
- 一对多,多的查询语句