@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Run Code Online (Sandbox Code Playgroud)
为什么我们使用这个注释?我需要知道这个自动增量我的表id值.(GenerationType.IDENTITY)当我们使用这个注释时,是否有其他类型的实际发生
public class Author extends Domain
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Column(name = "name")
private String name;
@Column(name = "address")
private String address;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "authorId")
private List<Book>
bookList;
public Author()
{
setServiceClassName("wawo.tutorial.service.admin.AuthorService");
}
}
Run Code Online (Sandbox Code Playgroud)
*是否有必要扩展Domain抽象类?有什么用?
Python装饰器是相同的还是相似的,或者与Java注释或Spring AOP或Aspect J等基本不同?
我试图了解这里的区别.我看到一个类已经使用相同的包示例注释了它们:
@Configuration
@EntityScan("some.known.persistence")
@ComponentScan({ "some.known.persistence"})
public class ApiConfig {
}
Run Code Online (Sandbox Code Playgroud)
我理解与API文档的不同之处,但希望详细了解.这也意味着扫描的任何东西@ComponentScan都具有更广泛的可见性和Spring背景,而@EntityScan不是.如果这样使用某些属性@ComponentScan应该已经足够需要在JPA上下文中绑定,不是吗?
我遇到了一个使用类定义注释的Room 教程@PrimaryKey:
@Entity(foreignKeys = @ForeignKey(entity = User.class,
parentColumns = "id",
childColumns = "userId",
onDelete = CASCADE))
public class Repo {
...
}
Run Code Online (Sandbox Code Playgroud)
现在,我有以下想要使用主键的数据类:
@Parcel(Parcel.Serialization.BEAN)
data class Foo @ParcelConstructor constructor(var stringOne: String,
var stringTwo: String,
var stringThree: String): BaseFoo() {
...
}
Run Code Online (Sandbox Code Playgroud)
所以,我刚刚@Entity(tableName = "Foo", foreignKeys = @ForeignKey(entity = Bar::class, parentColumns = "someCol", childColumns = "someOtherCol", onDelete = CASCADE))在顶部添加了片段,但我无法编译:
注释不能用作注释参数.
我想知道:为什么(我认为是)使用Java而不是在Kotlin中使用相同的概念?还有,有办法解决这个问题吗?
欢迎所有输入.
我最近升级到Android Studio 3.1,在使用Java项目构建我的Kotlin时,我收到了以下警告.
InnerClass注释缺少相应的EnclosingMember注释.这样的InnerClass注释被忽略.
消息{kind = WARNING,text = InnerClass注释缺少相应的EnclosingMember注释.这样的InnerClass注释被忽略.,sources = [Unknown source file]}
这是我的Gradle详细信息.
android {
compileSdkVersion 27
//buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
applicationId "org.myapp"
versionCode generateVersionCode()
//...
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Run Code Online (Sandbox Code Playgroud)
它并没有指出我的问题所在.如何找到有问题的代码?
在Java中读取自定义注释处理器的代码时,我注意到处理器process方法中的这段代码:
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!roundEnv.errorRaised() && !roundEnv.processingOver()) {
processRound(annotations, roundEnv);
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
碰巧我正在使用自定义Annotation处理器,我想在我的注释处理器中使用上面的代码片段.
我用这种方式尝试了上面的代码:
if (!roundEnv.errorRaised() && !roundEnv.processingOver()) {
processRound(annotations, roundEnv);
}
return false;
Run Code Online (Sandbox Code Playgroud)
& 这条路:
if (!roundEnv.errorRaised()) {
processRound(annotations, roundEnv);
}
return false;
Run Code Online (Sandbox Code Playgroud)
但我没有注意到处理器行为的任何变化.我得到了!roundEnv.errorRaised()支票,但我看不出有!roundEnv.processingOver()什么用处.
我想知道roundEnv.processingOver()在处理某一轮时使用它的用例.
我有一个方法params是一个大于50000项的列表; 限于业务逻辑,列表必须小于30000,所以我有一个方法在逻辑之前将这个数组拆分为2d数组
public static final <T> Collection<List<T>> partitionBasedOnSize(List<T> inputList, int size) {
AtomicInteger counter = new AtomicInteger(0);
return inputList.stream().collect(Collectors.groupingBy(s -> counter.getAndIncrement() / size)).values();
}
Run Code Online (Sandbox Code Playgroud)
这是我目前的解决方案:
public List<Account> getChildrenList(List<Long> ids) {
List<Account> childrenList = new ArrayList<>();
Collection<List<Long>> childrenId2dList = PartitionArray.partitionBasedOnSize(childrenIdsList, 30000);
for (List<Long> list : childrenId2dList) {
//this is my business logic: start
childrenList.addAll(accountRepository.getAccounts(list));
//this is my business logic: end
}
return childrenAccountsList;
}
Run Code Online (Sandbox Code Playgroud)
我想在方法的顶部创建一个注释,而不是许多重复的代码(每次检查和讨厌......)
考虑我的情况
public class SomeClass {
@Autowired @Qualifier("converter1") private IConverter converter1;
@Autowired @Qualifier("converter2") private IConverter converter2;
public void doSomeAction(String mimeType) {
converter1.execute();
converter2.execute();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码。
为了测试这个
@RunWith(MockitoJUnitRunner.class)
public class SomeClassTest {
@Mock(name="converter1") IConverter converter1;
@Mock(name="converter2") IConverter converter2;
@InjectMocks SomeClass class = new SomeClass();
@Test
public void testGetListOfExcelConverters() throws Exception {
class.doSomeAction("abcd");
}
}
Run Code Online (Sandbox Code Playgroud)
这里没有注入模拟,请帮助使用适当的机制来模拟合格的 bean。
如果这不是使用 spring 编码的正确方法,请告诉我使用它的正确方法。
在javax.annotation.processing包装中,有一个接口Processor,其中有一个功能:
/**
* Processes a set of annotation types on type elements
* originating from the prior round and returns whether or not
* these annotation types are claimed by this processor. If {@code
* true} is returned, the annotation types are claimed and subsequent
* processors will not be asked to process them; if {@code false}
* is returned, the annotation types are unclaimed and subsequent
* processors may be asked to process them. A …Run Code Online (Sandbox Code Playgroud) 在介绍 JPMS 服务时,Java 语言规范的 7.7.4 节指出“服务类型必须是类类型、接口类型或注释类型”。
我正在努力理解允许注释的意义。我的理解是服务的 JPMS 概念是我们期望在运行时选择实现的东西。看起来,为了有用,实现至少需要有可能是不同于标识所请求服务的原始类的东西。但我相信注释不能使用“扩展”,所以这永远不会发生?从那以后,我相信如果我尝试使用注释类型创建服务,我将不可避免地遇到这样一种情况,即服务查找可能返回的唯一内容,例如 SomeAnnotation。类将完全是 SomeAnnotation。这似乎毫无意义,所以我必须假设我错过了一些东西。
任何人都可以阐明这一点,也许可以提供注释如何成为“服务”的示例?
java-annotations ×10
java ×7
android ×2
spring-boot ×2
android-room ×1
hibernate ×1
java-8 ×1
java-9 ×1
java-module ×1
kotlin ×1
mockito ×1
python ×1
spring ×1
spring-4 ×1
sql ×1