我正在开发一个迁移软件,它将使用来自REST服务的未知数据.
我已经考虑过使用MongoDB,但我决定不使用它,而是使用PostgreSQL.
读完this后,我试图用Spring JPA在我的SpringBoot应用程序中实现它,但我不知道如何在实体中映射jsonb
.
试了this次,但什么都不懂!
我就在这里:
@Repository
@Transactional
public interface DnitRepository extends JpaRepository<Dnit, Long> {
@Query(value = "insert into dnit(id,data) VALUES (:id,:data)", nativeQuery = true)
void insertdata( @Param("id")Integer id,@Param("data") String data );
}
和
@RestController
public class TestController {
@Autowired
DnitRepository dnitRepository;
@RequestMapping(value = "/dnit", method = RequestMethod.GET)
public String testBig() {
dnitRepository.insertdata(2, someJsonDataAsString );
}
}
还有桌子:
CREATE TABLE public.dnit
(
id integer NOT NULL,
data jsonb,
CONSTRAINT dnit_pkey PRIMARY KEY (id)
)
我该怎么做?
Note: I don't want/need an Entity to work on. My JSON will always be String but I need jsonb to query the DB