0

次のように、SpringMVCコントローラーを使用してJavaScriptを生成します。

@RequestMapping(value="path/to/handler", method = RequestMethod.GET, produces ="text/javascript")
public ModelAndView getJs(HttpServletRequest request) {
  String contextPath = request.getContextPath();
  return new ModelAndView("/path/to/js/", "contextPath", contextPath);
}

ただし、javascriptリソースのビューリゾルバーを設定する方法がわかりません。誰かがjsリソースのビューリゾルバーを設定する方法をアドバイスできますか?

4

1 に答える 1

0

あなたはあなたのjsファイルをに置くことができます

src/main/webapp/resources/js/somefile.js

これをservlet-context.xmlに追加します

<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<resources location="/resources/favicon.ico" mapping="/favicon.ico"/>

これで、次の方法で.jsファイルにアクセスできます:localhost:8080 / yourapp / resources / js / somefile.js

于 2012-10-26T10:10:32.397 に答える