java - How to findAll entires(posts) which contain at least one specified tag. Spring Data -


i`m trying retrieve entries(posts) possess specific tag. 1 entry can have many tags, use list of objects. don't know how construct proper command in controller class, i'm afraid i’m lost here.

entry entity looks this:

@entity public class blogentry {  @id @generatedvalue private integer id;  private string title;  @column(name = "published_date") private date publisheddate;  @manytomany @jointable private list<tagblog> blogtags; /* multiple tags 1 entry */ 

and tag entity:

@entity public class tagblog {  @id @generatedvalue private integer id;  private string tag;  @manytomany(mappedby="blogtags") private list<blogentry> entries; 

in entryservice class wanted perform kind of sort "findbytagblogin" wish return list of posts possess specific tag.

public list<blogentry> findallbytags(list<tagblog> tag){                                  list<blogentry> blogentry = entryrepository.findbytagblogin(tag);      return blogentry; } 

but don't know how refer in controller class. how can retrieve entries specific tag? this? how pass list of tags parameter, maybe should string?

@requestmapping(value="/welcome") public string retrievetaggedentry(model model, ?list of tags?){  model.addattribute("entrieswithtag", entryservice.findallbytags(tagblog tag));      return "redirect:/welcome.html";  } 

in welcome.jsp file iterate throught whole list of tags had been assigned specific entry(post) in example below (between arrows "---> <---" part of conserns):

<c:foreach items="${entries}" var="entry"> <!--"entries" refers list of blogentry--> <table>             <tr>                     <td>entry no. ${entry.id }</td>                     <td>${entry.title}</td>                     <td>                     tags: ---> #${entry.? blogtag.tag ?}, <---                      </td>                     <td>published: ${entry.publisheddate}</td>                     <td>                         <spring:url value="/delete_entry/${entry.id}.html" var="url" />                         <a href="${url}">delete</a>                     </td>             </tr>         </table> </c:foreach> 

by working out later, want perform sort (by mapping spring:url value="/tag/${some_tag_as_a_string}.html") entries possess specific tag.

maybe there easier way return posts specific tag? guess easier me work got here. anyway, solution provided appreciated.

i'm willing add additional information if needed.

is there reason want send whole tagblog object controller? why not tag id or tag text? e.g.

@requestmapping(value="/welcome") public string retrievetaggedentry(model model, @requestparam list<string> tags) {     // tags } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -