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

不想你离开。 提交于 2019-12-02 07:18:50

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!";
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!