我需要编写一个方法,它接受一个String并解析它的链接(一个href).如果它找到了一个链接,它应该在链接中添加target ="_ blank",如果它还没有.
示例:Inputstring"
<a href="www.google.com">Google</a> and <a href="www.yahoo.com"> target="_blank">Yahoo</a> are search engines
Run Code Online (Sandbox Code Playgroud)
...应该导致输出String
<a href="www.google.com" target="_blank">Google</a> and <a href="www.yahoo.com" target="_blank">Yahoo</a> are search engines
Run Code Online (Sandbox Code Playgroud)
知道如何实现这个吗?
我@RunWith(Parameterized.class)在Test类上使用Annotation运行参数化的jUnit测试.但是现在我还需要运行我的测试类PowerMockRunner,因此使用注释@RunWith(PowerMockRunner.class).显然这是不可能的,因为只@RunWith允许一个注释.
如何在不使用注释的情况下实现参数化测试@RunWith(Parameterized.class)?
我需要在Java和php中编写一个明文,其结果必须相同.
给出以下条件:
以下代码可以工作并满足第一个和第二个要求,但它使用ECB作为模式,因此不使用初始化向量:
PHP:
<?php
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
$cleartext = 'abcdefghijklmnop';
$key128 = '1234567890123456';
$iv = '1234567890123456';
if (mcrypt_generic_init($cipher, $key128, $iv) != -1) //Parameter iv will be ignored in ECB mode
{
$cipherText = mcrypt_generic($cipher,$cleartext );
mcrypt_generic_deinit($cipher);
printf(bin2hex($cipherText));
}
?>
Run Code Online (Sandbox Code Playgroud)
输出为:fcad715bd73b5cb0488f840f3bad7889
JAVA:
public class AES {
public static void main(String[] args) throws Exception {
String cleartext = "abcdefghijklmnop";
String key = "1234567890123456";
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, …Run Code Online (Sandbox Code Playgroud) 我有几个带有ids country1,country2的下拉框,...当国家/地区在下拉列表中更改时,国家/地区的值将显示在警告框中.
如果我为这样的一个框添加onchange处理程序,它工作正常:
$('#country1') .live('change', function(e){
var selectedCountry = e.target.options[e.target.selectedIndex].value;
alert(selectedCountry);
});
Run Code Online (Sandbox Code Playgroud)
但我需要动态地为所有下拉框执行此操作,所以我尝试了:
$(document).ready(function() {
$('[id^=country]') .each(function(key,element){
$(this).live('change', function(e){
var selectedCountry = e.target.options[e.target.selectedIndex].value;
alert(selectedCountry);
});
});
});
Run Code Online (Sandbox Code Playgroud)
这不起作用.没有语法错误,但是当更改选择的国家/地区时没有任何反应.我确信每个循环都执行了几次,并且数组包含选择框.
有什么想法吗?
谢谢,保罗
我有两个相互依赖的项目.
假设项目maven1有一个类A,项目maven2有一个对类B的引用.我基本上想要的是我可以编译和测试项目maven2所以我添加了maven1作为依赖它并设置范围提供,因为我没有想要包含maven1(如果我把范围编译就好了,例如将它留下)在项目maven1中我添加了项目maven2作为依赖,范围为"compile",因为我希望它在运行时包含它.
在eclipse中,我收到一条错误消息:
A cycle was detected in the build path of project 'maven2'. The cycle consists of projects {maven1, maven2}
Run Code Online (Sandbox Code Playgroud)
它似乎也引起了eclipse的一些问题,但我一般想问我的配置是否有效.
感谢帮助!
我想用JQuery调用Spring REST WebService.
我的控制器中有两种方法:
@RequestMapping(value="/{id}", method=RequestMethod.GET)
public @ResponseBody User getUser(@PathVariable long id, Model model){
return new User("TestUser");
}
@RequestMapping(value="/{id}", method=RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateUser(@PathVariable long id, @Valid User user){
user.getName();
}
Run Code Online (Sandbox Code Playgroud)
User类看起来像这样:
public class User {
private String name;
public User(){};
public User(String name){this.name = name;}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
};
Run Code Online (Sandbox Code Playgroud)
}
现在,当我调用http://localhost:8080/demo/user/2结果时,{"name":"TestUser"}就像预期的那样.
但是在尝试修改资源时,我尝试这样做:
$.ajax({
url: "http://localhost:8080/demo/user/2",
dataType: "json",
data: '{"name":"NewTestUser"}',
type: "PUT",
success: function(){alert('success');}
});
Run Code Online (Sandbox Code Playgroud)
我可以在Debugmode中看到调用了正确的方法(updateUser),但User对象的实例变量名始终为null.谁能告诉我我做错了什么?谢谢!