单例模式---饿汉式
package com.golf;
/**
* 单例模式——饿汉式
* @author 26920
*
*/
public class SingletonDemo01 {
//类加载时初始化该对象,线程安全,跟Java类加载器加载过程有关,效率高,没有延迟加载
private static SingletonDemo01 instance=new SingletonDemo01();...
单例模式——静态内部类
有延迟加载,线程安全,效率高
package com.golf;
/**
* 单例模式——静态内部类
* @author 26920
*
*/
public class SingletonDemo03 {
//有延迟加载,线程安全,效率高
private static class nestClass{
private static SingletonDemo03 instanc...
springboot整合filter之在filter中如何获取spring容器中的bean对象
本人在项目使用的是springboot,具业务需要本人使用了filter过滤器,进行一个路径拦截,本人配置的是拦截所有/*,然后对路径中包含的特有字段进行处理。
filter中需要使用service的bean对象,我使用@Autowired注解注入对象,然后启动,访问时报空指针异常,filter中获取不到bean对象。
后面我发现spring容器初始化bean对象的顺序是listener--&...
springboot整合filter之多个filter的拦截顺序
使用@Configuration注解在类上,把该类当成配置类用来取代.xml文件中bean对象的配置
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean()...
springboot 整合servlet方式一
1.了解过web开发的都知道,处理一个request需要有与之对应的servlet。
2.现在中小型企业都使用微服务框架来加快项目开发的效率,springcloud和dubbo都是目前比较流行的微服务框架,后面我会说明两个框架的有什么共同点和区别。
3.springboot和springcloud都是spring的顶级框架。
springboot整合servlet之注解方式
1.创建一个s...
springboot整合servlet方式二
1.创建一个springboot项目
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.serv...
springboot整合filter方式一
1.创建一个springboot项目
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.serv...
springboot整合filter方式二
1.创建一个springboot项目
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.serv...
springboot访问静态资源
静态资源目录一
1.SpringBoot的静态资源可以放在classpath/static(注意目录的名称必须为static)
2.我在static目录下创建了一个index.html
3.启动项目,默认的端口是8080,然后访问http://localhost:8080/index.html,就可以看到index.html中的页面信息了。
静态资源目录二
在ServletConte...
springboot整合listener方式一
创建一个项目
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.Servle...
springboot整合listener方式二
创建一个项目
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.Filter...
springboot上传文件demo
书写一个文件上传页面upload.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<
springboot整合jspDemo
创建springboot工程
修改pom.xml文件,添加有关的依赖
<!-- jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency&gt
洛谷——P2801 教主的魔法
P2801 教主的魔法 (1) 若第一个字母为“M”,则紧接着有三个数字L、R、W。表示对闭区间 [L, R] 内所有英雄的身高加上W。 (2) 若第一个字母为“A”,则紧接着有三个数字L、R、C。询问闭区间 [L, R] 内有多少英雄的身高大于等于C。 线段树大法好 维护区间$max$和区间$min$ 修改,正常修改即可,push_up操作修改的也只是区间最大值和最小值 关键在于查找,若当前区间的最大值$<=$所要查询的值,返回0 若当前区间的最小值$>=$所要查询的值,返回$r-l+1$
Web框架开发-用户认证(auth)模块
一、auth模块 from django.contrib import auth
1、authenticate():验证用户输入的用户名和密码是否相同 提供了用户认证,即验证用户名以及密码是否正确,一般需要username password两个关键字参数 如果认证信息有效,会返回一个 User 对象。authenticate()会在User 对象上设置一个属性标识那种认证后端认证了该用户,且该信息在后面的登录过程中是需要的。当我们试图登陆一个从数据库中直接取出来不经过authenti
在spring的业务层获取request,response
1.直接通过controller层获取到传输到业务层 2.SpringMVC提供的RequestContextHolder可以直接获取 代码: RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); // RequestContextHolder.getRequestAttributes(); //从session里面获取对应的值 String str = (String) r
今日推荐
周排行