小编qwe*_*asd的帖子

Spring Data JPA:查询ManyToMany

我有实体UserTest

@Entity
public class User {
    private Long id;
    private String userName;
}

@Entity
public class Test {
    private Long id;

    @ManyToMany
    private Set<User> users;
}
Run Code Online (Sandbox Code Playgroud)

我可以通过用户实体获得所有测试:

public interface TestRepository extends JpaRepository<EventSettings, Long> {
    List<Test> findAllByUsers(User user);
}
Run Code Online (Sandbox Code Playgroud)

但是我可以使用哪个查询来查找所有测试userName

java spring jpa spring-data spring-data-jpa

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

React-intl多语言应用程序:更改语言和翻译存储

我有react-router app并且想添加i18n.在react-intl 示例中,IntlProvider中包含的根组件:

ReactDOM.render(
<IntlProvider locale="en">
    <App />
</IntlProvider>,
document.getElementById('container')
Run Code Online (Sandbox Code Playgroud)

);

但是只有一个区域设置.如何更新应用程序以添加其他语言以及如何存储翻译的最佳方式?

internationalization reactjs formatjs react-intl

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

在Typescript中使用npm模块

我想在Typescript项目中使用npm模块,但这个模块没有任何打字或tsd.当我尝试使用时,import Module from 'module'我遇到了一个错误:Cannot find module 'module'.有没有办法解决它?

[编辑]我的tsconfig.json:

{
  "compilerOptions": {
    "target": "ES5",
    "moduleResolution": "node",
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "sourceRoot": "src",
    "outDir": "bld"
  },
  "exclude": [
    "bld"
  ]
}
Run Code Online (Sandbox Code Playgroud)

npm typescript

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

Angular 2将事件传递给第二级子组件

在我的角度2 ngrx应用程序中,我有嵌套元素的结构:

parentContainer.ts
@Component({
  template: `<parent-component
    (onEvent)="onEvent($event)"
  ></parent-component>`,
})

class ParentContainer {
  constructor(private store: Store<IState>) { }

  private onEvent = (payload: IEventPayload) {
    this.store.dispatch(new EventAction(payload));
  }
}

parentComponent.ts
@Component({
  selector: 'parent-component',
  templateUrl: 'patent.html',
})

class ParentComponent {
  @Output() private onEvent = new EventEmitter<IEventPayload>();
}

patent.html
<div>
  ...some content

  <child-component></child-component>
</div>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我可以从父组件发出事件,我需要从子组件中执行它.有没有办法将事件通过父组件传递给子组件,然后使用这样的东西:this.onEvent.emit({... some payload})

typescript ngrx angular

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

具有ControlValueAccessor测试的Angular 2(4)组件

我想测试实现ControlValueAccessor接口的组件允许[(ngModel)]在我的自定义组件中使用,但问题是通常的输入是正确的但是ngModel- undefined.这是代码示例:

@Component({
  template: `
    <custom-component
      [usualInput]="usualInput"
      [(ngModel)]="modelValue"
    ></custom-component>`
})

class TestHostComponent {
  usualInput: number = 1;
  modelValue: number = 2;
}

describe('Component test', () => {
  let component: TestHostComponent;
  let fixture: ComponentFixture<TestHostComponent>;
  let de: DebugElement;
  let customComponent: DebugElement;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [
        CustomComponent,
      ],
      schemas: [NO_ERRORS_SCHEMA],
    }).compileComponents();
  }));
});
Run Code Online (Sandbox Code Playgroud)

所以,我希望我的customComponent中的regularInput Input()值等于1(它是真的),并且ngModel值将等于2,但是ngModel = undefined并且在调试之后我知道ControlValueAccessor writeValue方法不会在测试环境中调用(但是它适用于浏览器).那么我该如何解决呢?

jasmine karma-jasmine angular2-testing angular

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

使用 Spring El 表达式进行模板化

我想使用 spring el 进行简单的模板,例如"Some text: #{some dynamic value from map}". 就我而言,文档中的示例不适合,因为它仅适用于值形式映射:

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("property", 123);

    String message = "#data['property']";

    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setVariable("data", data);

    System.out.println(parser.parseExpression(message).getValue(context, String.class));
