我想学习Annotation,并创建一个演示项目.但是当我创建一个扩展AbstractProcessor的类时,Android Studio找不到这个类.我该如何添加它.
所以,我有使用@Builder lombok注释的类.这是它的外观和我如何使用它:
import lombok.Builder;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonProperty;
@Data
@Builder
public class MyModel {
@JsonProperty(value = "myField1")
private String myField1;
@JsonProperty(value = "myField2")
private String myField2;
@JsonProperty(value = "myField3")
private String myField3;
}
//This is how I use it:
MyModel model = MyModel.builder()
.myField1("value for field 1")
.myField2("value for field 2")
.build();
Run Code Online (Sandbox Code Playgroud)
我的问题是,在这个类中添加一些额外的方法是否是一个好习惯?或者我应该保持原样并在外面做任何业务逻辑?
基本上,让我们说,我需要一个帮助方法来设置myField3属性,因为我不能只做:
.myField3("value for field 3")
.build()Run Code Online (Sandbox Code Playgroud)
我需要对field3执行一些值的操作,之后将其设置为MyModel.
那么我可以将这个辅助方法放到这个类中吗?
我下载了以下项目并将其导入到Visual Studio Code:
https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example
调用以下课程时,我在以下课程上遇到了问题:car.getName()。
内容是:
CoolCarController.java
package com.okta.developer.demo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.stream.Collectors;
@RestController
class CoolCarController {
private CarRepository repository;
public CoolCarController(CarRepository repository) {
this.repository = repository;
}
@GetMapping("/cool-cars")
@CrossOrigin(origins = "http://localhost:4200")
public Collection<Car> coolCars() {
return repository.findAll().stream()
.filter(this::isCool)
.collect(Collectors.toList());
}
private boolean isCool(Car car) {
return !car.getName().equals("AMC Gremlin") &&
!car.getName().equals("Triumph Stag") &&
!car.getName().equals("Ford Pinto") &&
!car.getName().equals("Yugo GV");
}
}
Run Code Online (Sandbox Code Playgroud)
这也是以下内容:
汽车.java
package com.okta.developer.demo;
import lombok.*;
import javax.persistence.Id;
import …Run Code Online (Sandbox Code Playgroud) 在最近的 JetBrains Intellij IDEA 更新之后,我发现当我尝试实现用 javax.annotation.Nonnull 注释的方法时 - IDE 用 org.jetbrains.annotations.NotNull 来实现它。
例子:
如果你有一个接口:
import javax.annotation.Nonnull;
interface User {
@Nonnull
String getName();
}
Run Code Online (Sandbox Code Playgroud)
它将被实施为:
import org.jetbrains.annotations.NotNull;
class Customer implements User {
@NotNull
@Override
public String getName() {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是如何配置IDE来实现带有严格验证注解的方法?
我正在使用 java 1.8、Spring Boot 和 MongoDb 在数据库中存储一些数据以了解 mongoDb
我想通过注释来限制类字段的字符,我试图用 hibernate-validator 来控制它:
import javax.validation.constraints.Size;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
@Document(collection = "MusicGroup")
public class MusicGroup {
@Id
private String id;
@Size(min = 7, max = 7, message = "title need to have only 4 characters")
@Field("Title")
private String title;
@Size(min = 11, max = 11, message = "type need to have only 11 characters")
@Field("Type")
private String type;
@Field("Members")
private List<String> members;
public MusicGroup(String titulo, String tipo, List<String> integrantes) { …Run Code Online (Sandbox Code Playgroud) Gradle 是否具有与为 JOOQ 类型检查器注释处理器 ( https://www.jooq.org/doc/latest/manual/tools/checker-framework/ )描述的 Maven 配置等效的配置?Maven 版本是:
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-checker</artifactId>
<version>3.10.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
和
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<annotationProcessors>
<annotationProcessor>org.jooq.checker.SQLDialectChecker</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<arg>-Xbootclasspath/p:1.8</arg>
</compilerArgs>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,虽然我可以将编译依赖项添加到 Gradle 中,但我不确定该放在哪里annotationProcessor。任何帮助将不胜感激!
如何消除此示例代码中的警告。
我将 Eclipse Neon 与 Java 1.8 和 org.eclipse.jdt.annotation_2.1.0 结合使用
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@NonNullByDefault
public class NullAnnotationTest4 {
public static void main(String[] args) {
final TreeMap<@Nullable Integer, @Nullable String> treeMap = new TreeMap<>();
treeMap.put(3, "Test1");
treeMap.put(null, null);
//This produces the warning
final Set<@Nullable Entry<@Nullable Integer, @Nullable String>> set = treeMap.entrySet();
for (final Iterator<@Nullable Entry<@Nullable Integer, @Nullable String>> it = set.iterator(); it.hasNext(); ) {
final Entry<@Nullable Integer, @Nullable String> entry = it.next(); …Run Code Online (Sandbox Code Playgroud) 我有以下注释:
@Repeatable(Infos.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.Type, ElementType.Constructor})
public @interface Info {
String[] value() default {};
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它是可重复的,并且使用的是包装器类Infos;
@Retention(RetentionPolicy.RUNTIME)
public @interface Infos {
Info[] value();
}
Run Code Online (Sandbox Code Playgroud)
但是我在Info类上遇到以下编译器错误;
容器注释的目标不是此注释的目标的子集
此错误的原因和解决方法是什么?
我在GATE中的句子拆分器模块有问题。我的文字是这样的:
Social history. He drank a lot in his young age. He did
not attend a school. He was depressed of his condition.
Run Code Online (Sandbox Code Playgroud)
虽然我们确定句子应该像
Sentence 1: Social history.
Sentence 2: He drank a lot in his young age.
Sentence 3: He did not attend a school.
Sentence 4: He was depressed of his condition.
Run Code Online (Sandbox Code Playgroud)
ANNIE句子拆分器认识到,不同行中的文本应分组在不同的句子中,因此得出以下结果:
Sentence 1: Social history.
Sentence 2: He drank a lot in his young age.
Sentence 3: He did
Sentence 4: not attend a school.
Sentence …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Gatling 重用我现有的集成测试黄瓜小黄瓜场景进行性能测试。集成测试是用 restassured.io 和 Cucumber JVM 编写的。我想要做的是向现有的集成测试添加一个新标签,比如@Performance_REQ_noOfRequest_RESP_responseTime。
所以我想知道有没有办法以编程方式读取黄瓜标签,以便我可以提取请求和响应值并将其发送到 Gatling 测试。
示例 Gherkin is Feature:获取员工信息的端点
@Regression @Performance_Req_1000_Resp_100s
场景:获取员工
当我向 /api/employees 发送请求
然后我应该看到员工列表
java-annotations ×10
java ×6
annotations ×2
lombok ×2
android ×1
builder ×1
cucumber ×1
cucumber-jvm ×1
eclipse ×1
gate ×1
gradle ×1
jooq ×1
nlp ×1
non-nullable ×1
spring-boot ×1
spring-mvc ×1
sql ×1