Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Send object from Java backend to JavaScript frontend via model

I am trying to pass some objects from Java backend to the JavaScript frontend as following:

WeightController:

String jsonString = new JSONObject()
   .put("weightEntry", weightEntry).toString();

model.addAttribute("weightEntry", jsonString);

using the following library to create a json:

<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20220320</version>
</dependency> 
@Entity
@Table(name = "WeightEntry")
public class WeightEntry {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne()
    private User user;

    @OneToMany(mappedBy = "weightEntry")
    private Set<Image> imageSet = new HashSet<>();

    private double weight;
    private Date date;

    public WeightEntry() {}
}
<script>
    var obj = eval('('+'${weightEntry}'+')'); //this is not working
    var obj2 = [[${weightEntry}]] //this shows blank??
</script>

I found this on stackoverflow which is outdated (it seems) How to access model attribute in Javascript

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda