我创建了一个代码模板来添加记录器和相应的导入:
${:import(org.apache.log4j.Logger)}
private static final Logger logger = Logger.getLogger(${enclosing_type}.class);
Run Code Online (Sandbox Code Playgroud)
如果我现在添加它,记录器总是从行的开头开始,即使我的光标已经缩进了。有没有办法强制放置在光标位置?
这是一个屏幕截图来显示我的意思:

====>>>>

编辑:格罗夫的回答在这个特定案例中有所帮助。但是这个例子怎么样呢?我还想向记录器添加评论。如果我在同一行中定义这样的模板,那么记录器实际上会与注释出现在同一行中。
${:import(org.apache.log4j.Logger)}
/**
* Logger
*/ private static final Logger logger = Logger.getLogger(${enclosing_type}.class);
Run Code Online (Sandbox Code Playgroud) 如果我在开发模式下在eclipse中运行我的GWT应用程序并在浏览器中点击一段时间,我总是在eclipse中遇到"内存不足"错误.我的电脑有16 GB Ram,从未使用超过8GB.
我尝试了几个配置参数.我的运行配置中的VM参数包含以下参数:" - Xms8192m -Xmx8192m"
即使在eclipse.ini中我测试了几个配置参数,现在它看起来像这样:
--launcher.XXMaxPermSize
8192M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
8192m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms8192m
-Xmx8192m
Run Code Online (Sandbox Code Playgroud)
但我仍然得到错误.有什么方法可以防止这种情况吗?
如果我使用"GO"语言生成SHA-256哈希,我会得到一个与Java等效的字节数不同的字节数组.
这是GO版本:
fmt.Println(getSha256([]byte("5nonce=5")))
Run Code Online (Sandbox Code Playgroud)
结果数组如下所示:
41 79 186 235 199 123 95 226 16 59 51 161 112 245 192 50 21 66 180 250 179 109 153 18 233 148 16 237 156 69 163 150]
Run Code Online (Sandbox Code Playgroud)
这个应该在Java代码中做同样的事情:
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update("5nonce=5".getBytes());
byte[] digest = md.digest();
Run Code Online (Sandbox Code Playgroud)
但结果是这个字节数组
[41, 79, -70, -21, -57, 123, 95, -30, 16, 59, 51, -95, 112, -11, -64, 50, 21, 66, -76, -6, -77, 109, -103, 18, -23, -108, 16, -19, -100, 69, -93, -106]
Run Code Online (Sandbox Code Playgroud)
他们为什么不同?如何更改java版本才能像Go版本一样工作?
我找到了以下 HTML 通知示例,它在 Chrome 和 Firefox 中运行良好。下载并在本地尝试后,它不再在 Chrome 中工作。这是预期的行为(Chrome 出于某种原因在本地阻止通知)还是有任何其他原因导致这不起作用?
<!DOCTYPE html>
<html>
<body>
<button onclick="notifyMe()">Notify me!</button>
<script>
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to …Run Code Online (Sandbox Code Playgroud) 我在我的HTML页面中为facebook和google提供了一些meta标签,但是eclipse在"property"和"itemprop"上显示了警告.我尝试了不同的doctypes,但它没有验证.有没有办法摆脱警告而不禁用HTML文档的验证?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Facebook meta tags -->
<meta property="og:title" content="My Title" />
<meta property="og:description" content="My Description" />
<!-- Meta tags for google. -->
<meta itemprop="name" content="My Title"/>
<meta itemprop="description" content="My Description"/>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)

我有两个非常简单的对象,一个对象应该在一个集合中以"一对多"关系包含另一个对象.对象在数据库中正确插入,但"children"表中的外键始终为"null".
我无法弄清楚原因:
这是测试对象,它将子项保存在其集合中:
@Entity
@Table(name="test")
public class TestObj {
public TestObj(){}
private Long id;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private Set<Children> children = new HashSet<Children>();
@OneToMany(mappedBy = "testObj", cascade = CascadeType.ALL)
public synchronized Set<Children> getChildren() {
return children;
}
public synchronized void setChildren(Set<Children> children) {
this.children = children;
}
public void addChildren(Children child){
children.add(child);
}
}
Run Code Online (Sandbox Code Playgroud)
这是子对象,它包含"TestObj"的反向链接:
@Entity
@Table(name = "children")
public class Children {
public Children(){} …Run Code Online (Sandbox Code Playgroud) 如果我在eclipse中创建一个GWT项目而没有选中"生成示例代码"复选框,我将得到一个非常空的项目(如预期的那样).所有需要的文件都有一个向导:
但是:我如何生成所需的module.nocache.js文件?
我想国际化我的GWT应用程序.阅读文档后,我看不出使用常量而不是消息的原因.消息似乎在各方面都更加强大.
有没有理由使用常数?他们是否比消息有更好的性能或任何其他优势?
我看到了一些像这样的漂亮风格的下拉框,想要创建我自己的下拉框:

用于创建箭头的CSS非常简单.它只是将一个unicode字符作为内容添加到元素的类之前;
.select:before{
content: "\f0d7";
}
Run Code Online (Sandbox Code Playgroud)
我自己尝试了,但是没有显示角色,因为角色不包含在像Arial这样的默认语言中:
我当然可以包含一个包含这个字符的字体,但我认为要为该错误添加另一个~100kb的页面需要很多开销.
有没有其他好的解决方案来存档这个箭头样式没有额外的字体或图像?
我想解析一个字符串并得到"stringIAmLookingFor"它的一部分,它"\_"在结尾和开头被包围.我正在使用正则表达式匹配,然后删除"\_"找到的字符串中的.这是有效的,但我想知道是否有一个更优雅的方法来解决这个问题?
String test = "xyz_stringIAmLookingFor_zxy";
Pattern p = Pattern.compile("_(\\w)*_");
Matcher m = p.matcher(test);
while (m.find()) { // find next match
String match = m.group();
match = match.replaceAll("_", "");
System.out.println(match);
}
Run Code Online (Sandbox Code Playgroud) 我以“005056963AB75FD48BDC59C100314C40”之类的格式获取UUID,并想验证它们。我试过这样的代码:
public boolean isUUID(String uuid){
try {
UUID.fromString(uuid);
} catch (Exception e) {
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
但这会告诉我“005056963AB75FD48BDC59C100314C40”不是有效ID。另一方面,站点http://guid.us/Test/GUID告诉我它是,并给我一个添加了“-”的 UUID。是否有一种优雅的方法可以在 Java 中验证此 UUID,还是必须手动将“-”添加到正确的位置?
我使用以下代码插入了Google Analytics(分析).
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xyz-1', 'xyz.com');
ga('send', 'pageview');
</script>
Run Code Online (Sandbox Code Playgroud)
现在我想跟踪我的ajax应用程序中的特定页面.以下链接介绍了如何将事件推送到Google Analytics(分析):
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
如果我尝试执行以下命令,我只是得到错误,说"_gaq"没有定义.
_gaq.push(['_trackPageview', 'myPage']);
Run Code Online (Sandbox Code Playgroud)
我在这里做错了还是文档已经过时了?
编辑:所以似乎有一个新的API.相当于:
_gaq.push(['_trackPageview', 'myPage']);
Run Code Online (Sandbox Code Playgroud)
这是新API中的相同命令吗?
ga('send', 'pageview', 'myPage);
Run Code Online (Sandbox Code Playgroud)