是否有任何方法可以使JAXB不保存哪些值是@Element注释中指定的默认值,然后在从XML加载null或空的元素时将值设置为它?一个例子:
class Example
{
@XmlElement(defaultValue="default1")
String prop1;
}
Example example = new Example();
example.setProp1("default1");
jaxbMarshaller.marshal(example, aFile);
Run Code Online (Sandbox Code Playgroud)
应该生成:
<example/>
Run Code Online (Sandbox Code Playgroud)
并在加载时
Example example = (Example) jaxbUnMarshaller.unmarshal(aFile);
assertTrue(example.getProp1().equals("default1"));
Run Code Online (Sandbox Code Playgroud)
我试图这样做是为了生成一个干净的XML配置文件,并使其更好的可读性和更小的尺寸.
提前退位并表示感谢.
我正在创建一个应用程序。以前,我Gtk.Main()用来启动我的应用程序,并使用创建了一些钩子以从命令行停止应用程序Ctrl+C。现在,我已经将应用程序迁移到了更“标准”的位置Gtk.Application,但是无法停止使用Ctrl+C。
这很简单Gtk.Application,当从命令行运行时,不能使用Ctrl+C以下命令停止它:
from gi.repository import Gtk
import sys
# a Gtk ApplicationWindow
class MyWindow(Gtk.ApplicationWindow):
# constructor: the title is "Welcome to GNOME" and the window belongs
# to the application app
def __init__(self, app):
Gtk.Window.__init__(self, title="Welcome to GNOME", application=app)
class MyApplication(Gtk.Application):
# constructor of the Gtk Application
def __init__(self):
Gtk.Application.__init__(self)
# create and activate a MyWindow, with self (the MyApplication) as
# application the window belongs to.
# …Run Code Online (Sandbox Code Playgroud) 使用 Python SQLModel,我想以最 SQLModel 标准的方式截断表,或删除所有行,并获取已删除行的数量。我怎样才能做到这一点?我正在使用这个:
with Session(engine) as session:
count = session.exec(delete(MyModel)).fetchall()
session.commit()
Run Code Online (Sandbox Code Playgroud)
但它会引发一个错误:
ResourceClosedError('This result object does not return rows. It has been closed automatically.')
Run Code Online (Sandbox Code Playgroud)
我也尝试过scalar(),而fetchone()不是fetchall()没有成功。
我有一个用于 Apache 的自定义访问日志:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{JSESSIONID}C %D %V" mylog
Run Code Online (Sandbox Code Playgroud)
我正在尝试从 Python 解析生成的 LOG;但我有两个问题:
使用这个正则表达式:
(?P<ip>.*) (?P<remote_log_name>.*) (?P<userid>.*) \[(?P<date>.*)(?= ) (?P<timezone>.*?)\] \"(?P<request_method>.*) (?P<path>.*)(?P<request_version> HTTP/.*)\" (?P<status>.*) (?P<length>.*) \"(?P<referrer>.*)\" \"(?P<user_agent>.*)\" (?P<session_id>.*) (?P<generation_time_micro>.*) (?P<virtual_host>.*)
Run Code Online (Sandbox Code Playgroud)
此 LOG 的前 3 行解析失败:
1.1.1.2 - - [11/Nov/2016:03:04:55 +0100] "GET /" 200 83 "-" "-" - 9221 1.1.1.1
127.0.0.1 - - [11/Nov/2016:14:24:21 +0100] "GET /uno dos" 404 298 "-" "-" - …Run Code Online (Sandbox Code Playgroud) 我有一个具有以下结构的表:
select * from test_table;
id |load_balancer_name |listener_descriptions |
---|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1 |with_cert_1 |[{"Listener": {"Protocol": "HTTPS", "LoadBalancerPort": 443, "InstanceProtocol": "HTTP", "InstancePort": 9005, "SSLCertificateId": "arn:aws:acm:us-west-2:xxxx:certificate/xxx"}, "PolicyNames": ["xxxx"]}] |
2 |with_cert_1 |[{"Listener": {"Protocol": "HTTPS", "LoadBalancerPort": 443, "InstanceProtocol": "HTTP", "InstancePort": 9005, "SSLCertificateId": "arn:aws:acm:us-west-2:xxxx:certificate/xxx"}, "PolicyNames": ["xxxx"]}] |
3 |with_cert_2 |[{"Listener": {"Protocol": "HTTPS", "LoadBalancerPort": 443, "InstanceProtocol": "HTTP", "InstancePort": 9005, "SSLCertificateId": "arn:aws:acm:us-west-2:xxxx:certificate/yyy"}, "PolicyNames": ["xxxx"]}] |
4 |no_cert | |
Run Code Online (Sandbox Code Playgroud)
我需要的是根据listener_descriptions列进行一些搜索。为了确保JSON_*方法有效,我做了这个查询,效果很好:
select
id, load_balancer_name,
JSON_EXTRACT(listener_descriptions, "$[*].Listener.SSLCertificateId")
from test_table;
id |load_balancer_name |JSON_EXTRACT(listener_descriptions, "$[*].Listener.SSLCertificateId") |
---|-------------------|----------------------------------------------------------------------| …Run Code Online (Sandbox Code Playgroud) 使用 Kubuntu 18.04 (qt5 5.9.5)、Python 3.6。我无法让此代码显示托盘图标;显示了其他图标,例如 Dropbox 等,但不是:
import sys
from PyQt5.QtWidgets import QApplication, QMenu, QSystemTrayIcon, qApp, QMessageBox
from PyQt5.QtGui import QIcon
def run_something():
print("Running something...")
if __name__ == '__main__':
print("Creating application...")
app = QApplication(sys.argv)
print("Creating menu...")
menu = QMenu()
checkAction = menu.addAction("Check Now")
checkAction.triggered.connect(run_something)
quitAction = menu.addAction("Quit")
quitAction.triggered.connect(qApp.quit)
print("Creating icon...")
icon = QIcon.fromTheme("system-help")
print("Creating tray...")
trayIcon = QSystemTrayIcon(icon, app)
trayIcon.setContextMenu(menu)
print("Showing tray...")
trayIcon.show()
trayIcon.setToolTip("unko!")
trayIcon.showMessage("hoge", "moge")
print("Running application...")
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
显示了消息(“hoge”,“moge”),但我在任何地方都找不到该图标......正如其他帖子所说,在左上角都找不到。
python ×4
apache ×1
gtk3 ×1
java ×1
jaxb ×1
json ×1
logging ×1
mariadb ×1
marshalling ×1
mysql ×1
mysql-json ×1
pyqt ×1
python-3.x ×1
regex ×1
sqlalchemy ×1
sqlmodel ×1
ubuntu ×1