有人能告诉我为什么这个Grails域类不会编译(在运行时)?
class Person {
String name
String getSomething(int i) {
}
}
Run Code Online (Sandbox Code Playgroud)
我运行时遇到此错误grails run-app:
2008-12-27 15:26:33.955::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext@187e184{/asrs2,C:\Steve\asrs2/web-app}
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.NullPointerException
at java.security.AccessController.doPrivileged(Native Method)
at RunApp_groovy$_run_closure2_closure7.doCall(RunApp_groovy:67)
at RunApp_groovy$_run_closure2_closure7.doCall(RunApp_groovy)
at Init_groovy$_run_closure6.doCall(Init_groovy:131)
at RunApp_groovy$_run_closure2.doCall(RunApp_groovy:66)
at RunApp_groovy$_run_closure2.doCall(RunApp_groovy)
at RunApp_groovy$_run_closure1.doCall(RunApp_groovy:57)
at RunApp_groovy$_run_closure1.doCall(RunApp_groovy)
at gant.Gant.dispatch(Gant.groovy:271)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:436)
at gant.Gant.processArgs(Gant.groovy:372)
Caused by: java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
... 13 more …Run Code Online (Sandbox Code Playgroud) 在Spring + JSP中创建超链接的正确方法是什么?必须有一种比在<a href="...">标签中编码更好的方法.以一个显示人物的页面为例.网址是people.htm.相应的控制器从数据库中获取人员并执行可选的列排序.JSP可能看起来像:
<table>
<tr>
<td><a href="people.htm?sort=name">Name</a></td>
<td><a href="people.htm?sort=age">Age</a></td>
<td><a href="people.htm?sort=address">Address</a></td>
</tr>
...
Run Code Online (Sandbox Code Playgroud)
这似乎很糟糕,因为URL people.htm在JSP中是硬编码的.应该有一种方法让Spring <a>使用中定义的URL 自动构建标记servlet.xml.
编辑:也许我应该使用Spring表单.
我在MySQL 5.0.67中使用Hibernate的JPA实现.MySQL配置为使用InnoDB.
在执行JPA查询(转换为SQL)时,我发现使用该IN子句比执行单个查询要慢.例:
SELECT p FROM Person p WHERE p.name IN ('Joe', 'Jane', 'Bob', 'Alice')
Run Code Online (Sandbox Code Playgroud)
比四个单独的查询慢:
SELECT p FROM Person p WHERE p.name = 'Joe'
SELECT p FROM Person p WHERE p.name = 'Jane'
SELECT p FROM Person p WHERE p.name = 'Bob'
SELECT p FROM Person p WHERE p.name = 'Alice'
Run Code Online (Sandbox Code Playgroud)
为什么是这样?这是MySQL的性能限制吗?
我已经看到 Fowler-Noll-Vo (FNV) 被推荐为用于我们实现一致哈希系统的快速哈希算法的不错选择。
不过,似乎无法为它找到一个好的 Java 源代码。
我已将网页的HTML存储在数据库中.
我想利用HtmlUnit查找/引用DOM元素的能力.
是否可以从字符串(通过数据库列)加载HtmlPage对象?
我正在寻找一种方法将字符串转换为int,然后提取并返回此int中的前4位数字.
注意:它必须保留为String,以便其他方法正常工作.
我为我的一个IntelliJ项目配置了检查配置文件,并选中了"共享配置文件".当我在另一个项目中时,我创建的检查配置文件不可用(不会出现在下拉组合框中).有没有办法只创建一次检查配置文件并在许多项目中使用它?
我正在运行IntelliJ 10.5.4.
我有以下代码,
class AA {
public static void main(String[] args) {
long ll = 100 ;
AA1 a1 = new AA1() ;
if(ll == 100) // Marked line
long lls [] = a1.val(ll);
}
}
class AA1 {
public long [] val (long ll1) {
long [] val = new long []{1 , 2, 3};
return val ;
}
}
Run Code Online (Sandbox Code Playgroud)
没有标记线正确执行.但是,给出带有标记线的错误".class expected".任何人都可以帮助我解决问题以及如何解决这个问题?
有人告诉我有一个按长度排序的单词列表,而那些长度相同的单词按字母顺序排序。到目前为止,这就是我所拥有的方法。
public static void doIt(BufferedReader r, PrintWriter w) throws IOException {
TreeMap<String, Integer> s = new TreeMap<String, Integer>();
ArrayList<Integer> count = new ArrayList<Integer>();
String line;
int length;
while ((line = r.readLine()) != null) {
length = line.length();
s.put(line, length);
if (!count.contains(length)){
count.add(length);
}
}
Collections.sort(count);
System.out.println(count);
}
Run Code Online (Sandbox Code Playgroud)
我的想法是使用 TreeMap 来保留字符串,并以单词的长度作为键。我还有一个 ArrayList 可以跟踪所有单词的长度,没有任何重复,然后对其进行排序。
我希望以某种方式调用 TreeMap 的键值为 5,它会列出所有包含 5 个字母的单词。
我想知道我是否在正确的轨道上?我已经玩了一个多小时,似乎无法弄清楚在这之后我应该做什么。我是从正确的角度接近这个吗?