spring-data-rest

How to add a specific field in Spring Data Rest?

て烟熏妆下的殇ゞ 提交于 2019-12-02 20:04:11
问题 I am developing a web service using Spring Data Rest. public interface BookRepository extends PagingAndSortingRepository<Book, Long> { @Override @Query("select avg(rl.rating) as rating, b from ReadingList rl join rl.book b group by rl.book order by rating desc") Page<Book> findAll(Pageable pageable); } When I select in JPQL as above, 'avg (rl.rating) as rating' column does not have the name like the image below. enter image description here rating: 4.0 I would like to do this service. In

How to map Page<ObjectEntity> to Page<ObjectDTO> in spring-data-rest

ⅰ亾dé卋堺 提交于 2019-12-02 17:27:51
When I hit the database with PagingAndSortingRepository.findAll(Pageable) I get Page<ObjectEntity> . However, I want to expose DTO's to the client and not entities. I can create DTO just by injecting entity into it's constructor, but how do I map the entities in Page object to DTO's? According to spring documentation, Page provides read-only operations. Also, Page.map is not possibility, as we don't have support for java 8. How to create the new Page with mapped objects manually? You can still use the Page.map without lambda expressions: Page<ObjectEntity> entities = objectEntityRepository

Spring data rest managing all entities with one crud repository

本秂侑毒 提交于 2019-12-02 15:18:05
问题 I need to know is there any possibility to manage several entities with one crud repository in spring data rest. Example : Library entity @Entity public class Library { @Id @GeneratedValue private long id; @Column private String name; @OneToMany(mappedBy = "library") private List<Book> books; } Book entity @Entity public class Book { @Id @GeneratedValue private long id; @Column(nullable=false) private String title; @ManyToOne @JoinColumn(name="library_id") private Library library; } My

Spring Boot with session-based data source

别来无恙 提交于 2019-12-02 12:10:19
问题 I've been tearing my hair out with what should be a pretty common use case for a web application. I have a Spring-Boot application which uses REST Repositories, JPA, etc. The problem is that I have two data sources: Embedded H2 data source containing user authentication information MySQL data source for actual data which is specific to the authenticated user Because the second data source is specific to the authenticated user, I'm attempting to use AbstractRoutingDataSource to route to the

How to add a specific field in Spring Data Rest?

对着背影说爱祢 提交于 2019-12-02 11:57:24
I am developing a web service using Spring Data Rest. public interface BookRepository extends PagingAndSortingRepository<Book, Long> { @Override @Query("select avg(rl.rating) as rating, b from ReadingList rl join rl.book b group by rl.book order by rating desc") Page<Book> findAll(Pageable pageable); } When I select in JPQL as above, 'avg (rl.rating) as rating' column does not have the name like the image below. enter image description here rating: 4.0 I would like to do this service. In addition, the full source is in github. https://github.com/ohgamja3/readinglist-rest-server/ I would like

Pagination in Spring Data Rest for nested resources

筅森魡賤 提交于 2019-12-02 11:44:21
问题 When the below URL is visited, I get paginations in response /api/userPosts/ { "_links" : { "self" : { "href" : "/api/userPosts{?page,size,sort}", "templated" : true }, "next" : { "href" : api/userPosts?page=1&size=20{&sort}", "templated" : true } }, "_embedded" : { "userPosts" : [ { ... However when visiting following URL, there is no pagination out of box by Spring Data REST - /api/users/4/userPosts { "_embedded" : { "userPosts" : [ { Both UserRepository and UserPostRepository are

How to loop and retrieve value from HATEOAS _link attribute (e.g. retrieve a description)?

瘦欲@ 提交于 2019-12-02 11:19:33
tl;dr My code gets an array of javascript/json objects from a Restful GET. How do I write code to loop and retrieve, for display, a description (or any value) from a HATEOAS "_link" attribute? Context I've inherited a small Spring-based project --it tracks servers, software installations, etc for our team's internal use. It uses Angular front end and Spring/java/mysql back end for a restful back end. I'm in the process of converting the hand-coded SQL to JPA and 'spring starter data rest' Current API Does The current handcoded SQL joins tables to give "display friendly results". Product ------

Spring Data REST not including entity links in resource

只谈情不闲聊 提交于 2019-12-02 07:09:22
问题 Resolved By Oliver Gierke's Solution Looks like this was a known bug in Spring 4.2.0, upgrading to 4.2.1 has provided the expected functionality Original Question I'm working on moving my dev team over to Spring + WebMVC + Data-REST + Data-JPA + Spring HATEOAS for web applications. My current app is just going to maintain a list of our ongoing applications. I'm running into an issue with my default Spring Data REST setup. My resources aren't including their linked resource in their specific

Pagination in Spring Data Rest for nested resources

南楼画角 提交于 2019-12-02 04:56:23
When the below URL is visited, I get paginations in response /api/userPosts/ { "_links" : { "self" : { "href" : "/api/userPosts{?page,size,sort}", "templated" : true }, "next" : { "href" : api/userPosts?page=1&size=20{&sort}", "templated" : true } }, "_embedded" : { "userPosts" : [ { ... However when visiting following URL, there is no pagination out of box by Spring Data REST - /api/users/4/userPosts { "_embedded" : { "userPosts" : [ { Both UserRepository and UserPostRepository are JPARepository with pagination. As a result, the second URL is throwing GC overhead exceeded error since the row

Spring Boot Data Rest + CORS not being enabled properly for OPTIONS/DELETE

自闭症网瘾萝莉.ら 提交于 2019-12-02 04:54:10
问题 I've got an extremely simple example that I can't get to work. I have my domain that models my database, and my Repository. public interface MyTestRepository extends CrudRepository<MyTest, Integer> { } I used http://resttesttest.com/ to test it. For GET Method's it returns me the JSON REST information without any issue. I can query the endpoint http://localhost:8080/mytest/1 and I get back the information for id=1 from the database. However, the problem comes in when I try to use the DELETE