基于xwiki部署企业内部知识管理平台

article/2025/8/27 20:28:37

1. Xwiki介绍

印象笔记、有道笔记、为知笔记都是挺好的商用笔记知识管理软件,不过有些敏感文件是不太好放到互联网上的。

所以搭建一套内部局域网知识管理平台是非常有意义的,在开源Wiki系统中,XWiki是做的最好的产品之一。因为它提供的功能与Confluence的功能非常相似,不需要学习任何语法格式,可以直接在线像编辑Word一样编辑WIKI页面。通过配置插件和扩展,还可以实现包括Markdown语法之内的各种延展功能。

所以在2021年就撸了一遍xwiki,现在把当时的记录整理一遍,以飨同行。

2. 简介

本文基于Centos7.x+Tomcat+Mysql进行部署Xwiki11.10.10。

 Xwiki安装前仔细阅读Release Notes for XWiki 11.10.10,可以避免走很多不必要的坑。

3.安装步骤

3.1安装Tomcat

安装tomcat前首先要安装对应的jdk并配置Java环境。

3.1.1下载jdk安装包

官网下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

我这边是下载的jdk-8u181-linux-x64.tar.gz

如果Linux本身连接到互联网,我们可以直接通过wget命令直接把JDK安装包下载下来。

3.1.2解压jdk安装包

将我们下载好的JDK安装包上传到服务器,进行解压。

我是放在了/usr/local/java文件下,所以要创建java文件夹并将解压文件移动到java下

mkdir -p /usr/local/java

3.1.3修改配置文件(配置环境变量)

vim /etc/profile

export JAVA_HOME=/usr/local/java/jdk1.8.0_271

export JAVA_BIN=/usr/local/java/jdk1.8.0_271/bin

export PATH=${JAVA_HOME}/bin:$PATH

export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar

用vim编辑器来编辑profile文件,在文件末尾添加一下内容:

:wq回车保存退出。

保存之后通过source /etc/profile命令使修改的配置生效

3.1.4测试JDK安装是否成功

java -version 出现安装版本信息

3.1.5安装tomcat

下载安装tomcat(http://tomcat.apache.org/)我这边是下载的apache-tomcat-8.5.32.tar.gz

解压

tar -zxvf apache-tomcat-9.0.41.tar.gz

我是放在了usr/local/tomcat下所以要创建tomcat文件夹并将解压文件移动到tomcat下

mkdir /usr/local/tomcat

mv apache-tomcat-9.0.41 /usr/local/tomcat/

 进入tomcat安装bin目录并启动

cd /usr/local/tomcat/apache-tomcat-9.0.41/bin

./startup.sh

成功启动后浏览器输入http://localhost:8080/查看信息(如果不是本机则输入对应IP)至此,tomcat安装完成,后续可添加项目重启tomcat服务。

3.1.6将tomcat添加为linux系统服务

⑴复制catalina.sh作为系统服务脚本

cp -p /usr/local/tomcat/apache-tomcat-9.0.41/bin/catalina.sh /etc/init.d/tomcat 重命名的tomcat为以后的服务名

⑵修改脚本

vim /etc/init.d/tomcat

在脚本较前面的位置加下面两行注释

 #chkconfig:2345 10 90

#description:Tomcat service

JAVA_HOME=/usr/local/java/jdk1.8.0_271

CATALINA_HOME=/usr/local/tomcat/apache-tomcat-9.0.41

第一行是服务的配置:

第一个数字是服务的运行级,2345表明这个服务的运行级是2、3、4和5级(Linux的运行级为0到6);

第二个数字是启动优先级,数值从0到99;

第三个数是停止优先级,数值也是从0到99。

 第二行是对服务的描述

如果该注释有误,在添加服务时会出现"tomcat不支持chkconfig"的错误提示 

第三四行 为设置环境变量

在profile文件中设置的变量不起作用,要在这里再设置一遍

 ⑶添加脚本的可执行权限

chmod 755 /etc/init.d/tomcat

⑷添加为系统服务

chkconfig --add tomcat

⑸查看系统服务列表

chkconfig --list | grep tomcat

 ⑹启停tomcat 服务

启动tomcat

service tomcat start

 停止

service tomcat stop

 ⑺设置为开机自动启动

vi /etc/rc.local

添加startup.sh的路径

/usr/local/tomcat/apache-tomcat-9.0.41/bin/startup.sh完成

⑻修改tomcat服务器的启动端口(未修改)

cd /usr/local/tomcat/apache-tomcat-8.5.32/conf/

vim server.xml 

 修改将Tomcat服务器启动时使用的8080端口,例如改成9999

Make sure you give enough memory to Java since by default Tomcat is not configured with enough memory for XWiki.

When you run XWiki in Tomcat with the default settings, you'll probably get an Out Of Memory error (java.lang.OutOfMemoryError: Java heap space or java.lang.OutOfMemoryError: PermGen space) since the default Tomcat memory settings are not enough for XWiki Memory Requirements. You'll need to allocate more memory to the JVM. 

One easy solution to configure Tomcat's memory is to create a setenv.sh file (or setenv.bat on Windows) in [TOMCAT_HOME]/bin/ (where [TOMCAT_HOME] is where you've installed Tomcat) and inside this file add the following (adjust the memory values according to the XWiki Memory Requirements). For example:

