小编wvp*_*wvp的帖子

ReactJS,在React组件中按类名查找元素

我有一个React组件.一些元素将通过孩子插入.其中一些元素将具有特定的类名.如何在最外层的组件中获取这些DOM节点的列表?

<MyComponent>
  <div classname="snap"/>
  <p></p>
  <div classname="snap"/>
  <p></p>
  <div classname="snap"/>
</MyComponent>
Run Code Online (Sandbox Code Playgroud)

我想知道的是在我的组件中插入了多少个类名为"snap"的元素.

javascript reactjs

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

浮点数最多2位小数java

我试图将浮点数舍入到2位小数.

我有2个浮动值:

1.985
29.294998
Run Code Online (Sandbox Code Playgroud)

它们都需要四舍五入,所以我最终得到以下内容:

1.99
29.30
Run Code Online (Sandbox Code Playgroud)

当我使用以下方法时:

public static Float precision(int decimalPlace, Float d) {

    BigDecimal bd = new BigDecimal(Float.toString(d));
    bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
    return bd.floatValue();
  }
Run Code Online (Sandbox Code Playgroud)

结果是:

1.99
29.29
Run Code Online (Sandbox Code Playgroud)

java floating-point decimal rounding bigdecimal

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

UITableViewCellAccessoryCheckmark未在iOS 7中显示

我在单元格中显示Checkmark附件时出现问题.当我使用其他类型的配件时,它可以工作,但不能使用Checkmark附件.

它在iOS 6中完美运行,但在iOS 7上运行不佳.我何时失踪?

 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EVENT_SELECTION_CELL_IDENTIFIER forIndexPath:indexPath];
    Event *event = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = event.name;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if ([event.current boolValue]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uitableview ios

7
推荐指数
2
解决办法
6544
查看次数

Spring mvc拦截器addObject

我有一个延伸的拦截器HandlerInterceptorAdapter.

当我向我添加一个对象时,ModelAndView它也会作为路径变量添加到我的URL中,但我不希望这样.

@Override
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
    if (null == modelAndView) {
      return;
    }

    log.info("Language in postHandle: {}", LocaleContextHolder.getLocale());
    modelAndView.addObject("selectedLocale", LocaleContextHolder.getLocale());
}
Run Code Online (Sandbox Code Playgroud)

当我ModelAndView在控制器本身添加一些内容时,它不会出现在网址中.

spring-mvc interceptor

6
推荐指数
2
解决办法
4430
查看次数

Spring Data JPA @EnableJpaRepositories TypeNotPresentExceptionProxy

我有弹簧3.2.0.M2设置弹簧数据jpa 1.2.0.RELEASE.

我也有java配置.这是我的Repository配置类.

@Configuration
@EnableJpaRepositories(basePackages = {"xxx.xxx.xxx.core.dao"})
@EnableTransactionManagement
public class Repository {

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/xxxx");
        dataSource.setUsername("xxxx");
        dataSource.setPassword("xxxx");

        return dataSource;
    }

    @Bean
    public EntityManagerFactory entityManagerFactory() {
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setGenerateDdl(true);
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan("xx.xxxx.xxxx.xxxx.domain");
        factory.setDataSource(dataSource());
        factory.afterPropertiesSet();
        return factory.getObject();
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory());
        return txManager;
    }
Run Code Online (Sandbox Code Playgroud)

当我部署我的应用程序时,我得到以下异常:

(org.springframework.web.context.ContextLoader:307) - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file …
Run Code Online (Sandbox Code Playgroud)

java spring exception spring-data spring-data-jpa

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

最佳实践 - 在单元测试中设置不带setter的字段

假设您要测试以下课程:

public class SomeService {
  public String someMethod(SomeEntity someEntity) {
    return someEntity.getSomeProperty();
  }
}
Run Code Online (Sandbox Code Playgroud)

SomeEntity看起来像这样:

public class SomeEntity {
  private String someProperty;

  public getSomeProperty() {
    return this.someProperty;
  }
}
Run Code Online (Sandbox Code Playgroud)

