Я пишу некоторый код. Я хочу сделать поле questionId в BaseQuestion
Класс как Autogenerated.Any решение для этого? Я не использую jpa jar.so, я не могу использовать аннотацию @Generatedvalue
. Так как мы показываем здесь, это поле генерируется автоматически.
код ниже.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>audit_project</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
BaseQuestion.java
package model;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "basequestion")
public class BaseQuestion {
@ID
private String id;
private int questionId;
private String responseType;
private boolean required;
private boolean active;
private String questionCode;
private QuestionText questionText;
private String category;
private List<Responses> responses;
public QuestionText getQuestionText() {
return questionText;
}
public void setQuestionText(QuestionText questionText) {
this.questionText = questionText;
}
public List<Responses> getResponses() {
return responses;
}
public void setResponses(List<Responses> responses) {
this.responses = responses;
}
public int getQuestionId() {
return questionId;
}
public void setQuestionId(int questionId) {
this.questionId = questionId;
}
public String getResponseType() {
return responseType;
}
public void setResponseType(String responseType) {
this.responseType = responseType;
}
public boolean getRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
public String getQuestionCode() {
return questionCode;
}
public void setQuestionCode(String questionCode) {
this.questionCode = questionCode;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
AuditProjectRepository.java
package repository;
import org.springframework.data.mongodb.repository.MongoRepository;
import model.BaseQuestion;
public interface AuditProjectRepository extends MongoRepository<BaseQuestion, String> {
public BaseQuestion findByQuestionId(int questionId);
public BaseQuestion findByQuestionCode(String questionCode);
public Long deleteByQuestionId(int questionid);
}