我有两个实体:
Parent {
Child[] children;
}
and
Child {
Parent parent;
}
Run Code Online (Sandbox Code Playgroud)
我知道@JsonBackReference和@JsonManagedReference.如果我正在序列化实例,那么它们很好Parent.
但我还需要传输实例,Child并希望parent填充该字段.
换一种说法:
Parent它的序列化应该有,children但他们的父字段可能是空的(可以通过使用json引用注释来解决).Child它的序列化应该parent与他们children(但children不必parent填充.有没有办法使用标准的Jackson功能来解决它?
即跳过已经序列化的实体的序列化,而不是标记符合条件或不符合序列化条件的字段.
这是一个基准:
fn benchmark_or(repetitions: usize, mut increment: usize) -> usize {
let mut batch = 0;
for _ in 0..repetitions {
increment |= 1;
batch += increment | 1;
}
batch
}
fn benchmark_xor(repetitions: usize, mut increment: usize) -> usize {
let mut batch = 0;
for _ in 0..repetitions {
increment ^= 1;
batch += increment | 1;
}
batch
}
fn benchmark(c: &mut Criterion) {
let increment = 1;
let repetitions = 1000;
c.bench_function("Increment Or", |b| {
b.iter(|| black_box(benchmark_or(repetitions, …Run Code Online (Sandbox Code Playgroud) 我需要从这样的节点中提取文本:
<div>
Some text <b>with tags</b> might go here.
<p>Also there are paragraphs</p>
More text can go without paragraphs<br/>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要建立:
Some text <b>with tags</b> might go here.
Also there are paragraphs
More text can go without paragraphs
Run Code Online (Sandbox Code Playgroud)
Element.text只返回div的所有内容.Element.ownText - 所有不属于儿童元素的东西.两者都错了.迭代children忽略文本节点.
是否有方法迭代元素的内容以接收文本节点.例如
我尝试在DL4J上执行以下示例(加载预先训练的矢量文件):
File gModel = new File("./GoogleNews-vectors-negative300.bin.gz");
Word2Vec vec = WordVectorSerializer.loadGoogleModel(gModel, true);
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(r);
for (; ; ) {
System.out.print("Word: ");
String word = br.readLine();
if ("EXIT".equals(word)) break;
Collection<String> lst = vec.wordsNearest(word, 20);
System.out.println(word + " -> " + lst);
}
Run Code Online (Sandbox Code Playgroud)
但它超级慢(计算最近的单词需要大约10分钟,尽管它们是正确的).
有足够的内存(-Xms20g -Xmx20g).
当我从https://code.google.com/p/word2vec/运行相同的Word2Vec示例时
它非常快地给出最近的单词.
DL4J使用的ND4J声称速度是Numpy的两倍:http://nd4j.org/benchmarking
我的代码有什么问题吗?
更新:它基于https://github.com/deeplearning4j/dl4j-0.4-examples.git(我没有触及任何依赖项,只是试图阅读谷歌预先训练的矢量文件).Word2VecRawTextExample工作正常(但数据大小相对较小).
我输入命令apt-get install apache2 --fix-missing(在root用户下),这是我收到的:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
ssl-cert
Suggested packages:
apache2-doc apache2-suexec apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3
libaprutil1-ldap ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 36 not upgraded.
Need to get 2,945 kB/3,141 kB of archives.
After this operation, 10.4 …Run Code Online (Sandbox Code Playgroud) 我希望其他人向我解释,哪种方法更好:使用会话或设计无会话.我们正在开始开发新的Web应用程序,尚未确定要遵循的路径.
无会话设计IMO更为可取:
优点:
缺点:
在做出最终决定之前,我们还需要考虑哪些主题?
我试图使用Spring 3.x @ResponseBody生成json/xml响应,当有很多关系b/w表时我使用JPA 2.0 ORM然后json抛出LazyInitializationException
如果我给出"渴望获取",那么它将进入循环引用.
这是一些伪代码如下.
public class MyObject
{
private List<Object> someStuff;
private Timer timer;
public MyObject()
{
someStuff = new ArrayList<Object>();
timer = new Timer(new TimerTask(){
public void run()
{
for(Object o : someStuff)
{
//do some more stuff involving add and removes possibly
}
}
}, 0, 60*1000);
}
public List<Object> getSomeStuff()
{
return this.someStuff;
}
}
Run Code Online (Sandbox Code Playgroud)
所以基本上问题是上面代码中未列出的其他对象调用getSomeStuff()来获取列表以用于只读目的.当发生这种情况时,我在计时器线程中得到concurrentmodificationexception.我尝试使getSomeStuff方法同步,甚至尝试在计时器线程中使用synchronized块,但仍然不断收到错误.停止并发访问列表的最简单方法是什么?
我们有一个Web服务,人类用户将无法访问。即仅靠:
问题是:可以为此使用一些自定义端口(例如8080),还是应该只使用80端口(这样,URL将不包含端口号)。
优缺点都有什么?有任何原因为什么带有自定义端口的选项不可接受?
例如
<jsp:useBean id="total" class="java.util.LinkedHashMap"/>
// need somehow do something like this: total.put('key', 'value');
Run Code Online (Sandbox Code Playgroud)
但是没有使用scriptlet(它显而易见但有点难看)
[编辑]我不接受任何涉及BigInteger或其他类似低效方法的答案.请在回答之前先阅读问题!
令人讨厌的是,Java不支持无符号数字类型.您可以使用下一个更大的类型将byte,short或int转换为unsigned,例如:
short s = -10;
int unsigned_short = s & 0xFFFF;
Run Code Online (Sandbox Code Playgroud)
但是你不能长久地做到这一点,因为没有更大的类型.
那么,如何将一个签名的long转换为"unsigned"base-X,在我的情况下是base-36,然后返回?Long类具有这些方法,但将longs视为已签名,仅仅因为它们是.
我可以使用一些操作和BigInteger来做到这一点,但BigInteger 非常慢,并通过临时BigInteger创建创建垃圾.我会做很多转换(我想).我需要一个与Long.toString(long i,int radix)的默认实现一样高效的算法.
试图调整Long.toString()的代码我来:
final int RADIX = 36;
final char[] DIGITS = { '0', ... , 'Z' };
long value = 100;
if (value == 0) {
return "0";
} else {
char[] buf = new char[13];
int charPos = 12;
long i = value;
while (i != 0) {
buf[charPos--] = DIGITS[Math.abs((int) (i % RADIX))];
i /= RADIX;
}
return …Run Code Online (Sandbox Code Playgroud)