小编luc*_*e84的帖子

SolrJ HttpSolrServer在实例化期间抛出NoHttpResponseException

尝试实例化HttpSolrServer时,SolrJ正在抛出NoHttpResponseException.谁知道为什么?

在我的代码中:

SolrServer server = new HttpSolrServer ("http://localhost:8983/solr/"); // or some other url.
Run Code Online (Sandbox Code Playgroud)

它抛出:

 javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/http/NoHttpResponseException
Run Code Online (Sandbox Code Playgroud)

我正在使用Solr和SolrJ 4.1.0

solr solrj apache-httpclient-4.x

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

以编程方式获取Rails 4中belongs_to关联的类

假设我有一些由一对多关系链接的类:

class A
  field :name, type: String
  has_many :b

class B
  field :title, type: String 
  belongs_to :a
Run Code Online (Sandbox Code Playgroud)

我们还要说我有一个B的实例,我想要检索他的belongs_to关系的类名(在我的例子'A'中,而不是链接到我的B对象的A类实例).

a = A.new name: 'my A object'
b = B.new title: 'my B object', a: a

assert_equal b.get_relationships(:belongs_to), ['A'] #substitute "get_relationships" with something that actually exists :)
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

我看了一个关于类似主题的答案(使用反射),但我无法使其成功.也许在Rails 4中有些变化?

reflection ruby-on-rails classname ruby-on-rails-4

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

如何在Grails中使用嵌入式GORM类?

GORM文档之后,我尝试将以下域类与Grails 2.2.1一起使用:

package grailscompositiontest

class ScafPerson {
    String name
    ScafAddress homeAddress
    ScafAddress workAddress

    static constraints = {
        name(nullable: false, blank: false)
    }

    static embedded = ['homeAddress', 'workAddress']
}

class ScafAddress {
    String number
    String code
}
Run Code Online (Sandbox Code Playgroud)

控制器只使用脚手架:

package grailscompositiontest

class ScafPersonController {
    static scaffold = true
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用,只要我浏览到"创建"视图就会触发服务器错误:

URI:     /GrailsCompositionTest/scafPerson/create
Class:   java.lang.NullPointerException
Message: Cannot get property 'id' on null object
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

grails scaffolding grails-orm grails-domain-class

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

Grails按日期对现有集合进行排序

我试图通过dateCreated desc对集合进行排序,但我似乎无法做到这一点.

到目前为止我尝试了什么:

 postOrder.sort({
            dateCreated: 'desc'
        })

 postOrder.sort(dateCreated: 'asc')
Run Code Online (Sandbox Code Playgroud)

有任何想法吗??

sorting grails

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

如何在不同页面上实现“检查所有”功能,仅检查jquery数据表中的当前页面数据?

我有一个表,其中包含大量记录,借助数据表进行分页。第一个标题列是全选复选框,每行都有自己的复选框。

我希望在我的表中具有以下功能:

1) 用户可以浏览表格并随机选择/取消选择复选框。

2) 单击标题中的“全选”复选框应仅选中/取消选中所有当前可见的记录。

3)“全选”按钮应为数据表的不同页面保持状态(选中/未选中)。例如,如果用户单击第 1 页上的“全选”并导航到下一页,则应取消选择“全选”复选框,再次单击该复选框将仅检查此页面中的所有行,而之前选择的复选框不受影响。

到目前为止,我有以下代码来处理检查选择:

$('#selectAllCheck').click(function(e) {

    var chk = $(this).prop('checked');
    var currentRows = $('#myTable tbody tr');

    $.each(currentRows, function(){
        $(this).find(':checkbox[name=statusCheckbox]').each(function(){
            $(this).prop('checked', chk);
        });
    });
  });
Run Code Online (Sandbox Code Playgroud)

我知道这个_('tr', {"filter":"applied"});函数,但它只是将所有行返回给我。我不知道为什么。

我已经使用上面的代码实现了(1)和(2),并且工作正常。唯一的问题是“全选”功能在不同页面上的行为。我查看了 datatables.net 但找不到与此相关的任何内容。

jquery datatables

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

下面代码中的 db.createCollection 是否总是会建立一个新的数据库?

我的 Node 工作区的 server.js 文件中有以下代码。我的问题是,每次我从 bash 命令行运行 server.js 文件时,我是否会设置一个名为 polls 的新集合?或者 MongoDb 是否认识到该集合已经存在?当我终止与 Mongo 的连接然后从命令行重新启动它时会怎么样?

mongo.connect('mongodb://localhost:27017/url-shortener', function(err, newDb){
    if(err){
        throw new Error('Database failed to connect');
    }else{
        console.log('Successfully connected to MongoDb database');
    }
    db = newDb;
    db.createCollection('polls', {
        autoIndexId: true
    });
});
Run Code Online (Sandbox Code Playgroud)

bash mongodb node.js

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

Grails从预定作业调用控制器方法

在我的grails应用程序中,我想从预定的作业类调用控制器中包含的方法.

阅读[http://www.grails.org/Job+Scheduling+(Quartz)],我可以看到数据源和服务在作业类中按名称自动连接.对于控制器来说,默认情况下这似乎是不可能的,可能是因为控制器不应该做这种事情.

顺便说一句,有没有办法从grails中的作业调用控制器方法?对你来说这可能是一个不好的做法(以及为什么)?

在此先感谢Luca

grails controller job-scheduling

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

Grails:如何在地图上放置minSize约束

我有这个对象

@Validateable
class Foo {
    Map<String, String> items

    static constraints = {
        items minSize: 1
    }
}
Run Code Online (Sandbox Code Playgroud)

但是这个测试失败了:

@Test
void shouldNotValidateIfItemsIsEmpty() {
    Foo foo = new Foo(items: [:])

    assert !foo.validate()
}
Run Code Online (Sandbox Code Playgroud)

我做错了什么?它应该根据grails'minSize'文档工作:"设置集合或数字属性的最小大小."

validation grails map grails-2.2

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

grails run-app返回"上下文初始化失败"的奇怪情况

我使用带有少量插件的grails 2.0.0.M1(spring-security-core-1.2.1,spring-cache-1.3.1).清理和编辑应用程序没有问题,只运行它.

这是执行"grails run-app --stacktrace"的结果:

ERROR [org.springframework.web.context.ContextLoader]: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
    ... 5 more
Caused by: java.lang.reflect.InvocationTargetException
    ... 5 more
Caused by: java.lang.ExceptionInInitializerError
    ... 5 more
Caused …
Run Code Online (Sandbox Code Playgroud)

grails groovy casting initialization run-app

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

如果是循环,则抛出自定义异常

public class StringArray {
    private String strArr[];

    public StringArray(int capacity) {
       strArr = new String [capacity];
    }

    public int indexOf(String s) throws StringNotFoundException {
        for(int i=0;i<strArr.length ;++i) {
            if (strArr[i].equals(s)) {
                return i;
            } else {
                throw new StringNotFoundException();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要做的是返回我正在寻找的字符串的索引,如果它在数组中,否则抛出异常.

然而Eclipse说我必须返回一个int.

那么我应该将返回类型更改为void还是有其他选项?

StringNotFoundException是我编写的自定义异常.

java arrays for-loop exception custom-exceptions

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