CATALINA_OPTS="-Xmx4096m -XX:MaxPermSize=960m"

⑼手动解压war包到对应目录

Extract the XWiki WAR into a directory named xwiki in TOMCAT_HOME/webapps/

jar -xvf project.war

3.2 设置 permanent目录

Open TOMCAT_HOME/webapps/xwiki/WEB-INF/xwiki.properties files and configure a permanent directory

Permanent Directory

To set the permanent directory, you have 2 options:

Set the xwiki.data.dir system property when starting the JVM (ie. the Servlet Container's JVM, specifically: -Dxwiki.data.dir=...)

Set the environment.permanentDirectory property in your xwiki.properties file

Make sure to choose a folder different from the XWiki home on which XWiki (which usually means whatever user running the application server in which XWiki is installed) has write access. For example the standard Debian package use /var/lib/xwiki/data which is usually a good fit for many Linux distributions.

If the location points to a file or a directory to which XWiki(需要新建用户?) does not have write access to, a warning will be printed in the log and the temporary directory will be used as a default. The temporary directory can be periodically cleaned and all its content deleted so it is critical that it is not used for anything else. Thus it's especially important to set the Permanent directory to not point to the temporary directory.

Start Tomcat

When Tomcat has opened go to your wiki by accessing http://localhost:8080/xwiki/bin/view/Main/

NOTE - if you have issues with maximum cache size - In your $CATALINA_BASE/conf/context.xml add the following content before </Context>:

<Resources cachingAllowed="true" cacheMaxSize="100000" ></Resources>

Activate headless mode

If you're operating XWiki on a Linux server with no X11 libraries installed you have to enable headless mode for your Tomcat installation. Sometimes this is also needed on Windows platforms. Typical exceptions are:

Exception: Could not initialize class sun.awt.X11.XToolkit

java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable

On Linux create a file /TOMCAT_HOME/bin/setenv.sh and insert the following code:

#!/bin/sh
export JAVA_OPTS="${JAVA_OPTS} -Djava.awt.headless=true"

On Windows create a file /TOMCAT_HOME/bin/setenv.bat and insert the following code:

set JAVA_OPTS=%JAVA_OPTS% -Djava.awt.headless=true

When running as a Windows service the setenv.bat is not working. See registry HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\FOOBAR\Parameters\Java for similar settings.

Optional configuration

Edit your conf/server.xml to enable gzip compression: <Connector port="8080" ... compression="on" compressionMinSize="2048" compressibleMimeType="text/html,text/xml,text/css,text/javascript,application/x-javascript"></Connector>

If you want to modify the port on which Tomcat will run, edit TOMCAT_HOME/conf/server.xml/. Search for 8080 (sometimes 8180 if you are under Linux) and replace with the port value you wish to use.

It is possible to setup a Tomcat Java Server as a UNIX Daemon - JSVC. Just follow these instructions. The only reason to make Tomcat a daemon is to make it runnable on the 80th port, which can be replaced by using NginX as a proxy on the 80th port and then forwarding to Tomcat to the 8080th port.

Policy configuration

For those who activate the security manager for Tomcat, add this portion of code to the end of your conf/catalina.policy file from your Tomcat installation. You can adapt the code for the available installations of OpenOffice/LibreOffice on your server and for different databases :

grant codeBase "file:${catalina.base}/webapps/xwiki/WEB-INF/lib/-" {
  // for mySQL connection
  permission java.net.SocketPermission "127.0.0.1:3306", "connect,resolve";

  // XWiki must have access to all properties in read/write
  permission java.util.PropertyPermission "*", "read, write";

  // Generic detected permissions
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
  permission java.lang.RuntimePermission "createClassLoader";
  permission java.lang.RuntimePermission "setContextClassLoader";
  permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.loader";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
  permission java.lang.RuntimePermission "getenv.ProgramFiles";
  permission java.lang.RuntimePermission "getenv.APPDATA";
  permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
  permission java.lang.RuntimePermission "getClassLoader";
  permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.connector";
  permission java.lang.RuntimePermission "accessClassInPackage.org.apache.tomcat.util.threads";
  permission java.lang.RuntimePermission "reflectionFactoryAccess";
  permission java.lang.RuntimePermission "accessClassInPackage.com.sun.jmx.interceptor";
  permission java.lang.RuntimePermission "accessClassInPackage.com.sun.jmx.mbeanserver";
  permission java.lang.RuntimePermission "modifyThread";
  permission java.lang.RuntimePermission "getProtectionDomain";

  // JAXB permissions
  permission javax.xml.bind.JAXBPermission "setDatatypeConverter";

  // Serialization related permissions
  permission java.io.SerializablePermission "allowSerializationReflection";
  permission java.io.SerializablePermission "creator";
  permission java.io.SerializablePermission "enableSubclassImplementation";

  // Internal resources access permissions
  permission java.io.FilePermission "synonyms.txt", "read";
  permission java.io.FilePermission "lang/synonyms_en.txt", "read";
  permission java.io.FilePermission "quartz.properties", "read";
  permission java.io.FilePermission "/templates/-", "read";
  permission java.io.FilePermission "/skins/-", "read";
  permission java.io.FilePermission "/resources/-", "read";

  // MBean related permissions
  permission javax.management.MBeanServerPermission "createMBeanServer";
  permission javax.management.MBeanPermission "*", "registerMBean";
  permission javax.management.MBeanPermission "*", "unregisterMBean";
  permission javax.management.MBeanTrustPermission "register";
  permission javax.management.MBeanPermission "-#-[-]", "queryNames";
  permission javax.management.MBeanServerPermission "findMBeanServer";

  // LibreOffice/OpenOffice related permissions
  permission java.io.FilePermission "/opt/openoffice.org3/program/soffice.bin", "read";
  permission java.io.FilePermission "/opt/libreoffice/program/soffice.bin", "read";
  permission java.io.FilePermission "/usr/lib/openoffice/program/soffice.bin", "read";
  permission java.io.FilePermission "/usr/lib/libreoffice/program/soffice.bin", "read";

  // Allow file storage directory reading - for directory and everything underneath
  // This is dependent on the setting of environment.permanentDirectory in xwiki.properties
  permission java.io.FilePermission "
${catalina.base}${file.separator}xwikidata${file.separator}", "read,write,delete";
  permission java.io.FilePermission "
${catalina.base}${file.separator}xwikidata${file.separator}-", "read,write,delete";

  // Allow file storage directory reading - temporary directory and everything underneath
  // This is dependent on the setting of environment.temporaryDirectory in xwiki.properties.
  permission java.io.FilePermission "
${catalina.base}${file.separator}temp${file.separator}", "read,write,delete";
  permission java.io.FilePermission "
${catalina.base}${file.separator}temp${file.separator}-", "read,write,delete";
};

后续还可以配置ngnix  https

3.3安装mysql

下载途径:From the Download MySQL Community Server page in the MySQL Developer Zone.

shell> sudo yum install mysql-community-{server,client,common,libs}-*  -y

3.3.1启动服务

[root@sty software]# service mysqld start

Initializing MySQL database:  /usr/sbin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

MySQL has a dependency on the libaio library. Data directory initialization

and subsequent server startup steps will fail if this library is not installed locally.

If necessary, install it using the appropriate package manager. For example, on

Yum-based systems:

shell> yum search libaio # search for info

shell> yum install libaio # install library

[root@sty software]# yum install libaio* -y

[root@sty software]# service mysqld start

Initializing MySQL database:                               [  OK  ]

Starting mysqld:                                           [  OK  ]

[root@sty software]# service mysqld status

mysqld (pid  63380) is running...

[root@sty software]#

3.3.2查看root密码

[root@xwiki soft]# more /var/log/mysqld.log |grep password

2021-01-16T10:18:48.243819Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Hur!dHpCh1d? [root@xwiki soft]#

3.3.3登录

shell> mysql –u  root  -p

3.3.4修改密码规则以及修改密码

如果是以前的MySQL版本,常使用password函数来进行修改密码

mysql> update mysql.user set password=password('xxx') where user='root';

但是MySQL8之后,没有了password字段和password()函数,所以不能使用上面的修改密码的方法。

修改密码

mysql> alter user 'root'@'localhost' identified by 'Root@123456';

我们也还可以使用mysqladmin命令来进行修改

mysqladmin -u root -p '旧密码' password '新密码'

 # mysqladmin -u root -p'Root@12345' password 'xxx'

alter user 'xwiki'@'localhost' identified by 'xwiki';

alter user 'root'@'localhost' identified by 'root';

mysql> set global validate_password.policy=LOW;

mysql> set global validate_password.length=4;

3.3.5创建xwiki数据库

mysql -u root -e "create database xwiki default character set utf8mb4 collate utf8mb4_bin"

mysql -u root -e "grant all privileges on *.* to xwiki@localhost"

ALTER USER 'xwiki'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY ‘Passw0rd’;

ALTER USER 'root'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY ‘Root@123456’;

If the above command fails with a password-does-not-meet-requirements error, uninstall the MySQL password_validate plugin or pick a more complex password and update the password used by default in hibernate.cfg.xml:

mysql -u root -p -e "uninstall plugin validate_password;"

Please make sure that the DNS-name "localhost" is defined in your hosts-file (i.e. /etc/hosts)

You need to have the MySQL JDBC Driver JAR (named mysql-connector-java*.jar) installed in XWiki's WAR file. If this file isn't present in XWiki's WEB-INF/lib directory you'll need to download it and copy it there. You can download it from the MySQL Connector/J Driver page or directly from the Maven Central Repository(这里有现成的).

You need the 5.x version or higher. The 3.x version doesn't handle Boolean data correctly and will either throw errors or will make all documents hidden by default.

Now you need to tell XWiki to use MySQL. To do this, edit the WEB-INF/hibernate.cfg.xml file where you have expanded the XWiki WAR file and replace the matching properties with the following ones:

<property name="connection.url">jdbc:mysql://localhost/xwiki</property>
<property name="connection.username">xwiki</property>
<property name="connection.password">Xwiki_123456</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>

XML如何添加注释?

注释以 <!-- 开始并以 --> 结束,
例如 <!--注释内容-->。注释可以出现在文档序言中,包括文档类型定义 (DTD);文档之后;或文本内容中。 注释不能出现在属性值中。 不能出现在标记中。
分析器在遇到 > 时,就认为注释已结束;然后继续将文档作为正常的 XML 处理。 因此,字符串 > 不能出现在注释中。 除了该限制之外,任何合法的 XML 字符均可以出现在注释中,与 CDATA 节非常类似。 这样,可以从分析器看到的输出流中删除 XML 注释,同时又不会删除文档的内容。
以下注释可以用于暂时除去标记。
<!--- <test pattern="SECAM" /><test pattern="NTSC" /> -->

此处mysql8 需要配置publickey  ttps://mysqlconnector.net/connection-options/

    <property name="hibernate.connection.url">jdbc:mysql://localhost/xwiki?allowPublicKeyRetrieval=true&amp;useSSL=false&amp;serverTimezone=${timezone}</property>

By default MySQL only accepts packets that are smaller than 1MB. If you get the "Packet for query is too large (max_allowed_packet)" error then see the Packet too large error page. For example to increase the packet size to 32M you could start the MySQL server with mysqld --console --max_allowed_packet=32M or you can modify directly the my.cnf configuration file to set this value permanently.

If an empty XWiki starts with no errors, but you are unable to upload the default set of pages (XAR file) try to increase the max_allowed_packet parameter as shown above.

3.3.6给任意IP授权(尚未做)

3.3.7创建索引Indexes

// Required
create index xwl_value on xwikilargestrings (xwl_value(50));
create index xwd_parent on xwikidoc (xwd_parent(50));
create index xwd_class_xml on xwikidoc (xwd_class_xml(20));
create index ase_page_date on  activitystream_events (ase_page, ase_date);
create index xda_docid1 on xwikiattrecyclebin (xda_docid);
create index ase_param1 on activitystream_events (ase_param1(200));
create index ase_param2 on activitystream_events (ase_param2(200));
create index ase_param3 on activitystream_events (ase_param3(200));
create index ase_param4 on activitystream_events (ase_param4(200));
create index ase_param5 on activitystream_events (ase_param5(200));
// Only required if you use stats (feature is off by default)
create index xws_number on xwikistatsdoc (XWS_NUMBER);
create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
create index xwr_number on xwikistatsreferer (XWR_NUMBER);
create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
create index xwr_referer on xwikistatsreferer (XWR_REFERER(50));
create index xwv_user_agent on xwikistatsvisit (XWV_USER_AGENT(255));
create index xwv_cookie on xwikistatsvisit (XWV_COOKIE(255));
create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
create index xwv_number on xwikistatsvisit (XWV_NUMBER);

Note to XWiki developers: The following indexes could be created automatically though since they're less than 255 characters and thus should be added in a future version of XWiki so that they don't need to be created manually:

create index xws_number on xwikistatsdoc (XWS_NUMBER);
create index xws_classname on xwikistatsdoc (XWS_CLASSNAME);
create index xwr_number on xwikistatsreferer (XWR_NUMBER);
create index xwr_classname on xwikistatsreferer (XWR_CLASSNAME);
create index xwv_classname on xwikistatsvisit (XWV_CLASSNAME);
create index xwv_number on xwikistatsvisit (XWV_NUMBER);
create index xda_docid1 on xwikiattrecyclebin (xda_docid);

3.4配置数据库相关参数

Create a user with all privileges on that database

Copy your RDBMS Java drivers to the XWiki webapp's WEB-INF/lib directory

Configure XWiki to use the created database. This involves modifying the WEB-INF/hibernate.cfg.xml file as is described in the tutorials for each database below.

XWiki will automatically create the various tables it needs when it executes on the first run

3.5配置Xwiki Ui界面

   

3.6开启Office Importer Application 方便word文档直接导入xwiki

The Office Importer application comes pre-bundled with XWiki versions greater than 1.8M1, so there is no need for a manual installation. The Office Importer makes use of a running Libre Office server to convert office documents into HTML before they are finally transformed into XWiki 2.0 syntax. Thus, a Libre Office server instance is required on the server computer which hosts your XWiki installation. Beginning with XWiki 1.8.4 you can configure a Libre Office or an OpenOffice server in the following ways described below.

 

4.结语

过程其实还是比较折腾的,自己搭的时候前前后后花了四五天的时间。官网还提供了docker安装选择,想用而且想偷懒的同学可以考虑。


http://chatgpt.dhexx.cn/article/gucaJVdA.shtml

相关文章

xwiki初步认识

1、xwiki安装 下载xwiki的war包&#xff0c;tomcat&#xff0c;mysql&#xff0c;各自安装配置好。在mysql中建好xwiki库&#xff0c;将war包放入tomcat中&#xff0c;在解压出来的文件中修改hibernate.cfg.xml的数据库连接配置&#xff0c;如2、字符集更改的图中。注意删除war…

Xwiki安装部署详解

一、Xwiki简介XWiki是一个由Java编写的基于LGPL协议发布的开源wiki和应用平台。XWiki是一款基于java所编写的wiki&#xff0c;它可以运行在如Tomcat&#xff0c;Jetty&#xff0c;JBoss&#xff0c;WebLogic&#xff0c;WebSphere等Servlet容器上并利用关系型数据库(HSQL, MySQ…

xwiki安装部署

xwiki 下载&#xff0c;版本选择以及与jdk&#xff0c;servlet容器&#xff0c;数据库和JDBC的版本对应关系&#xff0c;可以参考我另一篇关于这个的文章 https://blog.csdn.net/qq_38417282/article/details/125271765 首先进入xwiki官网 在documentation中找到Admin Guide—…

设计模式之装饰器模式详解

设计模式之装饰器模式详解 文章目录 设计模式之装饰器模式详解一、什么是装饰器模式二、装饰器模式的角色组成三、装饰器模式通用写法示例四、装饰器模式业务中的应用举例五、装饰器模式优缺点 一、什么是装饰器模式 装饰器模式&#xff08;Decorator Pattern&#xff09; 也称…

TS装饰器

通过本文你可以知道什么 装饰器的发展历程JS和TS装饰器有何不同Angular中的装饰器到底是什么装饰器的定义&#xff0c;语法&#xff0c;作用reflect-meta是什么及如何使用 前言 我们平常开发中或多或少的听说或使用过装饰器&#xff0c;也切身感受到了它带给我们的便利。但是…

python的装饰器(函数装饰器)

作为许多语言都存在的高级语法之一&#xff0c;装饰器是你必须掌握的知识点。 装饰器&#xff08;Decorator&#xff09;&#xff1a;从字面上理解&#xff0c;就是装饰对象的器件。可以在不修改原有代码的情况下&#xff0c;为被装饰的对象增加新的功能或者附加限制条件或者帮…

python装饰器这一篇就够了

前言 什么是装饰器 实现原理 实现效果 适用场景 装饰器&#xff1a; 装饰器的写法 装饰器的拓展 装饰器的模板 什么是装饰器呢&#xff1f; 就是在特定条件下为某些函数再不改动函数体的时候为函数新添加一些功能&#xff0c;这就是装饰器 实现原理&#xff1a; …

【Python】闭包与装饰器

1.闭包 闭包的本质就是函数的嵌套定义&#xff0c;即在函数内部再定义函数 闭包有两种不同的方式&#xff0c;第一种是“返回一个函数名称”&#xff0c;第二种是在函数内部就“直接调用” 闭包的定义&#xff1a;在一个外函数中定义了一个内函数&#xff0c;内函数里运用了…

Python装饰器的通俗理解

看了这篇文章终于搞懂了装饰器&#xff0c;原文有少许错误&#xff0c;但无伤大雅&#xff0c;改正后转载于此&#xff0c;一起学习。 在学习Python的过程中&#xff0c;我相信有很多人和我一样&#xff0c;对Python的装饰器一直觉得很困惑&#xff0c;我也是困惑了好久&#x…

什么是装饰器?

一、引出装饰器概念 引入问题&#xff1a; 定义了一个函数&#xff0c;想在运行时动态的增加功能&#xff0c;又不想改动函数本身的代码&#xff1f; 示例&#xff1a; 希望对下列函数调用增加log功能&#xff0c;打印出函数调用&#xff1a; def f1(x): return x*2 d…

Python自定义装饰器

文章目录 1.闭包2.不带参数的装饰器3.带参数的装饰器4.不定长参数的装饰器5.多重装饰器修饰6.返回值是装饰器7.装饰器类 Python学习笔记—装饰器 装饰器&#xff1a;从生活角度理解&#xff0c;是对一个东西进行装饰&#xff0c;增加它本身的一些功能和内容&#xff1b; Python…

Python的装饰器

前言&#xff1a; &#x1f921; 作者简介&#xff1a;我是Morning&#xff0c;计算机的打工人&#xff0c;想要翻身做主人 &#x1f648; &#x1f648; &#x1f648; &#x1f3e0; 个人主页&#xff1a;Morning的主页 &#x1f4d5;系列专栏&#xff1a;&#…

装 饰 器

一&#xff0c;装饰器概念 装饰器本质上还是函数&#xff0c;让其它的函数在不做任何代码修改的情况下&#xff0c;增加额外的功能 所以说一句话&#xff1a;还是函数&#xff0c;记住奥 谈到一个原则&#xff1a;开发封闭原则 概念&#xff1a; 一个以函数作为参数并返回一…

学习TypeScript20(装饰器Decorator)

Decorator 装饰器是一项实验性特性&#xff0c;在未来的版本中可能会发生改变 它们不仅增加了代码的可读性&#xff0c;清晰地表达了意图&#xff0c;而且提供一种方便的手段&#xff0c;增加或修改类的功能 若要启用实验性的装饰器特性&#xff0c;你必须在命令行或tsconfig…

python装饰器详解

python中的装饰器(decorator)一般采用语法糖的形式&#xff0c;是一种语法格式。比如&#xff1a;classmethod&#xff0c;staticmethod&#xff0c;property&#xff0c;xxx.setter&#xff0c;wraps()&#xff0c;func_name等都是python中的装饰器。 装饰器&#xff0c;装饰的…

【Python】一文弄懂python装饰器(附源码例子)

目录 前言 一、什么是装饰器 二、为什么要用装饰器 三、简单的装饰器 四、装饰器的语法糖 五、装饰器传参 六、带参数的装饰器 七、类装饰器 八、带参数的类装饰器 九、装饰器的顺序 总结 写在后面 前言 最近有人问我装饰器是什么&#xff0c;我就跟他说&#xff…

偏微分方程数值解程序设计与实现——数学基础

常用算子符号 梯度算子 R d \mathbb{R}^d Rd空间中标量函数 u ( x ) u(\bf{x}) u(x)&#xff0c;其梯度算子定义如下&#xff1a; g r a d u ( x ) ∇ u ( x ) [ ∂ u ∂ x 0 ∂ u ∂ x 1 ⋮ ∂ u ∂ x d − 1 ] grad u(\mathbf{x})\nabla u(\mathbf{x}) \begin{bmatrix} …

偏微分方程的数值解(六): 偏微分方程的 pdetool 解法

偏微分方程的数值解系列博文&#xff1a; 偏微分方程的数值解(一):定解问题 & 差分解法 偏微分方程的数值解(二): 一维状态空间的偏微分方程的 MATLAB 解法 偏微分方程的数值解(三): 化工应用实例 ----------触煤反应装置内温度及转换率的分布 偏微分方程的数值解(四):…

微分方程数值解

一阶问题举例&#xff1a; 高阶问题举例 &#xff1a; 常微分方程数值解&#xff1a;向前欧拉方法之一阶问题 clc,clear,close all; a0;%初始时刻 b2*pi;%结束时刻 n100;%离散点数量 x00;%初值 h(b-a)/n;%步长 xx0 [0:n]*h;%离散点数组 funinline(sin(x)y,x,y); y01; %计算 y(…

常微分方程数值解法1

&#xff11;.牛顿迭代法 多数方程不存在求根公式&#xff0c;因此求精确根非常困难&#xff0c;甚至不可能&#xff0c;从而寻找方程的近似根就显得特别重要。牛顿迭代法使用函数 的泰勒级数的前面几项来寻找方程 的根。牛顿迭代法是求方程根的重要方法之一&#xff0c;其最大…