カナダのIT系企業でのCo-op体験談 第16週目 既存プロジェクトの見直し


本来なら今週で終わりだけど、希望者は来週(授業開始前)まで働けるということなので、延長しました。
現在の滞在先では4月末までしか住めないので、Airbnbを使って短期滞在できる場所を予約して、5月からはそこから通勤するつもりです。

今週は、コープ中にほぼ自力で仕上げたプロジェクトの見直しをしてました。クライアントからいくつか問い合わせがあり、一部の処理がうまく行われていないとのことでしたので、処理を見直し、また今後のことを考えてリファクタリングしました。

Thymeleafでデータを表示していたのですが、データ量が膨大な場合、ページネーションを活用するとローディング時間の短縮に成功できたので勉強になりました。

Thymeleafでmapを扱う時に参考になったコードがあるので以下に記載しておきます。
http://forum.thymeleaf.org/How-to-use-Map-lt-String-String-gt-with-Spring-and-Thymeleaf-forms-td4028666.html
= Validation Class = 

package limelight.model.validation; 

import java.util.Map; 

public class TestMapForm { 

        private Map<String,String> properties; 

        public Map<String,String> getProperties() { 
                return properties; 
        } 

        public void setProperties(Map<String,String> properties) { 
                this.properties = properties; 
        } 

        


= Thymeleaf Form = 

<form action="#" th:action="@{/processTestMapForm}" th:object="${testMapForm}" method="post">
            <div th:each="entry : ${txtProps}">
                <label th:for="${entry.key}" th:text="${entry.key}">example</label>
                <input th:id="${entry.key}" th:field="*{properties[__${entry.key}__]}" th:value="${entry.value}" />  
            </div><br />
            <input type="hidden" name="category" value="Alle" />
            <input type="submit" value="Speichern" class="button-primary float-none" />
      </form>

= Controller = 

@RequestMapping(value = "/testMap", method=RequestMethod.GET) 
        public String showMapForm(ModelMap modelMap) { 
                
                HashMap<String,String> txtProps = new HashMap<String,String>(); 
                txtProps.put("Property 1", ""); 
                txtProps.put("Property 2", ""); 
                txtProps.put("Property 3", ""); 
            
                modelMap.addAttribute("txtProps", txtProps); 

                TestMapForm testMapForm = new TestMapForm(); 
                HashMap<String,String> properties = new HashMap<String,String>(); 

                properties.putAll(txtProps); 
                testMapForm.setProperties(properties); 
                modelMap.addAttribute("testMapForm", testMapForm); 

                return "testMap"; 
        } 

        @RequestMapping(value = "/processTestMapForm", method=RequestMethod.POST) 
        public String processMapForm( 
                        @Valid @ModelAttribute(value="testMapForm") TestMapForm testMapForm, 
                        BindingResult result, 
                        ModelMap modelMap) { 

                if(result.hasErrors()) { 
                        HashMap<String,String> txtProps = new HashMap<String,String>(); 
                        txtProps.put("Property 1", ""); 
                        txtProps.put("Property 2", ""); 
                        txtProps.put("Property 3", ""); 
                        modelMap.addAttribute("txtProps", txtProps); 
                        return "redirect:/testMap/" + cat; 
                } 

            out.println(testMapForm.getProperties()); 
            
            
            return "redirect:/catalog"; 
        }

0 件のコメント :