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

前端 未结 2 876
北海茫月
北海茫月 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!";
    }
    
    0 讨论(0)
  • 2021-01-24 01:49

    From frist look it seems that you have wrong type for that property in the database table.

    0 讨论(0)
提交回复
热议问题