小编ris*_*ide的帖子

请解释一下:insertable = false,updatable = false

如果某个字段有注释insertable=false, updatable=false,这是否意味着您不能插入值也不能更改现有值?你为什么想这么做?

@Entity
public class Person {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToMany(mappedBy="person", cascade=CascadeType.ALL)
    private List<Address> addresses;
}

@Entity
public class Address {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne
    @JoinColumn(name="ADDRESS_FK")
    @Column(insertable=false, updatable=false)
    private Person person;
}
Run Code Online (Sandbox Code Playgroud)

java jpa eclipselink java-ee

132
推荐指数
5
解决办法
12万
查看次数

有没有办法在for-each循环迭代开始之前避免空值检查?

每次我必须迭代一个集合时,我最终都会检查null,就在for-each循环的迭代开始之前.像这样:

if( list1 != null ){
    for(Object obj : list1){

    }
}
Run Code Online (Sandbox Code Playgroud)

是否有更短的方法,以便我们可以避免编写"if"块?注意:我使用的是Java 5,并且会在一段时间内坚持使用它.

java foreach for-loop

106
推荐指数
9
解决办法
11万
查看次数

Angular2错误:没有将"exportAs"设置为"ngForm"的指令

我在RC4上,我收到错误由于我的模板,没有指令"exportAs"设置为"ngForm":

<div class="form-group">
        <label for="actionType">Action Type</label>
        <select
            ngControl="actionType" 
      ===>  #actionType="ngForm" 
            id="actionType" 
            class="form-control" 
            required>
            <option value=""></option>
            <option *ngFor="let actionType of actionTypes" value="{{ actionType.label }}">
                {{ actionType.label }}
            </option>
        </select> 
    </div>
Run Code Online (Sandbox Code Playgroud)

boot.ts:

import {disableDeprecatedForms, provideForms} from '@angular/forms'; 

 import {bootstrap} from '@angular/platform-browser-dynamic';
 import {HTTP_PROVIDERS, Http} from '@angular/http';
 import {provideRouter} from '@angular/router';

import {APP_ROUTER_PROVIDER} from './routes';

import {AppComponent} from './app.component';

bootstrap(AppComponent, [ disableDeprecatedForms(), provideForms(), APP_ROUTER_PROVIDER, HTTP_PROVIDERS]);
Run Code Online (Sandbox Code Playgroud)

///所以这是我的DropdownList:

<fieldset ngControlGroup="linkedProcess" >
                     <div ngControlGroup="Process" >
                         <label>Linked Process</label>
                          <div class="form-group">       
        <select 
            ngModel
            name="label" 
            #label="ngModel" 
            id="label" …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-forms angular

102
推荐指数
5
解决办法
12万
查看次数

是否可以重命名Hashmap密钥?

我正在寻找一种重命名Hashmap密钥的方法,但我不知道它是否可以在Java中使用.

java hashmap

83
推荐指数
4
解决办法
7万
查看次数

表单控件的值访问器没有名称:'recipient'

升级到Angular 2 Rc.5后出现此错误.这是我的组件模板:

<md-input
    [(ngModel)]="recipient"
    name="recipient"
    placeholder="Name"
    class="col-sm-4"
    (blur)="addRecipient(recipient)">
</md-input>
Run Code Online (Sandbox Code Playgroud)

我的app.module.ts导入了 FormsModule

我也尝试private recipient;在我的组件中声明.

我错过了什么吗?为什么我会收到此错误?

No value accessor for form control with name: 'recipient'
Run Code Online (Sandbox Code Playgroud)

typescript angular-material2 angular

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

错误:"遇到未定义的提供程序!通常这意味着您有一个循环依赖项"

这是我在Angular/TypeScript应用程序中遇到的一个无用的错误.在有人更好地提出错误消息之前,我们可以做些什么呢?导致这种情况发生的最可能的情况是什么?