Run Code Online (Sandbox Code Playgroud)

在这种情况下输出是123,但String message = "Some text: #data['property']";创建了异常

org.springframework.expression.spel.SpelParseException: EL1041E:(pos 5): After parsing a valid expression, there is still more data in the expression: 'text'
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:129)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:60)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:32)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:76)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:62)
Run Code Online (Sandbox Code Playgroud)

我的错误是什么?

java spring spring-el

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

测试:模糊模拟

我想用输入测试简单的角度组件。

所以底部的一个例子几乎没有为测试做准备,并且在一个组件中应该发生test功能模糊,它显示日志,但我在控制台中没有日志。我尝试了两种情况:获取 div 原生元素并单击它并使用blur()函数输入原生元素。在 angular 应用程序中成功发生模糊,但在测试中不起作用。我该如何解决?

@Component({
  template: '<div><input [(ngModel)]="str" (blur)="testFunc($event)" /></div>'
})

class TestHostComponent {
  it: string = '';

  testFunc = () => {
    console.log('blur!!!');
  }
}

describe('blur test', () => {
  let component: TestHostComponent;
  let fixture: ComponentFixture<TestHostComponent>;
  let de: DebugElement;
  let inputEl: DebugElement;

  beforeEach(() => { /* component configuration, imports... */ }

  beforeEach(() => {
    fixture = TestBed.createComponent(TestHostComponent);
    component = fixture.componentInstance;
    de = fixture.debugElement;
    inputEl = fixture.debugElement.query(By.css('input'));
    fixture.detectChanges();
  })

  it('test', async(() => {
    const …
Run Code Online (Sandbox Code Playgroud)

jasmine karma-jasmine angular2-testing angular

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

创建反应应用程序错误

我想使用create-react-app,所以我按照说明操作:

npm install -g create-react-app
create-react-app my-app
cd my-app/
npm start
Run Code Online (Sandbox Code Playgroud)

但是我在最后一步有错误.跑完后npm start我得到错误:

无法在linux-llw5上找到一个开放端口.网络错误消息:getaddrinfo ENOTFOUND linux-llw5

我该如何解决?

reactjs create-react-app

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

阈值图像颜色 - Base64

我想使用 javaScript在 base64 字符串 ( )上使用阈值过滤器,data:image/png;base64,iVBOR...如下所示:

function threshold(base64) {
    some action whith base64 string...

    return base64; //base64 is updated by threshold filter    
}
Run Code Online (Sandbox Code Playgroud)

是否可能,如果可能,我该怎么做?

javascript base64 threshold

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

使用 ng2-translate 管道或指令作为占位符

我想使用 ng2-translate 作为占位符。我发现这样做的唯一方法是使用 ng2-translate 服务并将变量传递给占位符,如下所示:

class Form {
  placeholder: string;

  constructor(translate: TranslateService) {
    translate.get('placeholder.value').subscribe(
      (placeholder: string) => this.placeholder = placeholder,
    );
  }
}

<input type="email" placeholder={{placeholder}}/>
Run Code Online (Sandbox Code Playgroud)

但是看起来很笨重。有没有办法将 ng2-translate 用于带有管道或指令的占位符?

ng2-translate angular

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

Angular 2动画,用于平滑垂直打开和关闭块

在我的角度2应用程序中,我有静态头和切换容器的组件.我想为打开和关闭内容块添加平滑动画,但找不到合适的转换.现在我尝试使用这个动画:

trigger('expandableState', [
      transition(':enter', [
        style({ transform: 'translateY(100%)', opacity: 0 }),
        animate('500ms', style({ transform: 'translateY(0)', opacity: 1 })),
      ]),
      transition(':leave', [
        style({ transform: 'translateY(0)', opacity: 1, display: 'none' }),
        animate('500ms', style({ transform: 'translateY(100%)', opacity: 0 })),
      ]),
    ])
Run Code Online (Sandbox Code Playgroud)

但它会移动内容而不是组件的边框.这是plunker的例子.那么,我应该使用哪些样式来平滑切换内容?

css css3 css-animations angular

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