对于我正在开发的webapps,我通常使用以下文件组织,因为我认为它尊重约定:
src
|-- main
|-- resources
| |-- *.properties
| |-- *.xml
| |-- spring
| |-- applicationContext.xml (main application context config file)
|-- webapp
|-- WEB-INF
|-- spring
| |-- spring-mvc.xml (web application context config file, delegated to manage only the web part)
| |-- spring-security-http.xml (web security config)
|-- static
| |-- *.css
| |-- *.js
|-- views
| |-- *.jsp
|-- web.xml (deployment configuration)
Run Code Online (Sandbox Code Playgroud)
我想尝试的是根据以下结构组织我的文件:
src
|-- main
|-- resources
| |-- *.properties
| |-- *.xml
| …Run Code Online (Sandbox Code Playgroud) 代码
String s = "y z a a a b c c z";
Pattern p = Pattern.compile("(a )+(b )+(c *)c");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group());
}
Run Code Online (Sandbox Code Playgroud)
版画
a a a b c c
Run Code Online (Sandbox Code Playgroud)
哪个是对的.
但逻辑上,子串
a a a b c
a a b c c
a a b c
a b c c
a b c
Run Code Online (Sandbox Code Playgroud)
也匹配正则表达式.
那么,我怎样才能让代码找到那些子串呢,即不仅是最扩展的子串,还有它的子代码?
public class MyClass {
private String string;
private Object[] objects;
// constructor 1
public MyClass(String string, Object... objects) {
this.string = string;
this.objects = objects;
}
// constructor 2
public MyClass(String string) {
this.string = string;
}
public static void main(String[] args) {
MyClass myClass = new MyClass("foobar");
}
}
Run Code Online (Sandbox Code Playgroud)
在那种情况下,Java编译器是如何决定使用constructor 2而不是constructor 1?为什么没有The constructor ... is ambiguous或类似的错误发生?
PS:这个问题也适用于经典方法.
在尝试回答这个问题时,我遇到了一个奇怪的行为(这是不一样的:他的迭代太少,我的太多了):
HTML:
<button id="go">it will be legend...</button>
<div id="output"></div>
Run Code Online (Sandbox Code Playgroud)
JS:
var output = document.getElementById('output');
document.getElementById('go').onclick = function() {
output.textContent += 'wait for it...';
for (var i=0; i<3000000000; i++) {
var unused = i; // don't really care
}
output.textContent += ' dary!';
};
Run Code Online (Sandbox Code Playgroud)
循环需要几秒钟才能执行,因为它有3,000,000,000次迭代.
单击按钮后,我的预期:
wait for it... 出现dary! 出现实际发生了什么:
wait for it... dary!一起出现知道为什么会出现这种行为吗?
自己检查:小提琴.
刷新令牌的想法是,如果访问令牌被泄露,因为它是短暂的,攻击者有一个有限的窗口滥用它.
我明白了,但是如果攻击者访问刷新令牌,他们将能够获得一个新的身份验证令牌,我错了吗?这似乎只是推迟了长期存在的令牌安全漏洞......
关于这一点,你会在同一个答案中找到:
刷新令牌(如果受到攻击)是无用的,因为除了刷新令牌之外,攻击者还需要客户端ID和机密才能获得访问令牌.
那么使用刷新令牌和简单地辞职之间的区别是什么?如果您不希望用户再次重新输入,那么如何存储客户端ID和密码?
正如@FStephenQ指出的那样,刷新令牌只能使用一次:攻击者将能够获得一个新的身份验证令牌,但只能获得一次,而且只能获得一次.但是,一旦你使用了新的刷新令牌,你如何获得新的刷新令牌呢?如果你使用一个新的,那么攻击者也可以刷新他们的令牌......
实际问题是:如何让我的用户登录?在我使用的应用程序上,一旦我登录,我就不必再次登录了:他们是如何进行的?
使用 webflux 时,无法在 localhost:8080/h2-console 访问 H2 db。我在某处读到这仅在开发基于 Servlet 的应用程序时可用。但是我正在将 Webflux 与 Netty 一起使用。那么有没有办法在这样的应用中看到h2控制台呢?
我想要实现的是,通过以这种简单的方式使用多线程,在我的 RESTApi 控制器中使用 @Async 和 CompletableFuture 可以获得更好的性能吗?
这是我所做的,这是我的控制器:
@PostMapping("/store")
@Async
public CompletableFuture<ResponseEntity<ResponseRequest<CategoryBpsjResponseDto>>> saveNewCategoryBPSJ(@Valid @RequestBody InputRequest<CategoryBPSJRequestDto> request) {
CompletableFuture<ResponseEntity<ResponseRequest<CategoryBpsjResponseDto>>> future = new CompletableFuture<>();
future.complete(ResponseEntity.ok(new ResponseRequest<>("Okay", categoryBPSJService.save(request))));
return future;
}
Run Code Online (Sandbox Code Playgroud)
VS
@PostMapping("/store")
public ResponseEntity<ResponseRequest<CategoryBpsjResponseDto>> saveNewCategoryBPSJ(@Valid @RequestBody InputRequest<CategoryBPSJRequestDto> request) {
return ResponseEntity.ok(new ResponseRequest<>("okay", categoryBPSJService.save(request));
}
Run Code Online (Sandbox Code Playgroud)
正如你在我的第一个控制器函数中看到的,我在我的函数响应中添加了 CompletableFuture,但是在我的服务中,我在这一行中保存的categoryBPSJService.save(request)不是异步的,只是一个看起来像这样的简单函数:
public CategoryBpsjResponseDto save(InputRequest<CategoryBPSJRequestDto> request) {
CategoryBPSJRequestDto categoryBPSJDto = request.getObject();
Boolean result = categoryBPSJRepository.existsCategoryBPSJBycategoryBPSJName(categoryBPSJDto.getCategoryBPSJName());
if(result){
throw new ResourceAlreadyExistException("Category BPSJ "+ categoryBPSJDto.getCategoryBPSJName() + " already exists!");
}
CategoryBPSJ categoryBPSJ = new CategoryBPSJ();
categoryBPSJ = map.DTOEntity(categoryBPSJDto);
categoryBPSJ.setId(0L); …Run Code Online (Sandbox Code Playgroud) 假设我有一个Map<String, String>,我想删除所有值包含的条目foo.在优化/内存等方面,最好的方法是什么?syso下面的四个是打印相同的结果,也就是说{n2=bar}.
public static void main(String[] args) {
Map<String, String> in = new HashMap<String, String>();
in.put("n1", "foo");
in.put("n2", "bar");
in.put("n3", "foobar");
// 1- create a new object with the returned Map
Map<String, String> in1 = new HashMap<String, String>(in);
Map<String, String> out1 = methodThatReturns(in1);
System.out.println(out1);
// 2- overwrite the initial Map with the returned one
Map<String, String> in2 = new HashMap<String, String>(in);
in2 = methodThatReturns(in2);
System.out.println(in2);
// 3- use the clear/putAll methods
Map<String, …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何处理抛出已检查异常的静态最终字段初始值设定项
在这个例子中,我得到了错误的空白最后一个字段myClass的可能不被初始化:
private final static MyClass myClass; // <-- error
static {
try {
myClass = new MyClass(); // <-- throws exception
myClass.init();
} catch (Exception e) {
// log
}
}
Run Code Online (Sandbox Code Playgroud)
在那个例子中,我得到错误最终字段myClass可能已经被分配:
private final static MyClass myClass;
static {
try {
myClass = new MyClass(); // <-- throws exception
myClass.init();
} catch (Exception e) {
myClass = null; // <-- error
// log
}
}
Run Code Online (Sandbox Code Playgroud)
那个问题有什么解决方案吗?
这是一个处理复选框上不确定状态的指令:
.directive('ngIndeterminate', function() {
return {
restrict: 'A',
link: function(scope, element, attributes) {
attributes.$observe('ngIndeterminate', function(value) {
$(element).prop('indeterminate', value == "true");
});
}
};
})
Run Code Online (Sandbox Code Playgroud)
然后,例如使用这些数据:
$scope.data = [
{name: 'foo', displayed: 2, total: 4},
{name: 'bar', displayed: 3, total: 3}
];
Run Code Online (Sandbox Code Playgroud)
你只需要:
<ul ng-repeat="item in data">
<li>
<input type="checkbox" ng-indeterminate="{{item.displayed > 0 && item.displayed < item.total}}" ng-checked="item.displayed > 0" />
{{item.name}} ({{item.displayed}}/{{item.total}})
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
有没有办法在没有双卷曲符号的情况下编写ng-indeterminate表达式,就像本机ng-checked一样?
ng-indeterminate="item.displayed > 0 && item.displayed < item.total"
Run Code Online (Sandbox Code Playgroud)
我试过了:
.directive('ngIndeterminate', function($compile) {
return {
restrict: 'A', …Run Code Online (Sandbox Code Playgroud) java ×7
spring ×3
javascript ×2
ambiguous ×1
angularjs ×1
api ×1
asynchronous ×1
auth-token ×1
checkbox ×1
field ×1
final ×1
h2 ×1
java-ee ×1
loops ×1
memory ×1
optimization ×1
performance ×1
regex ×1
remember-me ×1
security ×1
substring ×1