我有大量的项目,在他们的pom.xml中有相同的URL:
<url>https://github.com/malkusch/${project.artifactId}</url>
<scm>
<connection>scm:git:git://github.com/malkusch/${project.artifactId}.git</connection>
<developerConnection>scm:git:git@github.com:malkusch/${project.artifactId}.git</developerConnection>
<url>https://github.com/malkusch/${project.artifactId}</url>
</scm>
<issueManagement>
<system>github</system>
<url>https://github.com/malkusch/${project.artifactId}/issues</url>
</issueManagement>
Run Code Online (Sandbox Code Playgroud)
所以我认为把它放到父pom.xml中是一个好主意.但有效的pom会产生奇怪的$ {project.artifactId}:
<parent>
<groupId>de.malkusch.parent</groupId>
<artifactId>oss-parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<groupId>de.malkusch.localized</groupId>
<artifactId>localized</artifactId>
<url>https://github.com/malkusch/localized/localized</url>
<scm>
<connection>scm:git:git://github.com/malkusch/localized.git/localized</connection>
<developerConnection>scm:git:git@github.com:malkusch/localized.git/localized</developerConnection>
<url>https://github.com/malkusch/localized/localized</url>
</scm>
<issueManagement>
<system>github</system>
<url>https://github.com/malkusch/localized/issues</url>
</issueManagement>
Run Code Online (Sandbox Code Playgroud)
您注意到只有issueManagement.url已正确解析.其他的都很奇怪,特别是$ {project.artifactId} .git - > localized.git/localized.我正在使用Maven 3.0.4.我使用了一些未定义的功能吗?这是一个错误吗?
我们的应用程序目前使用当地时间而不是UTC.我知道使用UTC非常重要,但不能为我的生活记住原因.
假设DateTimes存储有偏移量,当将本地时间与UTC时间进行比较时,或者与具有不同时区的其他时间进行比较时,任何值得使用的库肯定会知道不同的时区并将两个对象变为可以是相比?
只要偏移量与DateTime一起传递(比如说它将使用对象而不是字符串),我不明白为什么它很重要.我为什么要处理2014-09-01T13:44:13+00:00而不是2014-09-01T14:44:13+01:00?实际上,存储为UTC会丢失偏移信息(声明时间的本地时间).
我在这里错过了什么?
上下文:我们有限制,一个一个样式的错误,我想'啊哈:把所有的东西都转移到UTC'然后意识到我只是通过代码转换一堆DateTime对象来使用UTC时区这让我感到很浪费时间.
A Stream是AutoCloseable基于I/O的,应该在try-with-resource块中使用.通过插入的基于中间I/O的流flatMap()怎么样?例:
try (var foos = foos()) {
return foos.flatMap(Foo::bars).toArray(Bar[]::new);
}
Run Code Online (Sandbox Code Playgroud)
与
try (var foos = foos()) {
return foos.flatMap(foo -> {
try (var bars = foo.bars()) {
return bars;
}
}).toArray(Bar[]::new);
}
Run Code Online (Sandbox Code Playgroud)
该flatMap()文件说:
每个映射的流在其内容放入此流后关闭.
嗯,这是快乐的道路.如果之间发生异常怎么办?那条流是否会保持未封闭状态并可能泄漏资源?那么我是否应该总是使用try-with-resource也用于中间流?
我想知道什么是使会话bean线程安全的最佳实践.
我们假设我有这个会话bean及其服务:
@Component
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
class Cart {
private HashSet<Item> items = new HashSet<Item>();
private int counter = 0;
public HashSet<Item> getItems() {
return items;
}
public int getCounter() {
return counter;
}
}
@Service
class CartService {
@Autowired
private Cart cart;
public void addItem(Item item) throws FullException {
if (cart.getCounter() > 1234) {
throw new FullException();
}
cart.getItems().add(item);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码不是线程安全的,并且当多个线程(同一会话,例如异步Ajax请求)执行时,将导致问题CartService.addItem(Item).
我想我不是第一个遇到这个问题的人,但是我的研究并没有带给我最佳实践.
我可以做的最糟糕的事情是同步addItem(),因为CartService由多个会话共享.在购物车中同步在CartService.addItem()我看来同样糟糕,因为Cart是一个代理bean.我理解,因为所有会话仍然会在同一个对象上同步.
一种可接受的解决办法似乎是在同步块Cart.getItems()中CartService.addItem():
@Service
class CartService …Run Code Online (Sandbox Code Playgroud) 在SQL中,您不应该引用整数,因为如果引用,它将是一个字符串.
但我很好奇如果我这样做会出现什么问题/并发症?
例如:(
SELECT * FROM table WHERE id = 1正确)
与
SELECT * FROM table WHERE id = '1'(不正确)
Ps在这个问题上没有找到任何重复.如果有,请纠正我
我正在编写一些PHP代码,我通过电子邮件验证检查结束它.有人可以审查它并确认它是否是一个好的解决方案?
<?php
function isTrue($var) {
return (isset($var)) ? TRUE : FALSE;
}
function len($str) {
$i;
for($i=0; isTrue($str[$i]); $i++) {
/* count me */
}
return $i;
}
function parsMe($str) {
$at; $dot; $isvalid=0; $isnotvalid=0;
for ( $at=0; isTrue($str[$at]); $at++) {
if ( $str[$at] == "@" ) {
for ( $dot=$at+1; isTrue($str[$dot]); $dot++ ) {
if ( $str[$dot] == "." ) $isvalid += 1;
if ( $str[$dot] =="@" || $str[len($str)-1] == "@" || $str[len($str)-1] == "." ) {
die("Error email …Run Code Online (Sandbox Code Playgroud) 我有一个Spring MVC控制器抛出两种异常:
@RequestMapping(value = "forwardRefundApply",method = RequestMethod.GET)
public ModelAndView forwardRefundApply1(String ticketNbr)throws Exception {
if(true)
throw new Exception();
else
throw new ApplicationException("test");
}
Run Code Online (Sandbox Code Playgroud)
然后我编写了一个AOP类来处理异常,然后像这样返回Model:
@Pointcut("execution(public * ..*(..))")
public void getRefundPointCut() {
}
@AfterThrowing(pointcut="getRefundPointCut()", throwing="e")
public ModelAndView throwException(Exception e){
ModelAndView mav = null;
if(e instanceof ApplicationException)
{
e.printStackTrace();
mav = new ModelAndView(CommonConstants.ERRORPAGE);
mav.addObject("errorMsg", "application error");
return mav;
}
else{
e.printStackTrace();
mav = new ModelAndView(CommonConstants.ERRORPAGE);
mav.addObject("errorMsg", "system error");
return mav;
}
}
Run Code Online (Sandbox Code Playgroud)
唉是工作.但结果是错误.系统错误:
org.springframework.web.util.NestedServletException:处理程序处理失败; 嵌套异常是java.lang.NoSuchMethodError
Aspect类是不是可以将ModelAndView返回给Controller?
这些天我发现了这个奇怪的代码片段"10" == "0xa",其评估结果为true.我在文档中找到的最好的是关于Type Juggling:
变量的类型由使用变量的上下文决定
但我没有在该代码片段中看到任何整数上下文.虽然询问周围的人似乎接受了这一功能.我听到的一个解释是PHP会将它们作为数字进行比较.所以我对一些有效的10个表达式(使用PHP-5.6.5)做了一些数字比较:
<?php
var_dump(
0b1010, "10" == "0b1010", // false
012, "10" == "012", // false
0xa, "10" == "0xa", // true
1E+1, "10" == "1E+1", // true
1e1, "10" == "1e1", // true
10.0, "10" == "10.0", // true
+10, "10" == "+10" // true
);
Run Code Online (Sandbox Code Playgroud)
手册中记录了这种行为在哪里?
编辑:请在示例代码的上下文中理解该问题.这应该强调二进制和八进制表示与其余表示之间的不一致.