小编Rus*_*lan的帖子

Sequelize,将实体转换为普通对象

我对javascript并不是很熟悉,并且令人惊叹,因为我无法使用ORM名称Sequelize.js从数据库中添加新属性到对象.

为了避免这种情况,我使用这个hack:

db.Sensors.findAll({
    where: {
        nodeid: node.nodeid
    }
}).success(function (sensors) {
        var nodedata = JSON.parse(JSON.stringify(node)); // this is my trick
        nodedata.sensors = sensors;
        nodesensors.push(nodedata);
        response.json(nodesensors);
});
Run Code Online (Sandbox Code Playgroud)

那么,通常的方法是向对象添加新属性.

如果它可以帮助,我使用sequelize-postgres版本2.0.x.

UPD.的console.log(节点):

{ dataValues: 
   { nodeid: 'NodeId',
     name: 'NameHere',
     altname: 'Test9',
     longname: '',
     latitude: 30,
     longitude: -10,
     networkid: 'NetworkId',
     farmid: '5',
     lastheard: Mon Dec 09 2013 04:04:40 GMT+0300 (FET),
     id: 9,
     createdAt: Tue Dec 03 2013 01:29:09 GMT+0300 (FET),
     updatedAt: Sun Feb 23 2014 01:07:14 GMT+0300 (FET) },
  __options: 
   { timestamps: true,
     createdAt: …
Run Code Online (Sandbox Code Playgroud)

node.js sequelize.js

72
推荐指数
9
解决办法
8万
查看次数

抛出并捕获异常,或使用instanceof?

我在变量中有一个异常(没有抛出).

什么是最好的选择?

Exception exception = someObj.getExcp();
try {
    throw exception;
} catch (ExceptionExample1 e) {
    e.getSomeCustomViolations();
} catch (ExceptionExample2 e) {
    e.getSomeOtherCustomViolations(); 
}
Run Code Online (Sandbox Code Playgroud)

要么

Exception exception = someObj.getExcp();
if (exception instanceof ExceptionExample1) {
    exception.getSomeCustomViolations();
} else if (exception instanceof ExceptionExample2) {
    exception.getSomeOtherCustomViolations();
}
Run Code Online (Sandbox Code Playgroud)

java performance exception instanceof throws

21
推荐指数
2
解决办法
2万
查看次数

部署到tomcat时出错

我用的是apache-tomcat-7.0.37

Git:https://github.com/IRus/jMusic

应用程序部署时:

[2013-03-15 10:52:11,542] Artifact jMusic:war exploded: Artifact is being deployed, please wait...
Mar 15, 2013 10:52:17 AM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1553)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:792)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:792)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1486)
    at …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat spring-mvc catalina

10
推荐指数
2
解决办法
2万
查看次数

Kotlin:什么是kjsm文件?

我一直在尝试按照本教程使用Kotlin - > js编译器.

当我运行时kotlinc-js --help,帮助文本提到以下内容:

-kjsm    Generate kjsm-files (for creating libraries)
Run Code Online (Sandbox Code Playgroud)

什么是kjsm文件?

javascript kotlin

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

使用JAXB进行部分解组

我想部分解组大XML.

XML具有以下结构:

<Records>
    <Contract>
        ...
    </Contract>
    <Contract>
        ...
    </Contract>
    ...
    <Contract>
        ...
    </Contract>
    <Contract>
        ...
    </Contract>
</Records>
Run Code Online (Sandbox Code Playgroud)

使用XJC生成结果类:

- Records
    |- Contract
Run Code Online (Sandbox Code Playgroud)

