小编RJo*_*RJo的帖子

如何在Angular 2服务中注入Document

我有一个Angular2应用程序.为了Document在测试中模拟 对象,我想将它注入服务,如:

import { Document } from '??' 

@Injectable()
export class MyService {
  constructor(document: Document) {}
}
Run Code Online (Sandbox Code Playgroud)

Titleangular 的服务使用内部getDOM()方法:

https://github.com/angular/angular/blob/master/modules/%40angular/platform-b​​rowser/src/browser/title.ts

有没有简单的方法将文档注入服务?另外,我应该如何在providers数组中引用它?

typescript angular

55
推荐指数
3
解决办法
5万
查看次数

不可变的@ConfigurationProperties

是否可以使用Spring Boot的@ConfigurationProperties注释创建不可变(最终)字段?以下示例

@ConfigurationProperties(prefix = "example")
public final class MyProps {

  private final String neededProperty;

  public MyProps(String neededProperty) {
    this.neededProperty = neededProperty;
  }

  public String getNeededProperty() { .. }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的方法:

  1. 创建@Bean了的MyProps两个类的构造函数
    • 提供两个构造函数:empty和with neededPropertyargument
    • bean是用.创建的 new MyProps()
    • 在该领域的结果 null
  2. 使用@ComponentScan@Component提供MyPropsbean.
    • 结果BeanInstantiationException- >NoSuchMethodException: MyProps.<init>()

我得到它的唯一方法是为每个非最终字段提供getter/setter.

java spring properties-file spring-boot

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

验证AngularJS中的不可见和禁用字段

有没有办法在AngularJS中进行条件验证?我试图解决的问题基本上是一个单选按钮列表,根据选择启用/禁用输入.以下图像描述了该问题.第一个文本输入只接受字母,第二个只接受数字.两者都有ng-patternng-required设定.(Plunker上的工作示例)

有问题的屏幕截图

我想要实现的是,当选择单选按钮时,验证将关闭相应的输入字段.

我曾希望ng-disabled将true 设置为true可以防止为有问题的表单控件设置无效状态,但唉,事实并非如此.

到目前为止,我发现的唯一解决方案是在选择另一个选项并将其设置ng-required为false 时清除输入.是否有任何合理的方法来实现这一点,或者是完全从DOM中取出元素的唯一解决方案?

forms validation angularjs

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

Lambdaj FinalClassArgumentCreators的应用程序范围配置.在哪里以及如何做到这一点?

我们在配置lambdaj以使用Joda Time时遇到问题.由于LocalDate是最终的类,Lambdaj需要初始化如下:( 参见bug 70)

public class LocalDateArgumentCreator implements FinalClassArgumentCreator<LocalDate> {
    private final long MSECS_IN_DAY = 1000L * 60L * 60L * 24L;
    public LocalDate createArgumentPlaceHolder(int seed) {
        return new LocalDate((long)seed * MSECS_IN_DAY);
    }
}
ArgumentsFactory.registerFinalClassArgumentCreator(LocalDate.class, new LocalDateArgumentCreator());
Run Code Online (Sandbox Code Playgroud)

由于我们需要在几乎所有地方应用此配置,因此我们缺乏如何实现此配置的选项.我们的应用程序是基于Spring和Wicket的Web应用程序.

我提出了三种不同的选择:

1.核心maven模块中的静态初始化块

由于核心模块包含在每个其他模块中,因此所有模块都包含该类.剩下的问题是,即使没有对目标类的引用,静态块总是会被初始化吗?

public final class LambdajInitializer {
    static {
        // initialize like above
    }
}
Run Code Online (Sandbox Code Playgroud)

2.初始化bean applicationContext.xml

缺点:从未对非Spring测试进行初始化

示例:在applicationContext-core.xml中(包含在每个模块中)

<bean class="...LambdajInitializer" />

public class LambdajInitializer {
    @PostConstruct
    public void init() {
        // Lambdaj initialization
    } …
Run Code Online (Sandbox Code Playgroud)

java spring static static-initialization lambdaj

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

在JPA2/Hibernate中使用重写的equals/hashCode审核@Embeddables的集合

我有JPA2/Hibernate的设置.此外,实体由Hibernate Envers审核.我有以下类来表示只有一个字段的邮政编码,即value.

当只保存任何邮政编码的一个实例时,一切正常Set<PostalCode>.但是,当我尝试添加另一个邮政编码时,审核失败并出现以下异常:

Caused by: javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [PostalCodesAudit#{PostOffice_id=5, revision_id=DefaultRevisionEntity(id = 16, revisionDate = Aug 19, 2013 8:50:05 AM), revisionType=ADD}]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1359)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:80)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:513)
... 58 more
Run Code Online (Sandbox Code Playgroud)

这里奇怪的是,它工作正常,当我删除的实现equals,并hashCodePostalCode类,该机制运行良好.此外,如果我将集合更改为Set<String>,类似的映射工作完美.

我不是绝对需要实现equalshashCodePostalCode类,但我不是在下探支撑过于敏锐,无论是.

映射这种情况的正确方法是什么?

实体

@Embeddable
public class PostalCode {
    @Column(name = "postalCode", length = 5)
    @Pattern(regexp = "[0-9}{5}")
    private …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa equals hashcode hibernate-envers

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

SVG使用和渐变作为填充

我一直在尝试将SVG图标外部化为文件,并使用标记来引用它们<svg><use xlink:href="file.svg#icon" /></svg>.从理论上讲,这非常有效,但不同的浏览器在渲染方面存在问题.所有浏览器都能够<use>在文件内部引用符号并直接打开svg文件的URL 时正确呈现svg .

简而言之,linearGradient在引用标记中的符号时,是否有一种跨浏览器的方式来使SVG 作为元素的填充工作<svg><use/></svg>

我设置了一个说明问题的plunker:http://plnkr.co/edit/feKvZ7?p = preview

简化后,标记如下:

<!DOCTYPE html>
<html>
  <body>
    <h1>SVG sprite test</h1>
    <svg width="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <use xlink:href="icon.svg#icon" />
    </svg>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

SVG文件如下所示:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <linearGradient id="gradient">
      <stop offset="0" stop-color="black" />
      <stop offset="1" stop-color="white" />
    </linearGradient>
  </defs>
  <symbol id="icon" viewBox="0 0 100 100">
    <circle cx="50" cy="50" r="40" stroke="black" fill="url(#gradient)" />
  </symbol>

  <use id="iconuse" xlink:href="#icon" width="100" height="100" />

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

这就是它在不同浏览器中的样子: 在不同浏览器中渲染符号的线性渐变的不同结果

html svg svg-sprite

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

如何绑定Spring Data REST实体来传输对象?

我们有两个具有客户端 - 服务器架构的Spring Boot应用程序.后端配置了Spring Data REST + JPA.前端应该消耗后端公开的资源并提供公共REST API.

是否可以通过声明例如mapper bean使Spring数据自动从DTO映射到域对象?

// JPA persistable
@Entity
public class Order { .. }

// Immutable DTO
public class OrderDto { .. } 

// Is this somehow possible..
@RepositoryRestResource
public interface OrderDtoRepository extends CrudRepository<OrderDto, Long> {}

// .. instead of this?
@RepositoryRestResource
public interface OrderRepository extends CrudRepository<Order, Long> {}
Run Code Online (Sandbox Code Playgroud)

data-transfer-objects spring-data-jpa spring-data-rest

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

将QueryDsl查询实体用作dao字段是否是线程安全的

使用QueryDsl查询实体是否是线程安全的,如下所示

public class MyDaoImpl implements MyDao {

    private static final QEntity entity = QEntity.entity;

    public List<Entity> entities() {
        return new JPAQuery(em).from(entity).list(entity);
    }

    public List<Entity> otherEntities() {
        return new JPAQuery(em).from(entity).where(entity.foo.isNull()).list(entity);
    }
}
Run Code Online (Sandbox Code Playgroud)

相反:

public class MyDaoImpl implements MyDao {

    public List<Entity> entities() {
        QEntity entity = QEntity.entity;
        return new JPAQuery(em).from(entity).list(entity);
    }

    public List<Entity> otherEntities() {
        QEntity entity = QEntity.entity;
        return new JPAQuery(em).from(entity).where(entity.foo.isNull()).list(entity);
    }
}
Run Code Online (Sandbox Code Playgroud)

thread-safety querydsl

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

Querydsl null-safe concatenation

假设你有相应的类在表中的以下数据Person,什么是搜索空安全地场的串联的正确方法name1name2

@Entity
public class Person {
    Long id;
    String name1;
    String name2;
    // Getters and setters omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)
id |  name1  | name2   
------------------------
1  |  Foo    | null
2  |  null   | Bar
3  |  Foo    | Bar

默认情况下,两列的连接将导致nullif为null.

public List<String> nameConcatenations() {
    JPAQuery q = new JPAQuery(entityManager);
    QPerson person = QPerson.person;
    StringExpression nameConcatenation = person.name1.concat(person.name2);
    return q.from(person).list(nameConcatenation)
}
Run Code Online (Sandbox Code Playgroud)

以上代码导致以下列表:

null
null
FooBar
Run Code Online (Sandbox Code Playgroud)

java database null data-access-layer querydsl

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

Sass mixin前置选择器

是否可以进行SASS混合以将其输出放在选择器的前面?我使用Modernizr检查浏览器的svg功能。当支持svg时,它将svg类输出到<html>元素。

我希望background-image根据svg功能进行更改。基本上,这就是我需要的:

.container .image { background-image: url('some.png'); }
html.svg .container .image { background-image: url('some.svg'); }
Run Code Online (Sandbox Code Playgroud)

我希望在SCSS中拥有一个混合,可以@include通过以下方式进行:

.container {
  .image {
    background-image: url('some.png');
    @include svg-supported {
      background-image: url('some.svg');
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

不必写:

.container {
  .image {
    background-image: url('some.png');
  }
}

@include svg-supported {
  .container {
    .image {
      background-image: url('some.svg');
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这有可能吗?

sass mixins

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

Spring @Autowire同一类的两个bean,它们没有在ApplicationContext中定义

我正在使用Spring MVC应用程序并遇到了问题.我是Spring的新手,所以如果我的工作有点笨拙,请原谅我.基本上我有一个java类ContractList.在我的应用程序中,我需要这个类的两个不同的对象(它们都必须是单例)

public class MyClass {
    @Autowired
    private ContractList contractList;

    @Autowired
    private ContractList correctContractList;

    .. do something..
}
Run Code Online (Sandbox Code Playgroud)

请注意,这两个bean都没有在ApplicationContext.xml中定义.我只使用注释.因此,当我尝试访问它们时 - contractList和correctContractList最终引用同一个对象.有没有办法以某种方式区分它们而不在ApplicationContext.xml中显式定义它们?

spring dependency-injection autowired

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

禁用嵌入式servlet加载

我有一个使用Spring Boot开发的批处理应用程序.我的批处理应用程序需要依赖关系spring-boot-starter-web.具体来说,我需要一个REST客户端spring-hateoasjackson-databind支持.如何禁用嵌入式Tomcat启动?我需要使用什么排除?

@EnableAutoConfiguration(excludes = {
   /** What do I need to put here? */
})
@EnableBatchProcessing
@EnableConfigurationProperties
@ComponentScan
public class MyBatchApplication {
  public static void main(String... args) {
    SpringApplication.run(MyBatchApplication.class, args);
  }
}
Run Code Online (Sandbox Code Playgroud)

至少,这些还不够,因为它以一个例外结束:

@EnableAutoConfiguration(exclude = {
  EmbeddedServletContainerAutoConfiguration.class,
  WebMvcAutoConfiguration.class,
  EmbeddedTomcat.class,
  DispatcherServletAutoConfiguration.class
})
Run Code Online (Sandbox Code Playgroud)

例外是:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
Run Code Online (Sandbox Code Playgroud)

rest spring-batch spring-boot

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