Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33093

Auto relacionamento com ManyToMany

$
0
0

@rafaelvicio escreveu:

Pessoal, estou com um problema pra fazer o Auto-relacionamento em uma ManyToMany.
Minhas entidades estão da seguinte forma:

Noticia:

@ManyToMany
@JoinTable(name = "not_tag", joinColumns = @JoinColumn(name = "not_id"), inverseJoinColumns = @JoinColumn(name = "tag_id"))
private List tags;

Tag:

@ManyToMany(mappedBy="tags")
private List noticias;

JSP:


${tag.nome}

Controller:

@RequestMapping(value = "/cadastro", method = RequestMethod.POST)
private String adicionar(@ModelAttribute("noticia") @Valid Noticia novaNoticia, BindingResult result, Model model, MultipartFile imagem){
if (result.hasErrors()) {
return "noticia.cadastro.tiles";
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String nomeUsuario = auth.getName();
Usuario usuario = repositorioUsuario.findByUsername(nomeUsuario);

    Date data = new Date();

    novaNoticia.setData(data);
    novaNoticia.setUsuario(usuario);

    repositorioNoticia.save(novaNoticia);


    return "redirect:/noticias/";

Como eu vou passar a lista de Tags escolhidas na tela para a noticia?

Mensagens: 1

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 33093


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>