• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

 前回まででEntityの作成まで終わったので、Webアプリケーションとして動作させるためのメモです。

以前のエントリはこちら
Spring Roo Install
[Spring Roo]プロジェクト作成, Logging&DB接続設定
[Spring Roo]Entity作成

・roo shell上でwebコマンドを実行することで、Webアプリケーションとして動作するために必要なファイルが生成されます。

   1  roo> web mvc setup
   2  Created SRC_MAIN_WEBAPP\WEB-INF\spring
   3  Created SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
   4  Created SRC_MAIN_WEBAPP\WEB-INF\web.xml
   5  Updated SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
   6  Created SRC_MAIN_WEBAPP\images
   7  Created SRC_MAIN_WEBAPP\images\create.png
   8  Created SRC_MAIN_WEBAPP\images\list.png
   9  Created SRC_MAIN_WEBAPP\images\resultset_previous.png
  10  Created SRC_MAIN_WEBAPP\images\resultset_next.png
  11  Created SRC_MAIN_WEBAPP\images\show.png
  12  Created SRC_MAIN_WEBAPP\images\favicon.ico
  13  Created SRC_MAIN_WEBAPP\images\delete.png
  14  Created SRC_MAIN_WEBAPP\images\resultset_first.png
  15  Created SRC_MAIN_WEBAPP\images\springsource-logo.png
  16  Created SRC_MAIN_WEBAPP\images\resultset_last.png
  17  Created SRC_MAIN_WEBAPP\images\add.png
  18  Created SRC_MAIN_WEBAPP\images\banner-graphic.png
  19  Created SRC_MAIN_WEBAPP\images\update.png
  20  Created SRC_MAIN_WEBAPP\styles
  21  Created SRC_MAIN_WEBAPP\styles\alt.css
  22  Created SRC_MAIN_WEBAPP\styles\standard.css
  23  Created SRC_MAIN_WEBAPP\WEB-INF\classes
  24  Created SRC_MAIN_WEBAPP\WEB-INF\classes\standard.properties
  25  Created SRC_MAIN_WEBAPP\WEB-INF\classes\alt.properties
  26  Created SRC_MAIN_WEBAPP\WEB-INF\layouts
  27  Created SRC_MAIN_WEBAPP\WEB-INF\layouts\default.jspx
  28  Created SRC_MAIN_WEBAPP\WEB-INF\layouts\layouts.xml
  29  Created SRC_MAIN_WEBAPP\WEB-INF\views
  30  Created SRC_MAIN_WEBAPP\WEB-INF\views\header.jspx
  31  Created SRC_MAIN_WEBAPP\WEB-INF\views\footer.jspx
  32  Created SRC_MAIN_WEBAPP\WEB-INF\views\views.xml
  33  Created SRC_MAIN_WEBAPP\WEB-INF\views\index.jspx
  34  Created SRC_MAIN_WEBAPP\WEB-INF\views\index-template.jspx
  35  Created SRC_MAIN_WEBAPP\WEB-INF\views\uncaughtException.jspx
  36  Created SRC_MAIN_WEBAPP\WEB-INF\views\resourceNotFound.jspx
  37  Created SRC_MAIN_WEBAPP\WEB-INF\views\dataAccessFailure.jspx
  38  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form
  39  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\update.tagx
  40  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\create.tagx
  41  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\dependency.tagx
  42  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\show.tagx
  43  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\list.tagx
  44  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\find.tagx
  45  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields
  46  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\select.tagx
  47  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\display.tagx
  48  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\column.tagx
  49  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\editor.tagx
  50  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\checkbox.tagx
  51  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\simple.tagx
  52  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\input.tagx
  53  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\textarea.tagx
  54  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\datetime.tagx
  55  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\table.tagx
  56  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\reference.tagx
  57  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu
  58  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util
  59  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\pagination.tagx
  60  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\theme.tagx
  61  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\placeholder.tagx
  62  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\panel.tagx
  63  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\language.tagx
  64  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\load-scripts.tagx
  65  Created SRC_MAIN_WEBAPP\WEB-INF\i18n
  66  Created SRC_MAIN_WEBAPP\WEB-INF\i18n\messages.properties
  67  Created SRC_MAIN_WEBAPP\images\en.png
  68  Updated SRC_MAIN_WEBAPP\WEB-INF\i18n\application.properties
  69  Updated SRC_MAIN_WEBAPP\WEB-INF\web.xml
  70  Updated ROOT\pom.xml [added dependencies org.springframework:spring-web:${spring.version}, org.springframework:spring-we
  71  bmvc:${spring.version}, org.springframework.webflow:spring-js-resources:2.2.1.RELEASE, commons-digester:commons-digester
  72  :2.0, commons-fileupload:commons-fileupload:1.2.1, javax.servlet.jsp.jstl:jstl-api:1.2, org.glassfish.web:jstl-impl:1.2,
  73  javax.el:el-api:1.0, joda-time:joda-time:1.6, javax.servlet.jsp:jsp-api:2.1, commons-codec:commons-codec:1.4; updated p
  74  roject type to war; added dependencies org.apache.tiles:tiles-core:2.2.1, org.apache.tiles:tiles-jsp:2.2.1]
  75  Updated SRC_MAIN_WEBAPP\WEB-INF\views\footer.jspx

  • Webアプリケーションに必要なweb.xmlなどのファイルが生成されました。

  • また、Rooで作成されるのはSpringMVCアプリケーションですので、webmvc-config.xmlなどのSpringMVCのファイルも生成されます。

  • さらにデフォルトの画面を表示するためのファイルも生成されています。Rooで生成されるSpringMVCアプリケーションでは画面表示にtilesとjspxを使用しているため、デフォルト画面や共通のヘッダ、フッタ用のjspxファイルやtagxファイルが生成されました。CSSや画像ファイルも生成されます。

  • 次に各EntityのControllerを作成していきます。Project EntityのControllerを作成するには下記のようにcontroller scaffoldコマンドを実行します。

   1  roo> controller scaffold --class ~.web.ProjectController --entity ~.model.Project
   2  Created SRC_MAIN_JAVA\com\example\web
   3  Created SRC_MAIN_JAVA\com\example\web\ProjectController.java
   4  Updated SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
   5  Created SRC_MAIN_JAVA\com\example\web\ApplicationConversionServiceFactoryBean.java
   6  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects
   7  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\views.xml
   8  Updated SRC_MAIN_WEBAPP\WEB-INF\views\projects\views.xml
   9  Created SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
  10  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu\menu.tagx
  11  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu\item.tagx
  12  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu\category.tagx
  13  Updated SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
  14  Updated SRC_MAIN_WEBAPP\WEB-INF\views\projects\views.xml
  15  Updated SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
  16  Updated SRC_MAIN_WEBAPP\WEB-INF\i18n\application.properties
  17  Created SRC_MAIN_JAVA\com\example\web\ProjectController_Roo_Controller.aj
  18  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\list.jspx
  19  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\show.jspx
  20  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\create.jspx
  21  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\update.jspx
  22  Created SRC_MAIN_JAVA\com\exampler\web\ApplicationConversionServiceFactoryBean_Roo_ConversionService.aj

  • --classオプションでControllerクラス名を指定し、--entityオプションで対象になるEntityを指定します。上記の例ではProjectControllerという名前のControllerクラスが作成されました。また、Project Entityに対するCRUD画面表示用のjspxファイルや、tilesの設定ファイルも生成されています。

  • これだけでProject Entityに対する一覧表示、詳細表示、作成、更新、削除の画面・機能が一通り提供されてしまいます。

  • 同様に各Entityに対してControllerを生成します。

  • これでWebアプリケーションとして動作するようになりましたので、コマンドプロンプトからmvnコマンドを実行してアプリケーションを起動します。(roo shellではなくコマンドプロンプトです。)

   1  >mvn jetty:run

  • Webブラウザから下記のURLでアクセスすることが出来ます。

   1  http://localhost:8080/example

  • 画面左側のメニューから各Entityの操作が可能になっています。
posted by Png akanuma on Thu 1 Dec 2011 at 08:27
Contents
[Spring Roo]Webアプリケーションセットアップ
Comments
yoku0825: nkfの方が使いやすいですが、glibcに含まれているiconvの方が 確実にどの環境にも入っ... '12-6
Hiroaki Akanuma: ご指摘ありがとうございます。「嗜好度は大きい値がより嗜好度が強いことを意味すればどのような値で... '11-11
akr: 初めての推薦エンジンのところ 「属性データはどんなものでも可能。」 は preference ... '11-11
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