小编rob*_*del的帖子

编译发现gradle的错误版本

我使用spring boot2。在一个多Java项目中。

我尝试构建我的主库(尚无Java文件)

apply plugin: 'java-library-distribution'


plugins {
    id 'org.springframework.boot' version '2.0.0.M7'
}

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}


dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.0.M7'
    compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
        testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.0.M7'
}

distributions {
    main{
        baseName = 'common-model'
    }
}

sourceCompatibility = 1.8

tasks.withType(JavaCompile) {
    options.compilerArgs = ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
}
Run Code Online (Sandbox Code Playgroud)

在我的gradle /包装器中,我有

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-bin.zip
Run Code Online (Sandbox Code Playgroud)

我得到的错误

引起原因:org.gradle.api.internal.plugins.PluginApplicationException:无法应用插件[id'org.springframework.boot']

原因:org.gradle.api.GradleException:Spring …

gradle spring-boot

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

在R中乘以两个矩阵

我有2个矩阵.

第一个: [1,2,3]

第二个:

[3,1,2
 2,1,3
 3,2,1]
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种方法来增加它们.

结果应该是: [11, 13, 10]

在R中,mat1%*%mat2不起作用.

r matrix

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

只保留数字,字母和删除空格

我试着只保留字母和数字

String str = "it's too hard & jean say";
String strNew = str.replaceAll("[^A-Za-z0-9\\s]", "");
Run Code Online (Sandbox Code Playgroud)

我尝试使用此代码但不删除空格.

所以我搜索一种方法来删除它.

java regex

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

解析包含日期,时间和偏移量的时间戳

我正在使用Java 5.

我需要解析ISO 8601格式的日期时间字符串,例如2011-11-30T12:00:00.000+00:00:

String dateString = "2011-11-30T12:00:00.000+00:00";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 
Date parsed=null;
try {
    parsed = df.parse(dateString);
}
Run Code Online (Sandbox Code Playgroud)

我也试过这个模式:yyyy-MM-dd'T'HH:mm:ss.SSSz但是得到相同的结果:

java.text.ParseException: Unparseable date: "2011-11-30T12:00:00.000+00:00"
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

java date iso8601

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

减少类型参数

在抽象课中,我有

public abstract class BaseService<T, R extends BaseDto<ID>, ID extends Object> {
    ...
}
Run Code Online (Sandbox Code Playgroud)

而不是通过三个参数,我想通过两个,做类似的事情

public abstract class BaseService<T, R extends BaseDto<ID extends Object>> 
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

> expected
'{' expecte
wrong number of type arguments; required 1
Run Code Online (Sandbox Code Playgroud)

java generics

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

在@RequestParam注释中为默认值分配null

我使用Spring Boot。

在 REST 控制器中,当我们使用注释为字符串参数@RequestParam设置默认值时,有没有办法?null

spring spring-restcontroller

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

带有 thymeleaf 转义字符的内联 javascript

我用百里香和春天。我尝试做内联javascript。

<script th:inline="javascript">

    $("#genericTable").bootstrapTable({
        url: /*[[${url}]]*/ 'generic',
        ...
     });    
Run Code Online (Sandbox Code Playgroud)

在服务器端我做

 model.addAttribute("url", "/rest/vehicles");
Run Code Online (Sandbox Code Playgroud)

我得到

url: "\/rest\/vehicles",

为什么有些字符被添加到字符串中?

编辑

url: /*[[@{${url}}]]*/ 'generic',
Run Code Online (Sandbox Code Playgroud)

第一个 / 就像已删除,因此调用无效...

spring html-escape-characters thymeleaf

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

Java流无匹配多个条件

在dto to bean转换中,

我尝试仅在bean中找不到dto时才添加dto ...或者如果dto的id为null

我使用没有匹配的流.

当我尝试添加许多汽车时,只添加第一个

 List<Car> cars = bean.getCar();
 List<CarDto> carsDto = dto.getCar();

 for (CarDto carDto : carsDto) {

     if (cars.stream().noneMatch(e -> Objects.equals(e.getId(), carDto.getId()) || carDto.getId()==null )) {

        //get car from bd....

        bean.addCar(car);
    }

}
Run Code Online (Sandbox Code Playgroud)

java java-8

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

与迭代器的ConcurrentModificationException

在我有一个DTO

public class ProductTypesDto extends BaseDto {
  private List<Integer> colors = new ArrayList<>();
  ...
}
Run Code Online (Sandbox Code Playgroud)

在我的豆子里

@Entity
public class ProductTypes 
   @ManyToMany
   private Set<Colors> colors = new HashSet<>();
   ...
}
Run Code Online (Sandbox Code Playgroud)

用户可以添加和删除颜色 productTypes

在DTO to bean转换中,我这样做

private void convertToBeans(ProductTypesDto dto, ProductTypes beans) {
    //add element
    for (Integer color : dto.getColors()) {
        if (beans.getColors().stream().noneMatch(e -> Objects.equals(e.getId(), color))) {
            Optional<Colors> optColors = colorsRepository.findById(color);
            if (optColors.isPresent()) {
                beans.addColor(optColors.get());
            }
        }
    }
    //remove element
    for (Iterator<Colors> iterator = beans.getColors().iterator(); iterator.hasNext();) {
        Colors color = iterator.next();

        if …
Run Code Online (Sandbox Code Playgroud)

java spring-data-jpa

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

必须使用mockbean而不是autowired

我用的是春靴2

我创建了一个基本测试

@RunWith(SpringJUnit4ClassRunner.class)
public class VehicleServiceImplTest {

    private VehiculeServiceImpl service;

    @Autowired
    private VehicleRepository repository;

    @Before
    public void prepare() {
        service = new VehiculeServiceImpl(repository);
    }

    @Test
    public void test(){

    }

}
Run Code Online (Sandbox Code Playgroud)

我明白了

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'com.namur.service.VehicleServiceImplTest'的bean时出错:通过字段'repository'表示的不满意的依赖关系; 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有'com.namur.repository.VehicleRepository'类型的限定bean可用:预期至少有1个bean可以作为autowire候选者.依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586)

如果我用MockBean替换Autowired它正在工作,但我不知道为什么

junit spring-boot

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