小编ski*_*kip的帖子

迭代CopyOnWriteArrayList时出现UnsupportedOperationException

我在一本书中看到了以下陈述:

任何基于写入复制IteratorListIterator(例如添加,设置或删除)调用的变异方法都会抛出UnsupportedOperationException.

但是,当我运行以下代码时,它工作正常,并没有抛出UnsupportedOperationException.

List<Integer> list = new CopyOnWriteArrayList<>(Arrays.asList(4, 3, 52));
System.out.println("Before " + list);
for (Integer item : list) {
    System.out.println(item + " ");
    list.remove(item);
}
System.out.println("After " + list);
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了以下结果:

Before [4, 3, 52]
4 
3 
52 
After []
Run Code Online (Sandbox Code Playgroud)

为什么我在list使用该remove方法修改给定时没有得到异常?

java collections concurrency iterator copyonwritearraylist

2
推荐指数
1
解决办法
212
查看次数

将 Duration.ofDays(1) 和 period.ofDays(1) 添加到夏令时附近的 ZonedDateTime 之间的区别

美国/东部时区夏令时于 11 月 1 日凌晨 2 点结束。结果,凌晨 2 点变成了凌晨 1 点。

我无法理解下面给出的代码中的以下内容:

  1. 为什么第 2 行显示时间 09:00,而不是 10:00(添加 1 天)?
  2. 为什么第 4 行显示时间 10:00,而不是 09:00(添加 24 小时)?

    LocalDateTime ld = LocalDateTime.of(2015, Month.OCTOBER, 31, 10, 0);
    
    ZonedDateTime date = ZonedDateTime.of(ld, ZoneId.of("US/Eastern"));
    System.out.println(date);       //line 1 - 2015-10-31T10:00-04:00[US/Eastern]
    
    date = date.plus(Duration.ofDays(1));
    System.out.println(date);       //line 2 - 2015-11-01T09:00-05:00[US/Eastern]
    
    date = ZonedDateTime.of(ld, ZoneId.of("US/Eastern"));
    System.out.println(date);       //line 3 - 2015-10-31T10:00-04:00[US/Eastern]
    
    date = date.plus(Period.ofDays(1));
    System.out.println(date);       //line 4 - 2015-11-01T10:00-05:00[US/Eastern]
    
    Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗?

java datetime dst java-8 zoneddatetime

2
推荐指数
1
解决办法
573
查看次数

JSP表达式语言不起作用

我无法${}在我的.jsp页面上运行表达式.

displayAllCustomers.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<html>
    <body>
        <h3>Our Entire Customer Database</h3>
        <ul>
            <c:forEach items="${allCustomers}" var="customer">
                <li>${customer.name}</li>
            </c:forEach>
        </ul>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

调度员servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                      http://www.springframework.org/schema/tx
                                      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                                      http://www.springframework.org/schema/aop 
                                      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <import resource="applicationContext.xml"/>     

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>


    <bean name="/displayAllCustomers" class="mypackage.DisplayAllCustomersController">
        <property name="customerManagementService" ref="customerManagementService" />
    </bean>     

</beans>
Run Code Online (Sandbox Code Playgroud)

DisplayAllCustomersController.java

public class DisplayAllCustomersController {

    private CustomerManagementService customerManagementService;
    public void setCustomerManagementService(CustomerManagementService customerManagementService) {
        this.customerManagementService = customerManagementService; …
Run Code Online (Sandbox Code Playgroud)

jsp spring-mvc spring-3

1
推荐指数
2
解决办法
1万
查看次数

Spring Security 3.0.3.RELEASE:ArtifactTransferException:无法传输

以下是解决依赖关系时spring spring 3的错误:

Multiple annotations found at this line:
    - Missing artifact org.springframework.security:org.springframework.security.web:jar:3.0.3.RELEASE
    - ArtifactTransferException: Failure to transfer 
     org.springframework.security:org.springframework.security.web:jar:3.0.3.RELEASE from http://
     repository.springsource.com/maven/bundles/release was cached in the local repository, resolution will not be 
     reattempted until the update interval of com.springsource.repository.bundles.release has elapsed or updates are 
     forced. Original error: Could not transfer artifact org.springframework.security:org.springframework.security.web:jar:
     3.0.3.RELEASE from/to com.springsource.repository.bundles.release (http://repository.springsource.com/maven/
     bundles/release): connection timed out to http://repository.springsource.com/maven/bundles/release/org/
     springframework/security/org.springframework.security.web/3.0.3.RELEASE/
     org.springframework.security.web-3.0.3.RELEASE.jar
Run Code Online (Sandbox Code Playgroud)

以下是我的pom文件中定义的spring security 3依赖项的方法:

        <!-- Spring Security dependencies -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>org.springframework.security.acls</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>org.springframework.security.config</artifactId> …
Run Code Online (Sandbox Code Playgroud)

spring spring-security pom.xml maven-3

1
推荐指数
1
解决办法
5492
查看次数

Hibernate 5:org.hibernate.MappingException:未知实体

以下代码适用于Hibernate 4.3,但是当我使用Hibernate 5.0尝试相同的代码时,会导致以下错误:

Exception in thread "main" org.hibernate.MappingException: Unknown entity: entity.Message
    at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
    at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1451)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:100)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:678)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:670)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:665)
    at client.Main.main(Main.java:14)
