我正在使用RestController、Service和一个实体开发spring引导应用程序。
我的问题是,当我调用web服务将我的数据保存在数据库中时,它似乎工作正常,也没有抛出异常,但是当我检查我的数据库时,我发现创建了该表,但我发现没有保存任何数据。下面是输出中的内容(对于列表中的每个元素):
Hibernate:插入到table_name (columnOne,columnTwo)值(?,?)
这是我的代码:
RestController
@RestController
@RequestMapping(path = "/api/")
public class myController {
@Autowired
private MyService myService;
@PostMapping(path="/inject/{year}")
public void myControllerMethod(@PathParam("year") Year year) {
this.myService.myServiceMethod(year);
}
}服务
@Service
public class MyService {
@Autowired
MyRepository myRepository;
public void myServiceMethod(Year year) {
List<MyEntity> myEntityList = this.parseMyEntityList(year);
this.myRepository.save(myEntityList)
}
}存储库
@Repository
public interface MyRepository extends CrudRepository<MyEntity, Long>, JpaSpecificationExecutor<InseeLibelle> {
}实体
@Entity
@Table(name = "table_name", indexes = {
@Index(name = "columnOne_idx", columnList = "columnOne"),
@Index(name = "columneTwo_idx", columnList = "columnTwo"),
})
public class MyEntity{
@JsonIgnore
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long columnId;
@Column
private Integer columnOne;
@Column
private String columnTwo;
public Integer getColumnOne() {
return columnOne;
}
public void setColumnOne(Integer columnOne) {
this.columneOne = colmunOne;
}
public String getColumnTwo() {
return columnTwo;
}
public void setColumnTwo(String columnTwo) {
this.columnTwo = columnTwo;
}
}我试图在存储库中添加这一行,但它也不起作用:
<S extends MyEntity> Iterable<S> save(Iterable<S> entities) ;发布于 2018-04-30 15:43:10
也许问题在于pgAdmin (就像我的例子),它没有显示数据,但是它们存在于数据库中,尝试存储库中的findAll方法,或者使用select *直接检查它们。
https://stackoverflow.com/questions/49151336
复制相似问题