小编Mar*_*tin的帖子

找到id不在id数组中的位置

要查找其值等于id数组的id的id:

$this->YourModel->find('all', array(
    'conditions' => array(
        "YourModel.id" => array(1, 2, 3, 4)
    )
));
Run Code Online (Sandbox Code Playgroud)

我怎么能做相反的事情,找到ids与ids数组不同的元素?

cakephp cakephp-2.0

19
推荐指数
1
解决办法
3万
查看次数

如何配置Spring启动以使用两个数据库?

我使用Spring Boot 2.XHibernate 5 在不同的服务器上连接两个不同的MySQL数据库(Bar和Foo).我试图从REST控制器中的方法列出实体的所有信息(自己的属性@OneToMany@ManyToOne关系).

我已经按照几个教程来执行此操作,因此,我能够获取我的@Primary数据库(Foo)的所有信息,但是,在检索@OneToMany集合时,我总是得到我的辅助数据库(Bar)的例外.如果我将@Primary注释交换到Bar数据库,我可以从Bar数据库获取数据,但不能从Foo数据库获取数据.有办法解决这个问题吗?

这是我得到的例外:

...w.s.m.s.DefaultHandlerExceptionResolver :
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: 
    Could not write JSON document: failed to lazily initialize a collection of role: 
        com.foobar.bar.domain.Bar.manyBars, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-com.foobar.bar.domain.Bar["manyBars"]); 
    nested exception is com.fasterxml.jackson.databind.JsonMappingException:
        failed to lazily initialize a collection of role: 
        com.foobar.bar.domain.Bar.manyBars, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]->com.foobar.bar.domain.Bar["manyBars"])
Run Code Online (Sandbox Code Playgroud)

我的application.properties:

# …
Run Code Online (Sandbox Code Playgroud)

java mysql spring hibernate spring-boot

12
推荐指数
1
解决办法
2203
查看次数

如何使用PHP用HTML注释字符串(即,如何通过偏移量将HTML标记插入字符串以保留有效的HTML)?

我正在尝试在字符串中的单词之间添加HTML标签(通过html标签即HTML注释包装单词)。HTML标记应写入的位置由偏移量数组界定,例如:

//array(Start offset, End offset) in characters
//Note that annotation starts in the Start offset number and ends before the End offset number
$annotationCharactersPositions= array(
   0=>array(0,3),
   1=>array(2,6),
   2=>array(8,10)
);
Run Code Online (Sandbox Code Playgroud)

因此,要使用以下HTML标记($ tag)注释以下HTML文本($ source)。包裹由$ annotationPositions数组定界的字符(不考虑源的HTML标记)。

$source="<div>This is</div> only a test for stackoverflow";
$tag="<span class='annotation n-$cont'>";
Run Code Online (Sandbox Code Playgroud)

结果应为以下内容(https://jsfiddle.net/cotg2pn1/):

charPos   =--------------------------------- 01---------------------------- 2-------------------------------------------3------------------------------------------45-------67-----------------------------89-------10,11,12,13......
$output = "<div><span class='annotation n-1'>Th<span class='annotation n-2'>i</span></span><span class='annotation n-2'>s</span><span class='annotation n-2'> i</span>s</div> <span class='annotation n-3'>on</span>ly a test for stackoverflow"
Run Code Online (Sandbox Code Playgroud)

我如何编程下一个功能:

    $cont=0;
    $myAnnotationClass="placesOfTheWorld";
    for ($annotationCharactersPositions as $position) {
         $tag="<span class='annotation $myAnnotationClass'>"; …
Run Code Online (Sandbox Code Playgroud)

html php string dom annotate

7
推荐指数
1
解决办法
319
查看次数

Rnn神经网络预测返回意外预测

我正在试图配置RNN神经网络,以预测5种不同类型的文本实体.我正在使用下一个配置:

    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
            .seed(seed)
            .iterations(100)
            .updater(Updater.ADAM)  //To configure: .updater(Adam.builder().beta1(0.9).beta2(0.999).build())
            .regularization(true).l2(1e-5)
            .weightInit(WeightInit.XAVIER)
            .gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue).gradientNormalizationThreshold(1.0)
            .learningRate(2e-2)
            .trainingWorkspaceMode(WorkspaceMode.SEPARATE).inferenceWorkspaceMode(WorkspaceMode.SEPARATE)   //https://deeplearning4j.org/workspaces
            .list()
            .layer(0, new GravesLSTM.Builder().nIn(500).nOut(3)
                    .activation(Activation.TANH).build())
            .layer(1, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT).activation(Activation.SOFTMAX)        //MCXENT + softmax for classification
                    .nIn(3).nOut(5).build())
            .pretrain(false).backprop(true).build();
  MultiLayerNetwork net = new MultiLayerNetwork(conf);
  net.init();
