Java spring mvc: IllegalStateException: Cannot convert value of type [java.lang.String] to required type

前端 未结 2 877
北海茫月
北海茫月 2021-01-24 00:48

As the title says i\'m having an annoying IllegalStateException in my spring web app. I\'ve been through numerous topics here on SO and other forums, without any luck.

T

2条回答
  •  有刺的猬
    2021-01-24 01:33

    Remove the code to get the folder object in your controller and pass the folderName String parameter. In your Note Service implementation class use the folderService to do the job.

    Use the @Trasactional annotation when you merge your data to the table for managing transaction,

    Here's the code

    @Transactional
    public String insertNote(Note note, String folderName) {
      try{
        EntityManager em = emf.createEntityManager();
        Folder folder = folderService.getFolderByName(folderName);
        note.setFolder(folder);
        em.flush();
        em.merge(note);
      }catch(Exception e){
          e.printStackTrace();
      }
    return "Success!";
    }
    

提交回复
热议问题