如果我按照这些(来自jaxb-ri的样本),我得到错误:

Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"http://somedomain.com", local:"Contract"). Expected elements are <{http://somedomain.com}Records>
Run Code Online (Sandbox Code Playgroud)

如果我使用:

<jaxb:globalBindings localScoping="toplevel"/>
Run Code Online (Sandbox Code Playgroud)

我收到错误:

org.xml.sax.SAXParseException: A class/interface with the same name "com.my.package.Text" is already in use. Use a class customization to resolve this conflict.
Run Code Online (Sandbox Code Playgroud)

但我需要改变很多课程.这不是解决方案.

xml binding jaxb xjc

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

集合成为原始类型

例如,我们有一些AbsractClass

package inherit;

import java.util.HashSet;
import java.util.Set;

/**
 * TODO: Add comment
 *
 * @author Ruslan Ibragimov
 */
public abstract class AbstractClass<T extends Integer> {

    private Set<String> strings = new HashSet<>();

    private T value;

    public Set<String> getStrings() {
        return strings;
    }

    public void setStrings(Set<String> strings) {
        this.strings = strings;
    }

    public void addString(String string) {
        strings.add(string);
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }
}
Run Code Online (Sandbox Code Playgroud)

还有一些孩子:

package inherit;

/**
 * TODO: …
Run Code Online (Sandbox Code Playgroud)

java generics inheritance

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

Spring Batch重试策略和跳过策略问题

我在批处理作业中有以下步骤.

    <batch:step id="parse-step">
        <batch:tasklet>
            <batch:chunk reader="xmlCommonReader"
                         processor="xmlCommonProcessor"
                         writer="xmlCommonWriter"
                         commit-interval="1">
                <batch:skip-policy>
                    <bean class="org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy" scope="step"/>
                </batch:skip-policy>
                <batch:retry-policy>
                    <bean class="org.springframework.retry.policy.NeverRetryPolicy" scope="step"/>
                </batch:retry-policy>
            </batch:chunk>
        </batch:tasklet>
        <batch:next on="FAILED" to="file-failed-step"/>
        <batch:next on="COMPLETED" to="file-success-step"/>
        <batch:listeners>
            <batch:listener ref="parseStepExecutionListener"/>
            <batch:listener ref="parseStepSkipListener"/>
        </batch:listeners>
    </batch:step>
Run Code Online (Sandbox Code Playgroud)

当一些异常抛出时,我在parseStepSkipListener中捕获他并登录数据库.

我期待以下行为:

  1. 工作开始了
  2. 执行前面的步骤
  3. 开始执行解析步骤
  4. 阅读项目
  5. 处理项目
    1. Ooooops,例外.
    2. 捕获异常,登录数据库,转到下一个块(读取,处理,写入).
  6. 继续执行其他步骤.
  7. 完成工作.

但实际上我得到以下行为:

  1. 工作开始了
  2. 执行前面的步骤
  3. 开始执行解析步骤
  4. 阅读项目
  5. 处理项目
    1. Ooooops,例外.
    2. 处理项目
    3. 写项目
      1. Ooooops,例外.
      2. 捕获异常,登录数据库,转到下一个块(读取,处理,写入).
  6. 继续执行其他步骤.
  7. 完成工作.

因此,一大块数据尝试处理和写入两次.

spring spring-batch

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

Kotlin实例化不可变列表

我已经开始使用Kotlin作为java的替代品并且非常喜欢它.但是,如果没有跳回到java-land,我一直无法找到解决方案:

我有一个Iterable<SomeObject>并且需要将其转换为列表,因此我可以多次迭代它.这是一个不可变列表的明显应用,因为我需要做的就是多次读取它.我如何在开始时将这些数据实际放入列表中?(我知道这是一个界面,但我一直无法在文档中找到它的实现)

可能的(如果不满意)解决方案:

val valueList = arrayListOf(values)
// iterate through valuelist
Run Code Online (Sandbox Code Playgroud)

要么

fun copyIterableToList(values: Iterable<SomeObject>) : List<SomeObject> {
    var outList = ArrayList<SomeObject>()
    for (value in values) {
        outList.add(value)
    }
    return outList
}
Run Code Online (Sandbox Code Playgroud)

除非我误解,否则这些最终MutableLists会有效,但感觉就像是一种解决方法.是否有类似的immutableListOf(Iterable<SomeObject>)方法将实例化一个不可变的列表对象?

immutability kotlin

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

Spring roo可以处理gradle项目吗?

我想知道,那个春天的roo正在使用maven作为构建工具,并创建了maven项目.

是否支持gradle,或计划支持gradle?

gradle spring-roo

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