社内環境用ページを作る

弊社で開発しているシステムには、
「履歴を開く」メニューをクリックすると別タブでページが開く機能があり、お客さんの環境では送ったパラメータを元に該当のデータを表示することができている。
 
社内の検証環境では404が出てしまうので改善をおおせつかった。
メニューをクリックした時にURLで送っているパラメータを表示できるようにすることが要件。
 
バックエンドがJava8なので順当に行けばcontroller→thymeleafなんだろうけど
コンテキストメニューのリンクが
'PM/Gate'
でバックエンドのコンテキストパスが
'PM/IM'
なのでどうするか。
 
少し考えて
デプロイサーバに
'PM/Gate'
ディレクトリを作成しそこにindex.htmlファイルを置いた。
index.htmlからパラメータを引き継いでリダイレクトして
controller→thymeleafと遷移するようにした
 
index.html
javascriptでパラメータを取得し、リダイレクト先の末尾にくっつけている

<!DOCTYPE html><html><head>
      <meta charset="utf-8" />
<title></title>
<script type="text/javascript">
             var paramstr = document.location.search;

             ドキュメント.ロケーション.エイチレフ = "http://%E3%83%9B%E3%82%B9%E3%83%88%E5%90%8D/PM/IM/context"+paramstr;
 
         </script>
    </head><body><p>転送ページです。
       </p></body>

index.htmlからリダイレクトされるcontroller
URLの値を取得し、thymeleafで表示できるようmodelに詰める

@GetMapping("/context")
     
public String showContext

      (@RequestParam("a") String a,

       @RequestParam("b") String b,

       @RequestParam("c") String c,

       @RequestParam(name = "d", required = false, defaultValue = "任意の値") String d,

       @RequestParam(name="e", required = false, defaultValue = "任意の値") String e,

       @RequestParam(name="f", required = false, defaultValue = "任意の値") String f,

       @RequestParam(name="g", required = false, defaultValue = "任意の値") String g,

       @RequestParam(name="h", required = false, defaultValue = "任意の値") String h,
Model model) {

                  model.addAttribute("a", a);

                  model.addAttribute("b", b);

                  model.addAttribute("c", c);

                  model.addAttribute("d", d);

                  model.addAttribute("e", e);

                  model.addAttribute("f", f);

                  model.addAttribute("g", g);
                  
model.addAttribute("h", h);

                  return "context";


      }

 
URLのパラメータを表示するcontext.html

<!DOCTYPE HTML><html xmlns:th="http://www.thymeleaf.org"><head>
              <title>ステージング環境コンテキストメニュー</title>
              <meta charset="UTF-8"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
       </head><body><h2>ステージング環境用コンテキストメニュー</h2>
                      <h4>受け取ったパラメータ</h4><table><thead><tr><th>パラメータa</th><th>パラメータb</th>
                                           <th>パラメータc</th><th>パラメータd</th><th>パラメータe</th></tr></thead><tbody>
                                      <tr><td th:text="${a}"></td><td th:text="${b}"></td><td th:text="${c}"></td>
                                          <td th:text="${d}"></td><td th:text="${e}"></td></tr></tbody></table>
               </body></html>

チームメンバーになるほどと言わせたぞ!
いつも私が教わるばかりなので結構嬉しかった