static

关于app.use('/static', express.static(path.join(__dirname, 'public')))的理解

ぃ、小莉子 提交于 2020-01-23 19:39:48
Express官方文档里的静态文件部分有一句话 这两个都是设置开放静态资源目录,那底下这句作用是什么?先翻译一下 然而,但是,您提供给express.static函数的路径是相对于您启动节点进程的目录的。 如果您从另一个目录运行Express App,则使用要提供服务的目录的绝对路径更为安全: 可以这样理解,第一个是相对路径写法,而第二个是绝对路径写法。 __dirname为绝对路径 path.join()为拼接路径语法 例如: 在其他目录下(即项目目录外)运行时语法为 此时如果是第一种写法,则会获取失败,因为这种写法为相对路径写法,即 根据当前运行该指令所在的文件路径去寻找 . 来源: https://www.cnblogs.com/jianxian/p/12231068.html

Java: reference outer class in nested static class [duplicate]

蹲街弑〆低调 提交于 2020-01-23 19:26:49
问题 This question already has answers here : Java inner class and static nested class (26 answers) Closed 4 years ago . I have a class structure like this: public class OuterClass { private static class InnerClass { public void someMethod() { OtherClass.otherMethod(<???>); } } which refers to a static method of some other class OtherClass : public class OtherClass { public static void otherMethod(OuterClass) { .... } } I am trying to figure out what to put in place of the <???> . How do I refer

静态资源

梦想的初衷 提交于 2020-01-23 10:26:20
静态资源 settings的设置 # 静态文件的路由(url)地址 STATIC_URL = '/static/' # 静态文件的路径地址 STATICFILES_DIRS = ( os . path . join ( BASE_DIR , 'static' ) , ) 然后在目录下创建static文件 css的设置 创建background.css文件 代码如下: body { background-color : #21ceed ; color : brown ; } 动态的编写代码 { % load static % } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!--硬编码 <link rel="stylesheet" href="/static/css/background.css"> --> <!--动态的编码--> <link rel="stylesheet" href=" { % static '/css/background.css' % } "> </head> <body> <h1>我是模板</h1> { { name } } { { age } } { { sex } } <hr> <!--调用列表--> { { learn.0 }

Java Static Variables and inheritance and Memory

爱⌒轻易说出口 提交于 2020-01-23 06:35:10
问题 I know that if I have multiple instance of the same class all of them are gonna share the same class variables, so the static properties of the class will use a fixed amount of memory no matter how many instance of the class I have. My question is: If I have a couple subclasses inheriting some static field from their superclass, will they share the class variables or not? And if not, what is the best practice/pattern to make sure they share the same class variables? 回答1: If I have a couple

Java Static Variables and inheritance and Memory

那年仲夏 提交于 2020-01-23 06:31:45
问题 I know that if I have multiple instance of the same class all of them are gonna share the same class variables, so the static properties of the class will use a fixed amount of memory no matter how many instance of the class I have. My question is: If I have a couple subclasses inheriting some static field from their superclass, will they share the class variables or not? And if not, what is the best practice/pattern to make sure they share the same class variables? 回答1: If I have a couple

Can static code blocks throw exceptions? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2020-01-23 05:38:18
问题 This question already has answers here : Why doesn't Java allow to throw a checked exception from static initialization block? (8 answers) Closed 5 years ago . In a hypothetical situation I have a class like this: import java.io.File; import java.util.Scanner; class X { static Scanner scanner; static { scanner = new Scanner(new File("X.txt")); } } When compiling, I get unreported exeption java.io.FileNotFoundException ; must be caught or declared to be thrown because public Scanner(File

单例设计模式

二次信任 提交于 2020-01-23 05:01:24
对所有的Java开发者而言,所有项目中最为常见的三个设计模式:工厂设计模式、代理设计模式、单例设计模式。 单例设计模式: 如果一个类中定义有普通方法,那么这些普通方法一定要通过本类的实例化对象你才可以调用。 传统调用: class Single{ public void print(){ System.out.println("单身"); }}class TestDemo{ public static void main(String arg[]){ Single single = new Single(); single.print(); }}运行结果:单身 在本程序中Single是一个普通的类,由于本类并没有进行任何构造方法的定义,所以这个类中会自动生成一个无参的、什么都不做的的构造方法,正是因为如此,我们可以在外部进行无参构造的调用。 但现在相对Single 类做一个修改: class Single{ private Single(){} public void print(){ System.out.println("单身"); }}class TestDemo{ public static void main(String arg[]){ Single single= null; single = new Single(); single.print(); }} 运行结果

Java中的枚举类型

好久不见. 提交于 2020-01-23 04:46:13
JDK1.5中新增了枚举类型,可以使用该功能取代以往定义常量的方法,同时枚举类型还赋予程序在编译时进行检查的功能。 一、使用枚举类型设置常量 以为设置常量,通常将常量放置在接口中,这样在程序中就可以直接使用,并且该常量不能被修改,因为在接口中定义常量时,该常量的修饰符为final与static。常规定义常量的示例如下: public interface Constants{ public static final int Constants_A = 1; public static final int Constants_B = 12; } 使用枚举类型定义常量的语法如下: public enum Constants{ Constants_A, Constants_B, Constants_C } 在上述示例中,enum是定义枚举类型关键字,当需要在程序中使用该常量时,可以使用Constants.Constants_A来表示 二、深入了解枚举类型 1、操作枚举类型成员的方法 枚举类型较传统定义常量的方式,除了具有参数类型检测的优势之外,还具有了其它优势。 用户可以将一个枚举类型看作是一个类,它继承于java.lang.Enum类,当定义一个枚举类型时,每一个枚举类型成员都可以看作时枚举类型的一个实例,这些枚举类型成员都默认被final、public、static修饰

Is it accurate to describe dispatch in Clojure using a Protocol as 'static'?

浪尽此生 提交于 2020-01-23 01:33:51
问题 Meikel Brandmeyer wrote a post on dispatch in Clojure with the URL title Static vs Dynamic. He writes: Protocols are not the only place where we have a trade-off of static vs. dynamic. There are several places where such a trade-off can be spotted. He provides the following example of static dispatch in a protocol: (defprotocol Flipable (flip [thing])) (defrecord Left [x]) (defrecord Right [x]) (extend-protocol Flipable Left (flip [this] (Right. (:x this))) Right (flip [this] (Left. (:x this)

VUE-CLI配置自动生成环境变量

守給你的承諾、 提交于 2020-01-23 00:21:24
vue-cli配置.env执行项目后自动同步static/config.js文件 下载dotenv依赖包,执行命令: npm install dotenv 在根目录下创建.env文件,内容如下: WEB_SOCKET = '192.168.1.111' 在build文件夹下新建zpreface.js文件,内容如下: const fs = require('fs') const path = require('path') const env = path.join(__dirname, '../.env') const out = path.join(__dirname, '../static/config.js') const script = function (env_file = env, out_file = out) { const { parsed } = require('dotenv').config({ path: env_file }) fs.writeFileSync(out_file, `window.zPreface = '${parsed.WEB_SOCKET}'`) } script(); module.exports = script 在static文件加下创建config.js,内容如下: window.zPreface = '192.168.1