有人可以向我解释一下编译器在第一次投射时不会抱怨,但是在第二次投射中是否会抱怨?
interface I1 { }
interface I2 { }
class C1 implements I1 { }
class C2 implements I2 { }
public class Test{
public static void main(){
C1 o1 = new C1();
C2 o2 = new C2();
Integer o3 = new Integer(4);
I2 x = (I2)o1; //compiler does not complain
I2 y = (I2)o3; //compiler complains here !!
}
}
Run Code Online (Sandbox Code Playgroud) 假设我们有一个实体Person,一个控制器PersonController和一个edit.jsp页面(创建一个新的或编辑一个现有的人)
调节器
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String editPerson(@RequestParam("fname") String fname, Model model) {
if(fname == null || fname.length() == 0){
model.addAttribute("personToEditOrCreate", new Person());
}
else{
Person p = personService.getPersonByFirstName(fname);
model.addAttribute("personToEditOrCreate", p);
}
return "persons/edit";
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String savePerson(Person person, BindingResult result) {
personService.savePerson(person);
return "redirect:/home";
}
Run Code Online (Sandbox Code Playgroud)
文件edit.jsp
<form:form method="post" modelAttribute="personToEditOrCreate" action="save">
<form:hidden path="id"/>
<table>
<tr>
<td><form:label path="firstName">First Name</form:label></td>
<td><form:input path="firstName" /></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName" /></td>
</tr>
<tr> …Run Code Online (Sandbox Code Playgroud) 我试图使用jquery fullcalendar.事件数据来自使用JSON的服务器.我的页面有一个下拉元素和fullcalendar div.
我需要的是每次用户更改下拉列表时刷新日历.应将下拉列表的选定值发布到服务器以获取新的事件数据
这是我的代码
$(document).ready(function() {
$('#calendar').fullCalendar({
events: {
url : '/myfeed',
data : {personId : $('#personDropDown').val() }
}
});
$('#personDropDown').change(function(){
$('#calendar').fullCalendar('refetchEvents');
});
});
Run Code Online (Sandbox Code Playgroud)
但上面的代码不起作用.有帮助吗?
让我们假设,有一个Tree对象,具有根TreeNode对象,并且每个TreeNode都有leftNode和rightNode对象(例如BinaryTree对象)
如果我打电话:
myTree = null;
Run Code Online (Sandbox Code Playgroud)
树中相关的TreeNode对象真的会发生什么?将垃圾收集,或者我必须设置树对象内的所有相关对象?
我试图理解DHT协议如何工作,特别是在文件共享洪流世界.我阅读了很多文章,但我仍然与文件名值哈希生成混淆.
我的dht如何工作如下:让我说我加入了一个p2p网络,我想分享一些文件.对于这些文件,生成散列映射密钥并通过网络"遍历",直到访问负责这些生成的密钥的节点.然后,这些节点中的每一个都在其列表中添加一条记录,该记录显示"具有x IP地址的人具有与指定密钥相关的文件.
当我搜索文件时,会为该文件生成hashmap密钥并在网络中传输,直到找到负责此密钥的节点.然后该节点与我通信并向我发送承载真实数据的节点的IP地址
我的上述情况是否正确?
我试着使用Like按钮的XFBML实现,正如facebook社交插件页面中所描述的那样
类似按钮出现并正常工作(它要求确认操作,但它工作正常).
当我按下"赞"按钮时,会弹出一个新的对话框注释框,让我添加一些评论以显示在我的墙上.但是,当我按下"发布到Facebook"按钮时,没有任何反应,弹出对话框仍然存在.最后,评论不会出现在我的Facebook墙上.
任何帮助?
我有一个实体(作者)和一个控制器动作,呈现所有作者.
def index = {
def list = Author.list()
render(view: 'index', model: ['allauthors' : list])
}
Run Code Online (Sandbox Code Playgroud)
呈现页面时,将按预期执行单个查询:
Hibernate:
select
this_.id as id0_0_,
this_.version as version0_0_,
this_.name as name0_0_
from
author this_
Run Code Online (Sandbox Code Playgroud)
但是,当我按下Refresh(F5)然后为每个作者执行一个select语句(这里我有3个作者):
Hibernate:
select
author0_.id as id0_0_,
author0_.version as version0_0_,
author0_.name as name0_0_
from
author author0_
where
author0_.id=?
Hibernate:
select
author0_.id as id0_0_,
author0_.version as version0_0_,
author0_.name as name0_0_
from
author author0_
where
author0_.id=?
Hibernate:
select
author0_.id as id0_0_,
author0_.version as version0_0_,
author0_.name as name0_0_
from
author author0_
where
author0_.id=? …Run Code Online (Sandbox Code Playgroud) 我有两个regexpressions:
[a-c] : any character from a-c
[a-z] : any character from a-z
Run Code Online (Sandbox Code Playgroud)
并测试:
public static void main(String[] args) {
String s = "abcde";
String[] arr1 = s.split("[a-c]");
String[] arr2 = s.split("[a-z]");
System.out.println(arr1.length); //prints 4 : "", "", "", "de"
System.out.println(arr2.length); //prints 0
}
Run Code Online (Sandbox Code Playgroud)
为什么第二次分裂表现得像这样?我希望有一个带有6个空字符串""结果的reslut.
模型:
class Author{
String name
static hasMany = [books: Book]
}
class Book{
String name
Author author
static belongsTo = Author
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个控制器
class MyController{
def authors{
def authors = Author.getAll()
render authors as JSON
}
Run Code Online (Sandbox Code Playgroud)
问题是,即使Author-Books关联是懒惰的,也会执行N + 1个查询以急切地获取每个作者的书籍.它发生了什么以及如何禁用它
我需要一个查询来更新一个字段.如果传递的参数为null,则不要使用参数的null值更新它
update myTable
set myField1 = :param1
Run Code Online (Sandbox Code Playgroud)
环境:hibernate和oracle
我试图用gmail帐户发送带有邮件插件的电子邮件.电子邮件已成功发送,但我的电子邮件发件人有问题
在Config.groovy中
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "myacount@gmail.com"
password = "mypassword"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
Run Code Online (Sandbox Code Playgroud)
然后从我的应用程序,我打电话
mailService.sendMail {
to "another@gmail.com"
from "sender@gmail.com"
subject sub
body message
}
Run Code Online (Sandbox Code Playgroud)
电子邮件被发送到another@gmail.com,但发件人不是sender@gmail.com而是myaccount@gmail.com.有什么建议?
我是groovy-grails的新手.
以下是域级别的声明:
static hasMany = [ posts : Post, tags : Tag, following : UserAccount ]
Run Code Online (Sandbox Code Playgroud)
这是什么样的对象?即它是一个时髦的地图?以及如何从语句中删除对象类型?
grails ×4
java ×3
hibernate ×2
json ×2
annotations ×1
associations ×1
casting ×1
dht ×1
eager ×1
email ×1
fullcalendar ×1
grails-orm ×1
groovy ×1
interface ×1
jquery ×1
oracle ×1
p2p ×1
plugins ×1
regex ×1
sender ×1
spring-mvc ×1
sql ×1
xfbml ×1