Uncaught Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.
    at Object.syntaxError 
    at eval     at Array.forEach (native) [<root>]
    at CompileMetadataResolver._getProvidersMetadata 
    at CompileMetadataResolver.getNgModuleMetadata 
    at CompileMetadataResolver.getNgModuleSummary 
    at eval 
...
Run Code Online (Sandbox Code Playgroud)

typescript angular

58
推荐指数
5
解决办法
6万
查看次数

在调用save()之前,必须手动分配此类的ID:

Caused by: org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save(): com.rfid.model.Role; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.rfid.model.Role
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:748)
    at com.wfos.engine.wrapper.domain.impl.WrapperImpl.save(WrapperImpl.java:159)
    ... 47 more
    Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.rfid.model.Role
    at org.hibernate.id.Assigned.generate(Assigned.java:53)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:685)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:677)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:673)
    at …

java hibernate identifier

57
推荐指数
3
解决办法
11万
查看次数

跟踪滚动位置并通知其他组件

有一种简单的方法可以跟踪浏览器滚动位置并通知多个组件吗?

使用案例:在滚动时,我希望能够根据我的位置更改页面上各种元素的类.在以前版本的角度中,它有点可能通过插件(对于jQuery来说相同).当然,可以选择编写裸JS来在应用程序启动时初始化它并发出一个事件,但这听起来很脏,并且事件发射对于这类事情而言相当昂贵.

我有什么选择?


更新(建议后):

这是我尝试过的:

我创建了一个组件:

import {Component} from "angular2/core";

@Component({
    selector: '[track-scroll]',
    host: {'(window:scroll)': 'track($event)'},
    template: ''
})

export class TrackScrollComponent {
    track($event) {
        console.debug("Scroll Event", $event);
    }
}
Run Code Online (Sandbox Code Playgroud)

在app的主指令中添加了一个属性:

<priz-app track-scroll>
Run Code Online (Sandbox Code Playgroud)

并将该组件添加为顶级组件中的提供者之一:

import {TrackScrollComponent} from "../../shared/components/track-scroll.component";

@Component({
  selector: 'priz-app',
  moduleId: module.id,
  templateUrl: './app.component.html',
  directives: [ROUTER_DIRECTIVES, SecureRouterOutlet, AppHeader, TrackScrollComponent],
  providers: [AuthenticationService]
})
Run Code Online (Sandbox Code Playgroud)

依然没有...


另一个更新:

移动track-scroll到主模板的div元素之一:

<div class="container-fluid" track-scroll>
    <div class="row">
        <div class="col-md-12">
            <app-header></app-header>
            <secure-outlet signin="Login" unauthorized="AccessDenied"></secure-outlet>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

现在,应用程序加载了一个完全空的屏幕.FUN FUN FUN ...


最终解决方案(对我有用).

  1. 定义指令:
import {Directive} …
Run Code Online (Sandbox Code Playgroud)

events scroll typescript angular

45
推荐指数
3
解决办法
7万
查看次数

无法让Jacoco使用离线工具与Powermockito合作

鉴于Jacoco在"动态"工具时不能很好地与PowerMockito配合使用,我一直在尝试配置离线工具,希望这能为我提供适用于使用PowerMockito的类的单元测试覆盖率.

我已经将我的pom设置如下,但我的测试课程仍然保持0%的覆盖率.任何帮助都非常感激,因为它让我慢慢疯狂!

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mandy</groupId>
    <artifactId>jacoco-test</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>jacoco-test Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <powermock.version>1.5.4</powermock.version>
        <jacoco.version>0.7.1.201405082137</jacoco.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <classifier>runtime</classifier>
            <version>${jacoco.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>restore-report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>restore-instrumented-classes</goal>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin> …
Run Code Online (Sandbox Code Playgroud)

java powermock jacoco

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

到期时间@cacheable spring boot

我已经实现了缓存,现在我想添加一个到期时间.

如何在春季启动时设置到期时间@Cacheable

这是一段代码:

@Cacheable(value="forecast",unless="#result == null")
Run Code Online (Sandbox Code Playgroud)

java caching spring-cache

30
推荐指数
5
解决办法
4万
查看次数