SpringBoot2
SpringBoot2
唐火
开始人工智能之路了!!!
展开
-
[SpringBoot2]数据访问_数据库场景的自动配置分析和整合测试
数据访问1、导入jdbc场景 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jdbc</artifactId> </dependency> 数据库驱动?为什么导入JDBC场景,官方不导入驱动?原创 2022-03-02 12:58:29 · 69 阅读 · 0 评论 -
[SpringBoot2]定制化原理_SpringBoot定制化组件的几种方式
定制化原理定制化的常见方式● 修改配置文件;● xxxxxCustomizer;● 编写自定义的配置类 xxxConfiguration;+ @Bean替换、增加容器中默认组件;视图解析器● Web应用 编写一个配置类实现 WebMvcConfigurer 即可定制化web功能;+ @Bean给容器中再扩展一些组件@Configurationpublic class AdminWebConfig implements WebMvcConfigurer● @EnableWebMvc +转载 2022-03-02 12:58:01 · 166 阅读 · 0 评论 -
[SpringBoot2]原生组件注入_原生注解与Spring方式注入
1、使用Servlet API@ServletComponentScan(basePackages = “com.atguigu.admin”):指定原生Servlet组件都放在那里@WebServlet(urlPatterns ="/my"):效果:直接响应,没有经过Spring的拦截器?@WebFilter(urlPatterns={"/css/","/images/"})@WebListener@ServletComponentScan(basePackages = "com.atgu原创 2022-03-02 12:57:52 · 163 阅读 · 0 评论 -
[SpringBoot2]错误处理_默认规则
错误处理默认规则● 默认情况下,Spring Boot提供/error处理所有错误的映射● 对于机器客户端,它将生成JSON响应,其中包含错误,HTTP状态和异常消息的详细信息。对于浏览器客户端,响应一个“ whitelabel”错误视图,以HTML格式呈现相同的数据● 要对其进行自定义,添加View解析为error● 要完全替换默认行为,可以实现 ErrorController 并注册该类型的Bean定义,或添加ErrorAttributes类型的组件以使用现有机制但替换其内容。● err原创 2022-03-01 00:01:31 · 84 阅读 · 0 评论 -
[SpringBoot2]文件上传_单文件与多文件上传的使用
<form role="form" th:action="@{/upload}" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="exampleInputEmail1">邮箱</label> ...原创 2022-01-26 09:43:43 · 85 阅读 · 0 评论 -
[SpringBoot2]拦截器
拦截器1.编写一个拦截器实现HandlerInterceptor接口2.拦截器注册到容器中(实现WebMvcConfigurer的addInterceptors)3.指定拦截规则[如果是拦截所有,静态资源也会被拦截]/** * 登陆检查 * 1.配置好拦截器要拦截哪些请求 * 2.把这些配置放在容器中 */@Slf4jpublic class LoginInterceptor implements HandlerInterceptor { /** *原创 2022-03-01 00:01:28 · 252 阅读 · 0 评论 -
[SpringBoot2]Thymeleaf
引入starter <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>自动配置好了thymeleaf@Configuration(proxyBea.原创 2022-03-01 00:01:20 · 161 阅读 · 0 评论 -
[SpringBoot2]@MatrixVariable&UrlPathHelper
场景页面开发,cookie禁用了,session里面的内容怎么使用:session.set(a,b)—>jessionid—>cookie—>每次发请求携带此时cookie禁用了,我们要怎么得到session里面的内容呢?url重写:/abc;jsessionid=xxxx 把cookie的值使用矩阵变量的方式进行传递1、语法: 请求路径:/cars/sell;low=34;brand=byd,audi,yd2、SpringBoot默认是禁用了矩阵变量的功能手动开启:.原创 2022-03-01 00:01:15 · 220 阅读 · 0 评论 -
[SpringBoot2]常用参数注解使用
url:localhost:8080/car/3/owner/lisi?age=18&inters=basketball&inters=game@RestControllerpublic class ParameterTestController { // car/2/owner/zhangsan @GetMapping("/car/{id}/owner/{username}") public Map<String,Object> getCa.原创 2022-03-01 00:01:08 · 79 阅读 · 0 评论 -
[SpringBoot2]请求处理_@RequestAttribute
@Controllerpublic class RequestController { @GetMapping("/goto") public String gotoPage(HttpServletRequest request) { request.setAttribute("msg","success"); request.setAttribute("code",200); return "forward:/success";原创 2022-03-01 00:01:03 · 202 阅读 · 0 评论 -
[SpringBoot2]welcome&favicon
awdsfdg原创 2022-03-15 12:59:29 · 138 阅读 · 0 评论 -
[SpringBoot2]web场景_静态资源规则与定制化
静态资源目录只要静态资源放在类路径下: called /static (or /public or /resources or/META-INF/resources 访问 : 当前项目根路径/ + 静态资源名原理: 静态映射/**。请求进来,先去找Controller看能不能处理。不能处理的所有请求又都交给静态资源处理器。静态资源也找不到则响应404页面改变默认的静态资源路径spring: mvc: static-path-pattern: /res/**原创 2022-02-06 15:24:54 · 52 阅读 · 0 评论 -
[SpringBoot2]web场景_SpringBoot2_SpringMVC自动配置概览
Spring Boot provides auto-configuration for Spring MVC that works well with most applications.(大多场景我们都无需自定义配置)The auto-configuration adds the following features on top of Spring’s defaults:● Inclusion of ContentNegotiatingViewResolver and BeanNameViewRe.转载 2022-02-06 15:24:49 · 94 阅读 · 0 评论 -
[SpringBoot2]yaml
简介YAML 是 “YAML Ain’t Markup Language”(YAML 不是一种标记语言)的递归缩写。在开发的这种语言时,YAML 的意思其实是:“Yet Another Markup Language”(仍是一种标记语言)。非常适合用来做以数据为中心的配置文件基本语法● key: value;kv之间有空格● 大小写敏感● 使用缩进表示层级关系● 缩进不允许使用tab,只允许空格● 缩进的空格数不重要,只要相同层级的元素左对齐即可● '#‘表示注释● 字符串无需加引号,如转载 2022-02-06 15:24:41 · 60 阅读 · 0 评论 -
[SpringBoot2]dev-tools
引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>项目或者页.原创 2022-02-06 15:24:27 · 277 阅读 · 0 评论 -
[SpringBoot2]Lombok
引入依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency>idea中搜索安装lombok插件===============================简化JavaBean开发===========.原创 2022-02-06 15:24:30 · 98 阅读 · 0 评论 -
[SpringBoot2]SpringBoot应用如何编写
最佳实践● 引入场景依赖○ https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter● 查看自动配置了哪些(选做)○ 自己分析,引入场景对应的自动配置一般都生效了○ 配置文件中debug=true开启自动配置报告。Negative(不生效)\Positive(生效)● 是否需要修改○ 参照文档修改配置项■ https://docs.sprin转载 2022-02-06 15:24:04 · 74 阅读 · 0 评论 -
[SpringBoot2]容器功能_底层注解&配置绑定_@Configuration&@Import&@Conditional&@ImportResource&
@Configuration&@Bean告诉SpringBoot这是一个配置类==配置文件#############################Configuration使用示例######################################################/** * 1、配置类里面使用@Bean标注在方法上给容器注册组件,默认也是单实例的 * 2、配置类本身也是组件 * 3、proxyBeanMethods:代理bean的方法 * Ful原创 2022-02-06 15:24:08 · 267 阅读 · 0 评论 -
[SpringBoot2]自动配置
自动配置● 自动配好Tomcat引入Tomcat依赖。配置Tomcat<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>2.3.4.RELEASE</version> <sco原创 2022-02-06 15:24:11 · 74 阅读 · 0 评论 -
[SpringBoot2]依赖管理
依赖管理父项目做依赖管理<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version></parent>他的父项目 <parent原创 2022-02-06 15:24:14 · 135 阅读 · 0 评论 -
[SpringBoot2]HelloWorld
导入依赖<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> </parent> <dependencies>.原创 2022-02-06 15:23:48 · 57 阅读 · 0 评论 -
[SpringBoot2]ajax函数中data参数的数据设置方式
ajax函数中data参数的数据设置方式:原创 2022-01-21 09:46:34 · 410 阅读 · 0 评论