springboot学习笔记(二)

1.Springboot过滤器filter
默认启动的Filter
characterEncodingFilter
hiddenHttpMethodFilter
httpPutFormContentFilter
requestContextFilter
Filter优先级
Ordered.HIGHEST_PRECEDENCE
Ordered.LOWEST_PRECEDENCE
低位值意味着更高的优先级 Higher values are interpreted as lower priority
自定义Filter,避免和默认的Filter优先级一样,不然会冲突
注册Filter的bean FilterRegistrationBean
同模块里面有相关默认Filter
web->servlet->filter
自定义Filter
使用Servlet3.0的注解进行配置
启动类里面增加 @ServletComponentScan,进行扫描
新建一个Filter类,implements Filter,并实现对应的接口
@WebFilter 标记一个类为filter,被spring进行扫描 ,urlPatterns:拦截规则,支持正则
控制chain.doFilter的方法的调用,来实现是否通过放行不放行,web应用resp.sendRedirect("/index.html");
场景:权限控制、用户登录(非前端后端分离场景)等
官网地址:
https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-embedded-container-servlets-filters-listeners
自定义Servlet
@WebServlet(name = “userServlet”,urlPatterns = “/test/customs”)
自定义listener
常用的监听器 servletContextListener、httpSessionListener、servletRequestListener
2.Springboot Starter
3.IDEA教程
http://wiki.jikexueyuan.com/project/intellij-idea-tutorial/
IDEA自动编译
File-Settings-Build,Execution,Deployment-Compiler-勾选Build Project automatically
Shift+Ctrl+Alt+/,选择Registry
选 compiler.automake.allow.when.app.running
4.Mysql深度分页
5.Freemarker、thymeleaf整合

org.springframework.boot spring-boot-starter-freemarker Freemarker基础配置 # 是否开启thymeleaf缓存,本地为false,生产建议为true spring.freemarker.cache=false spring.freemarker.charset=UTF-8 spring.freemarker.allow-request-override=false spring.freemarker.check-template-location=true #类型 spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose-session-attributes=true #文件后缀 spring.freemarker.suffix=.ftl #路径 spring.freemarker.template-loader-path=classpath:/templates/ Thymeleaf整合 org.springframework.boot spring-boot-starter-thymeleaf thymeleaf基础配置 官网地址: https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html #开发时关闭缓存,不然没法看到实时页面 spring.thymeleaf.cache=false spring.thymeleaf.mode=HTML5 #前缀 spring.thymeleaf.prefix=classpath:/templates/ #编码 spring.thymeleaf.encoding=UTF-8 #类型 spring.thymeleaf.content-type=text/html #名称的后缀 spring.thymeleaf.suffix=.html 语法地址: https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html 6.Mybatis配置 mybatis 下划线转驼峰配置,两者都可以 #mybatis.configuration.mapUnderscoreToCamelCase=true mybatis.configuration.map-underscore-to-camel-case=true #增加打印sql语句,一般用于本地开发测试 mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl Mybatis教程地址: http://www.mybatis.org/mybatis-3/zh/java-api.html 7.Springboot异步任务 启动类里面使用@EnableAsync注解开启功能,自动扫描 定义异步任务类并使用@Component标记组件被容器扫描,异步方法加上@Async 类上增加@Async则该类对应的方法都可表示为异步执行 注意点: 1)要把异步任务封装到类里面,不能直接写到Controller 2)增加Future 返回结果 AsyncResult("task执行完成"); 3)如果需要拿到结果 需要判断全部的 task.isDone() 通过注入方式,注入到controller里面,如果测试前后区别则改为同步则把Async注释掉 8.Springboot
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值