您想要做的断言可能如下:

String result = someService.someMethod(someEntity);

assertThat(result).isEqualTo("someValue");
Run Code Online (Sandbox Code Playgroud)

你怎么能让这个测试工作?

1)在SomeEntity类中为'someProperty'添加一个setter.我不认为这是一个很好的解决方案,因为您不会更改生产代码以使测试工作.

2)使用ReflectionUtils设置此字段的值.测试看起来像这样:

 public class TestClass {
      private SomeService someService;

        @Test
          public void testSomeProperty() {
            SomeEntity someEntity = new SomeEntity();
            ReflectionTestUtils.setField(someEntity, "someProperty", "someValue");

            String result = someService.someMethod(someEntity);

            assertThat(result).isEqualTo("someValue");
          }
}
Run Code Online (Sandbox Code Playgroud)

3)在测试类中创建一个扩展SomeEntity类的内部类,并为该字段添加setter.但是,要实现此功能,您还需要更改SomeEntity类,因为该字段应该变为"受保护"而不是"私有".测试类可能如下所示:

public class TestClass {
  private SomeService someService;

  @Test
  public void testSomeProperty() {
   SomeEntityWithSetters someEntity …
Run Code Online (Sandbox Code Playgroud)

java reflection unit-testing mockito getter-setter

6
推荐指数
2
解决办法
6578
查看次数

按钮被禁用时,JQuery注册单击事件

我有一个禁用的输入按钮,在选中复选框时将启用该按钮.现在,我想要的是按钮在点击时显示警告,同时被禁用以通知用户他需要先检查复选框.

<input type="submit" disabled="disabled" id="proceedButton">
Run Code Online (Sandbox Code Playgroud)

当我单击按钮时没有任何反应,因为它被禁用

$("input#proceedButton").click(function() {
    if (!$("input#acceptCheckbox").is(':checked')) {
        alert("show me");
    }
});
Run Code Online (Sandbox Code Playgroud)

html jquery events click

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

ios segues没有导航控制器

我想用故事板来创建我的应用程序.我可以找到很多关于如何使用导航或tabcontroller的信息,但我不是其中之一.

我的目标是创建一个具有不同视图但不使用导航或tabcontroller的应用程序.我该怎么做?

xcode ios uistoryboard segue

5
推荐指数
2
解决办法
8039
查看次数

JAXRS客户端找不到邮件正文编写器

我有一个像这样配置的jaxrs客户端:

<jaxrs:client id="opaRestProxy" name="opaRestProxy"
        address="${endpoint}" serviceClass="com.test.RestProxy"
        inheritHeaders="true" threadSafe="true">
        <jaxrs:headers>
            <entry key="Accept" value="application/json" />
            <entry key="Content-Type" value="application/json" />
        </jaxrs:headers>
    </jaxrs:client>
Run Code Online (Sandbox Code Playgroud)

但是当我发送请求时,我得到以下异常:

Caused by: org.apache.cxf.interceptor.Fault: .No message body writer has been found for class : class com.test.RequestObject, ContentType : application/json.
    at org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:646)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:527)
    ... 47 more
Run Code Online (Sandbox Code Playgroud)

我的RestProxy类看起来像这样:

@Component
public interface RestProxy {

  @POST
  @Path("/getSomething")
  String getSomething(RequestObject RequestObject);
}
Run Code Online (Sandbox Code Playgroud)

java json cxf jax-rs

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

正则表达式检查单引号是否在另一个单引号之前

我想写一个正则表达式来验证单引号是否在另一个单引号之前.

有效字符串:

azerty''uiop
aze''rty''uiop
''azertyuiop
azerty''uiop''
azerty ''uiop''
azerty''''uiop
azerty''''uiop''''
Run Code Online (Sandbox Code Playgroud)

无效的字符串:

azerty'uiop
aze'rty'uiop
'azertyuiop
azerty'uiop'
azerty 'uiop'
azerty'''uiop
Run Code Online (Sandbox Code Playgroud)

java regex

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