我遇到了一个持久对象的小问题。以下是我的实体类看起来像的一个例子。如何仅保存在spring crudrepository中分配的属性?
@Entity
public class Example(){
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private int number;
private String sentence;
/* No arg const, getters and setters omitted */
CrudRepository接口:
@Repository
public interface ExampleRepository extends CrudRepository<Example, Integer>
{}
服务实现接口:
@Service
public class ExampleService{
@Autowired
public ExampleRepository exampleRepository;
public void save(Example example){
exampleRespository.save(example)
}
}
内CommandLineRunner的:
Example example1 = new Example();
example1.sentence("Hello World!");
exampleService.save(example1);
现在我遇到问题是即使我没有给属性号赋值,它仍然会持续为0.如何阻止该属性被赋值为0并使其为空?
谢谢你的提示。我会记住这一点。 – Saurin