@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Run Code Online (Sandbox Code Playgroud)
为什么我们使用这个注释?我需要知道这个自动增量我的表id值.(GenerationType.IDENTITY)当我们使用这个注释时,是否有其他类型的实际发生
public class Author extends Domain
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Column(name = "name")
private String name;
@Column(name = "address")
private String address;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "authorId")
private List<Book>
bookList;
public Author()
{
setServiceClassName("wawo.tutorial.service.admin.AuthorService");
}
}
Run Code Online (Sandbox Code Playgroud)
*是否有必要扩展Domain抽象类?有什么用?
可以说我有几个浮点数要在Bash脚本中打印。但是我希望浮点数相应地显示在LC_NUMERIC
语言环境环境变量中。
#!/usr/bin/env bash
# For consistent/reproducible error messages in this sample code
LANGUAGE=C
# The speed of light in vacum in m.s
declare -r const_C=299792458
# Declare separately when assigning command output
declare -- const_pi
# ? is 4 × arc-tangent of 1, using bc calculator with math library
typeset -r const_pi="$(bc --mathlib <<<'scale=20; 4*a(1)')"
# Do it in US's English
LC_NUMERIC=en_US.utf8
printf 'LC_NUMERIC=%s\n' "${LC_NUMERIC}"
printf 'Speed of light in vacuum is:\nC=%.f m/s\n\n?=%.10f\n' \
"${const_C}" \
"${const_pi}"
echo …
Run Code Online (Sandbox Code Playgroud) ${var:?}
Ash、Dash 或 Bash、Zsh以不同的方式处理此处文档中的无效空参数扩展错误。
下面是experiment.sh
使用真正的 POSIX 语法的代码:
#!/usr/bin/env sh
empty_var=
read -r value << EOF
Expected fail here ${empty_var:?}"
EOF
printf '$?=%d\nvalue=%s\n' $? "$value"
Run Code Online (Sandbox Code Playgroud)
下面是使用不同 shell 运行实验的代码:
for sh in ash bash dash ksh zsh; do
printf 'Testing with: %s\n' "$sh"
LC_ALL=C "$sh" ./experiment.sh || :
echo
done
Run Code Online (Sandbox Code Playgroud)
得到的结果:
Testing with: ash
./experiment.sh: 5: empty_var: parameter not set or null
$?=2
value=
Testing with: bash
./experiment.sh: line 5: empty_var: parameter null or not set
Testing with: dash
./experiment.sh: …
Run Code Online (Sandbox Code Playgroud) 我进行了一项实验,看看在进程链之间使用不同的 shell 时,Bash 的导出函数是否仍然可见。
令我惊讶的是,导出的函数有时仍然可见。
我正在寻找关于如何以及为什么通过不同的 shell 在环境中维护 Bash 的特定导出函数的解释,而它不是 POSIX 标准环境变量。
不知怎的,我有一个线索,导出的函数声明作为字符串存储在(标准?)环境变量中。但它如何作为环境变量对不兼容的 shell 不可见,以及如何在环境中维护它?
这是我的实验代码:
#!/usr/bin/env bash
LANG=C
# Declare function and export it
fn(){ printf 'Hello World\n';}
export -f fn
# Standard usage, call exported function within a child bash
bash -c fn
# Available shells for tests
available_shells=()
for sh in ash bash dash ksh tcsh zsh
do
if shell_path=$(command -v "$sh" 2> /dev/null)
then
available_shells+=("$shell_path")
real_shell_path=$(realpath "$shell_path")
shell_version=$(
read -r pkg < <(apt-file search "${real_shell_path#/usr}" | …
Run Code Online (Sandbox Code Playgroud) 我通过Java注释生成的JSON swagger文档遇到了一些麻烦(REST使用Jersey公开,序列化由jackson处理).查看生成的swagger,它包含空值,这会导致swagger UI崩溃(生成的YAML没有此问题).
这里是JSON的摘录:
{
"swagger": "2.0",
"info": { "description": null, "version": "1.0.0", "title": "", "termsOfService": null, "contact": null, "license": null },
"host": "localhost:8080",
"basePath": "/api",
"tags": [ { "name": "dataset", "description": null, "externalDocs": null } ],
"schemes": [ "http" ],
"consumes": null,
"produces": null,
"paths": {
"/dataset": {
"get": {
"tags": ["dataset"],
"summary": "A dataset",
"description": "All the available datasets",
"operationId": "datasetGet",
"schemes": null,
"consumes": null,
"produces": ["application/json"],
"parameters": [],
"responses": {
"200": {
"description": "Available datasets",
"schema": { …
Run Code Online (Sandbox Code Playgroud) 我最近安装了 Python 和 Visual Studio Code。参加完入门课程后,我编写了一个基本脚本并在 Visual Studio Code 中运行它。就在那时,我注意到 Visual Studio 代码中的 Python 设置方式存在问题。问题:当我启动 Visual Studio Code 并打开 python 文件时,终端默认为“C:\Users\my_name\Documents Python”(这是存储我的 python 文件的文件夹)。据我了解,当你使用Python时,提示符应该是“>>>”。我能够运行我的脚本,但无法在终端中运行任何其他 Python 代码(即像 z = 5 这样简单的代码)。如果我输入“Python”,系统会提示我“>>>”,但无法再运行我的脚本。
我认为这是一个安装问题,所以我卸载并重新安装了 Python 和 Visual,但问题仍然存在。
我尝试在系统设置下将程序安装位置的Python文件路径添加到Windows环境中,并在重新安装Python时单击“添加到路径”,但这些解决方案似乎都不起作用。
当基本的 python 代码(即 z=5)似乎不起作用但脚本运行良好时,我收到以下错误消息:
PS C:\Users\my_name\Documents\Python 2> z=5
z=5 : The term 'z=5' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is …
Run Code Online (Sandbox Code Playgroud) 我在最新的 mac 操作系统上使用 shell 脚本“a.sh”进行了实验,其中包含以下内容(精确副本)。
#!/bin/bash
echo $BASH_VERSION
a=0
(( a < 100 || 1 / a < 2 )) && echo ok
Run Code Online (Sandbox Code Playgroud)
我有:
3.2.57(1)-release
./a.sh: line 4: ((: a < 100 || 1 / a < 2 : division by 0 (error token is "< 2 ")
Run Code Online (Sandbox Code Playgroud)
既然a < 100
已经是事实了,我想1 / a < 2
就不会评价了。
有人可以帮助我理解这一点吗?
我可以在iPhone上的Objective-C中执行此操作,但现在我正在寻找相应的Android Java代码.我也可以用普通的Java来做,但我不知道Android特定的类是什么.我想在运行中生成一个PNG图像,该图像在图像中居中.
public void createImage(String word,String outputFilePath){/*我该怎么办?*/}
相关主题:
我正在尝试在 bash 中创建一个选择,让您从 .txt 文件中选择项目。每个项目都是一个新行,我读取这些项目并将它们放入一个数组中:
items=()
while read -r line; do
items+=("$line")
done <items.txt
Run Code Online (Sandbox Code Playgroud)
这工作正常。
之后,我将它们放入一个选择中:
PS3="Choose Item > "
select item in "${items[@]}" "Cancel"; do
case ${item} in
Cancel)
echo "You chose to cancel"
break
;;
*)
echo "You chose ${item}"
break
;;
esac
done
Run Code Online (Sandbox Code Playgroud)
选择逐行显示所有项目。这一切正常,直到有超过 9 个项目。当有超过 9 个项目时,它会显示它们真的很奇怪。它还结合了项目名称。见下图。
我在网上阅读它可能与 bash 如何读取编号参数有关。但我找不到任何解决方案。为什么 9 之后的 bash 命令行参数需要大括号?
有人知道如何解决 bash 选择中最多只能有 9/10 个选项的问题吗?
Bash中一个非常基本的问题,但我似乎无法弄清楚。我正在bash中寻找一个带有管道的衬板命令,该命令在当前目录中找到所有上次在13:15到13:30之间更改的* .py文件(与日期无关)。
我想我可以使用ls
,cut
但是我不确定是否是写入格式。寻找使用“基本命令”。
因此,假设我想在bash中运行一些命令,然后说八度。有什么办法可以用两个不同的命令运行相同的文件吗?在下面的示例中,我希望第一部分由bash运行,第二部分由八度运行
#!/bin/bash
echo helloooo
#!/bin/octave
plot(1,2)
pause()
Run Code Online (Sandbox Code Playgroud) 您好,我正在尝试使用 bash 创建日志,但我得到的时间是错误的。我在后台运行这个。
# log code here before executing curl script log "Yay I was started"
curl https://example.com/process | sed "s/^/$(date -u) /" >> /path/to/logs.log &
Run Code Online (Sandbox Code Playgroud)
处理curl后设置的时间是执行它的时间,而不是我得到响应后的时间。我需要得到回复后的时间。
这是示例输出(错误响应)
Fri Aug 21 01:43:12 UTC 2020 Yay I was started
Fri Aug 21 01:43:12 UTC 2020 Yay I was the response returned by the url
Run Code Online (Sandbox Code Playgroud)
这里的 urlhttps://example.com/process
会休眠 2 秒,但正如您所看到的,时间与执行时和执行后我们收到响应的时间相同。
正确反应
Fri Aug 21 01:43:12 UTC 2020 Yay I was started
Fri Aug 21 01:43:14 UTC 2020 Yay I was the …
Run Code Online (Sandbox Code Playgroud) 在我的交互式 shell 中,我可以将模式存储在变量中
$ targets="?(pcm52|pcm61)"
$ ls -l config/devdesc.$targets
-rw-r--r-- 1 kfa kfa 113 Dec 16 13:43 config/devdesc.pcm52
-rw-r--r-- 1 kfa kfa 14 Dec 16 13:44 config/devdesc.pcm61
Run Code Online (Sandbox Code Playgroud)
但是如果我创建一个shell脚本
targets="?(pcm52|pcm61)"
ls -l config/devdesc.$targets
Run Code Online (Sandbox Code Playgroud)
运行它时出现此错误
$ bash -x /tmp/e.sh
+ targets='?(pcm52|pcm61)'
+ ls -l 'config/devdesc.?(pcm52|pcm61)'
ls: cannot access 'config/devdesc.?(pcm52|pcm61)': No such file or directory
Run Code Online (Sandbox Code Playgroud)
为什么放入脚本时会失败?