當前位置:編程學習大全網 - 網站源碼 - SpringMVC如何返回字符串到前端用js獲取

SpringMVC如何返回字符串到前端用js獲取

方法壹:

方法返回值為字符串類型,可以在Controller需要使用的方法中添加HttpServletRequest ?request參數,然後在方法體中添加request.setAttribute("string", "前端需要的字符串");

return "/areas/mgt/views/process/modelList"; ?在modelList.html頁面中使用${string}即可獲取"前端需要的字符串"這個字符串

方法二:

方法返回值為ModelAndView類型,可以在Controller需要使用的方法內

[html]?view plain?copy

Map<String,String>?map=new?HashMap<String,String>();?

map.put("activityId",?activityId);?

return?new?ModelAndView("/areas/mgt/views/form/elecfg/actioncfg",map);?

[html]?view plain?copy

actioncfg<span?style="font-family:?Arial,?Helvetica,?sans-serif;?background-color:?rgb(255,?255,?255);">.html頁面中使用${</span><span?style="font-family:?Arial,?Helvetica,?sans-serif;">activityId</span><span?style="background-color:?rgb(255,?255,?255);?font-family:?Arial,?Helvetica,?sans-serif;">}即可獲取"</span><span?style="font-family:?Arial,?Helvetica,?sans-serif;">?activityId</span><span?style="background-color:?rgb(255,?255,?255);?font-family:?Arial,?Helvetica,?sans-serif;">"這個值</span>?

  • 上一篇:windows環境svnversion命令未找到
  • 下一篇:找壹個10年前的三國網頁遊戲?
  • copyright 2024編程學習大全網