书接上回,把Hello World 在页面上显示! 1.在pom文件中加入web支持 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 注意:加入spring-boot-starter-web就可以把spring-boot-starter删除了,s…
springboot编程之全局异常捕获 1.创建GlobalExceptionHandler.java,在类上注解@ControllerAdvice, 在方法上注解@ExceptionHandler(value = Exception.class),Exception.class表示拦截所有的异常信息 package com.imooc.web.controller; import com.imooc.exception.UserNotExistException; import org.spr…
在我们访问页面的时候经常会遇到各种问题,比如404,400,500,502等等,可返回的错误页对用户来讲,并不太亲民,所以要定制一下自己的错误页. 我们先访问一个错误页面,看下效果:(虽然给我们提供了错误时间.类型.状态码.错误信息,但是好丑,而且用户也不知道这是什么意思) 如果定制呢?我们下边介绍两个定制化的地方. 定制错误页面 1. 对于SpringBoot来说,它默认会帮我们查找对应的错误页面,也就是说,如果在模板引擎里没有找到匹配的页面,他就对应状态码来展示错误页,例如: 访问页面是40…
目录 一. springboot总览 1.springboot特性 2.准备运行环境 二.理解独立的spring应用 1.应用类型 2.@RestController 3.官网创建springboot应用 4.基础的start依赖 5.springboot打包 6.springboot的jar文件 三.理解固话的Maven依赖 1.spring-boot-starter-parent与spring-boot-dependencies 四.理解嵌入式Web容器 1. tomcat容器 2. jet…
这篇文章我们来学习如何使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉及到这方面的需求.在Java领域一般有Spring Security.Apache Shiro等安全框架,但是由于Spring Security过于庞大和复杂,大多数公司会选择Apache Shiro来使用,这篇文章会先介绍一下Apache Shiro,在结合Spring Boot给出使用案例. Apache Shiro What is Apache Shiro?…
此文系参考网络大牛的,如有侵权,请见谅! Spring Boot应用启动器基本的一共有N(现知道的是44)种:具体如下: 1)spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2)spring-boot-starter-actuator 帮助监控和管理应用. 3)spring-boot-starter-amqp 通过spring-rabbit来支持AMQP协议(Advanced Message Queuing Protocol).…
spring boot使用application.properties默认了很多配置.但需要自己添加一些配置的时候,可以这样用,如下! 在application.properties文件中增加信息 1.在application.properties配置文件增加 ##自定义属性 rick.name=rick rick.age=30 2.自定义配置类RickProperties package com.rick.common.properties; import org.springframewor…
springboot定时任务,比较简单! 1.编写DemoSchedule.java类 package com.rick.common.schedule; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annota…
Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConfiguration 中的配置各种属性. 建议大家使用Spring Boot的默认配置方式,如果需要特殊处理的再通过配置进行修改. 如果想要自己完全控制WebMVC,就需要在@Configuration注解的配置类上增加 @EnableWebMvc(@SpringBootApplication 注解的程序入口类已经包含@Configuration),增加该注解以后WebMvcAutoConfiguration中…
静态错误页放在         动态可以放在freemaker或者thymeleaf         匹配规则: 先找动态页面再找静态页面 先找精确错误页面再找模糊页面     注:精确错误页面=500.html/400html 模糊页面=5xx.html/4xx.html…