Run Code Online (Sandbox Code Playgroud)

有人可以帮我理解为什么会这样吗?


以下是用于测试示例的代码:

Main.java

package client;
import org.hibernate.Session;
import util.HibernateUtil;
import entity.Message;

public class Main {
    public static void main(String[] args) {        
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        Message message = new Message( "Hello Hibernate 5" );

        session.save(message);    

        session.getTransaction().commit();
        session.close();    
    }
}
Run Code Online (Sandbox Code Playgroud)

HibernateUtil.java

package util;
import org.hibernate.SessionFactory; …
Run Code Online (Sandbox Code Playgroud)

java mysql hibernate hibernate-mapping hibernate-5.x

1
推荐指数
1
解决办法
6838
查看次数

如何在单击浏览器后退按钮后显示当前页面

即使在用户点击浏览器后退按钮后,是否可以继续显示同一页面?

它就像一个多步骤表单,在提交时会重定向到结果页面,一旦表单提交,我不希望用户能够使用浏览器后退按钮导航回任何以前的页面.因此,我希望在单击后退按钮时向用户显示相同的结果页面.只需单击后退按钮的URL可以从历史记录更改为以前的URL,但我不希望用户返回到任何以前的页面.

如果可能的话,有人可以建议我如何实现这一点.

编辑:说有3个步骤的一些过程,然后生成的页面一样../step1,../step2,../step3,../resulting page.用户可以使用后退和前进按钮来播放这些步骤,但是一旦提交了步骤3并且用户在,../resulting page我希望用户仅在保持结果页面的同时显示先前显示的页面的URL.

javascript jquery

0
推荐指数
1
解决办法
2251
查看次数

Hibernate:不成功的alter table

我正在使用Hibernate 4,我想快速测试@OrderColumn注释但是我在尝试这样做时遇到以下错误:

INFO [main] (SchemaExport.java:343) - HHH000227: Running hbm2ddl schema export
DEBUG [main] (SchemaExport.java:353) - Import file not found: /import.sql
DEBUG [main] (SqlStatementLogger.java:104) - 
    alter table Order 
        drop 
        foreign key FK48E972E19D16493
Hibernate: 
    alter table Order 
        drop 
        foreign key FK48E972E19D16493
ERROR [main] (SchemaExport.java:425) - HHH000389: Unsuccessful: alter table Order drop foreign key FK48E972E19D16493
ERROR [main] (SchemaExport.java:426) - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax …
Run Code Online (Sandbox Code Playgroud)

mysql hibernate nhibernate-mapping

0
推荐指数
1
解决办法
9832
查看次数

如何使用取消按钮返回模型的先前状态

我在这里有这个plunkr ,它显示了一个可编辑的表格.

以下是表格的HTML代码:

  <body ng-controller="MainCtrl">
    <table style="width:100%">
  <tr>
    <th>Name</th>
    <th>Is enabled?</th>        
    <th>Points</th>
  </tr>
  <tr ng-repeat="fooObject in fooObjects | orderBy:'points'">
    <td><input ng-model="fooObject.name" ng-disabled="fooState!='EDIT'"/></td>
    <td><input ng-model="fooObject.isEnabled" ng-disabled="fooState!='EDIT'"/></td>     
    <td><input ng-model="fooObject.points" ng-disabled="fooState!='EDIT'"/></td>
    <td>
      <a href="#" ng-click="handleEdit(fooObject, 'EDIT', $index)">Edit</a>
      <a href="#" ng-click="handleEditCancel(fooObject, 'VIEW', $index)">Cancel</a>
    </td>
  </tr>
</table>
  </body>
Run Code Online (Sandbox Code Playgroud)

我希望Cancel行中的链接显示前一个状态,fooObject就好像该行从未被触及一样.

以下是AngularJS控制器中的代码,它似乎只要我"orderBy:'points'"ng-repeat表达式中没有,但是不起作用:

app.controller('MainCtrl', function($scope) {
  $scope.fooObjects = [
    {"name": "mariofoo", "points": 65, "isEnabled": true}, 
    {"name": "supermanfoo", "points": 47, "isEnabled": false}, 
    {"name": "monsterfoo", "points": 85, "isEnabled": true}
    ]; …
Run Code Online (Sandbox Code Playgroud)

html-table edit dirty-data angularjs angularjs-ng-repeat

-2
推荐指数
1
解决办法
2162
查看次数

BiFunction&lt;X, X&gt; 和 BinaryOperator&lt;X&gt; 的区别

我无法理解为什么BinaryOperator<Integer>可以A在下面的代码中放置在的位置,而不是BiFunction<Integer, Integer>

A foo = (a, b) -> { return a * a + b * b; };
int bar = foo.apply(2, 3);
System.out.println(bar);
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我理解它。

java java-8 java-stream functional-interface

-2
推荐指数
1
解决办法
1072
查看次数