Run Code Online (Sandbox Code Playgroud)

我训练它然后我评估它.有用.不过我用的时候:

 int[] prediction = net.predict(features);
Run Code Online (Sandbox Code Playgroud)

有时它会回归并出现意想不到的预测.它返回正确的预测为1,2 .... 5但有时它返回数字为9,14,12 ...这个数字不对应于已识别的预测/标签.

为什么此配置会返回意外输出?

java deep-learning deeplearning4j rnn

5
推荐指数
1
解决办法
228
查看次数

HTML如何删除标签但不删除内容

如何使用 javascript html 标签(例如 span)删除但不删除内容和内容中的 html 标签?一个例子:

<div id="content">
    <span id=1 class="note" >
        <p>   <span id=1 class="note" >hello! its one example  </span> </p>
        <li>  <span id=1 class="note" >yes,one example  </span> </li>
    </span> 
</div>
Run Code Online (Sandbox Code Playgroud)

结果应该是:

<div id="content">
    <p> hello! its one example</p><li>yes,one example</li>
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript dom

2
推荐指数
1
解决办法
2158
查看次数

使用jquery按属性删除html元素

我需要删除一个属性的元素cursor = "pointer"..我需要用html中的javascript来实现这个问题<g cursor="pointer"></g>.我不知道元素在html中有这种形式的原因.

html javascript jquery

2
推荐指数
1
解决办法
602
查看次数

当您想要搜索具有特定值的多个 HtmlObject 时,哪种 JavaScript 代码更有效?

我尝试找出哪种 JavaScript 代码更高效,例如当我搜索多个 JavaScript Span 时。

这种模式与jquery:

$('span[value='+value+']')
Run Code Online (Sandbox Code Playgroud)

或者使用标准 javascript 的这种模式:

function gEBI(id) {
    return document.getElementById(id);
}
var spans = gEBI("content").getElementsByTagName('span'); 
for (i = 0; i < this.spans.length; i++)
 { 
     if (this.spans[i].getAttribute("value") == valueThis ) { // operations } 
 }
Run Code Online (Sandbox Code Playgroud)

还有一个问题,搜索通常是更高效的 jquery 或标准 JavaScript

javascript performance jquery

2
推荐指数
1
解决办法
174
查看次数

如何将编译扩展到函数或循环

我有一个带循环的函数,我将在c ++代码中获得循环的扩展开发.我也有一个递归函数,我希望得到相同的.

我需要的一个例子:

for (i = 0; i <4; i++)
{
      printf ("%d", "example");
}
Run Code Online (Sandbox Code Playgroud)

应该导致我需要

printf ("%d", "example");
printf ("%d", "example");
printf ("%d", "example");
printf ("%d", "example");
Run Code Online (Sandbox Code Playgroud)

这是一个简单的例子.但是我需要为更复杂的功能做这件事.我使用它的价值visual c++.我不知道是否有这样的构建选项.

c++ compiler-construction performance build

1
推荐指数
1
解决办法
81
查看次数

如何使用 jquery 库将鼠标移动限制到 div

当在此 div 中按下右键时,我尝试使用 jquery 库将鼠标移动限制到 div 区域。我该怎么做?或者我能做的最好的问题?类似于限制屏幕部分的移动。

html javascript jquery mousemove

1
推荐指数
1
解决办法
1691
查看次数

如何在休眠中保留 AtomicInteger 而不是 Integer?

我尝试 使用hibernate java 框架持久保存一个具有AtomicInteger变量而不是Integer 的对象(保存后我需要在线程安全场景中使用该对象),但是当我尝试保存我的对象时,java 抛出:

java.lang.ClassCastException: java.util.concurrent.atomic.AtomicInteger cannot be cast to java.lang.Integer
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将 AtomicInteger 映射到整数吗?有一个对象的例子:

public class Statistics implements java.io.Serializable {
  private AtomicInteger id;
  private AtomicInteger totalErrors;

  public Statistics() {
  }


  public AtomicInteger getTotalErrors() {
    return this.totalErrors;
  }

  public void seTotalErrors(AtomicInteger totalErrors) {
    this.totalErrors= totalErrors;
  }
}
Run Code Online (Sandbox Code Playgroud)

以及相应的 POJO xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="Statistics" table="statistics" catalog="example" optimistic-lock="version">
      <id name="id" type="java.lang.Integer">
         <column name="id" />
         <generator …
Run Code Online (Sandbox Code Playgroud)

java multithreading hibernate jpa atomicinteger

0
推荐指数
1
解决办法
2858
查看次数