Question: Please help to fix below coding of 1-30. package comps368.tma02; import comps368.tma02.model.Items; import java.util.List; import org.springframework.ui.ModelMap; //1. Add annotation for Controller @RequestMapping(value={,/items})/* Controller Context Mapping

Please help to fix below coding of 1-30.

package comps368.tma02;

import comps368.tma02.model.Items; import java.util.List; import org.springframework.ui.ModelMap;

//1. Add annotation for Controller @RequestMapping(value={"","/items"})/* Controller Context Mapping */ public class ItemController { //2. Annotation for injecting Resource (u5p97) private /* 3. Type of the JPA Repository of entity items */ itemRepo; //4. Annotation for injecting spring bean (u5p97) private ItemValidator validator; /* 5. Annotation for Context Mapping of this action. This action is to handle HTTP GET. Moroever, it should have mulitple mapping : "index" and empty */ public String index(ModelMap m){ List items = /* 6. Retrieve all the Items records from ItemRepository, and assign to a List of Items (u5p90) */; /* 7. Put the List of items into Model Map, with the name "items" (u5p90)*/ ("items", items); return "items/index"; } /* 8. Annotation for Context Mapping of this action. This action is to handle HTTP GET. The context path value should be "index/{keyword}" (u5p93) */ public String search(/* 9. Annotation for getting the path variable {keyword} (u5p93) */("keyword") String keyword, ModelMap m){ List items = /* 10. Call the SearchItemByCodeOrName(String keyword) in the ItemRepository */; /* 7. Put the List of items into Model Map, with the name "items" (u5p90)*/ ("items", items); return "items/index"; } //An action for DISPLAY the create page /* 11. Annotation for Context Mapping of this action. This action is to handle HTTP GET. The context path value should be "create" (u5p93 - refer to newCustomer() method) */ public String viewCreate(ModelMap m){ /* 12. Put a form model into Model Map, with the name "newItem" (u5p97 - beware, not 100% the same) */ ("newItem", /* 13. create form model */); return "items/create"; } //An action for HANDLE create form send from client /**** IMPORTANT : You can refer to u5p97 to have a better understanding / references ****/ /* 13. Annotation for Context Mapping of this action. This action is to handle HTTP POST. The context path value should be "create" (u5p97 - refer to create() method) */ public String create(ModelMap m, /* 14. Annotation for Getting the model attribute with name "newItem" */("newItem") /* 15. Annotation for validating the Form Model*/ ItemViewModel _item, /* 16. The class that contains the validation result */ result ){ /* 17. Valid the form model by the ItemValidtor */ if (result./* 18. check whether there are errors */) { //if yes, return to the create page with the original form model m.addAttribute("newItem", /* 19. What is the form model name? */); return "items/create"; } /* 20. Create the Items entity object */ /* 21. Copy the value in form object to the entity object */ /* 22. Use the ItemRepository to persist the entity object*/ //redirect to index page return "redirect:../index"; } //An action for DISPLAY edit page /**** IMPORTANT : You can refer to u5p105 to have a better understanding / references ****/ /* 23. Annotation for Context Mapping of this action. This action is to handle HTTP GET. The context path value should be "edit/{itemId}" (u5p105) */ public String viewEdit(/* 24. Annotation for getting the path variable {itemId} (u5p105) */("itemId") Integer itemId, ModelMap m){ Items _item = itemRepo./* 25. Retrieve Items entity by id from Items Repository */.get(); /* 26. Put the items into Model Map */("editItem", _item); return "items/edit"; } //An action for HANDLE edit form send from client /**** IMPORTANT : You can refer to u5p105 to have a better understanding / references ****/ /* 27. Annotation for Context Mapping of this action. This action is to handle HTTP POST. The context path value should be "edit/{itemId}" (u5p105) */ public String edit(ModelMap m, /* 24. Annotation for getting the path variable {itemId} (u5p105) */("itemId") Integer itemId, /* 25. Annotation for Getting the model attribute with name "editItem" */("editItem") /* 15. Annotation for validating the Form Model*/ ItemViewModel _item, /* 16. The class that contains the validation result */ result ){ /* 17. Valid the form model by the ItemValidtor */ if (result./* 18. check whether there are errors */) { //if yes, return to the edit page with the original form model m.addAttribute("editItem", /* 26. What is the form model name? */); return "items/edit"; } //Retrieve the Items from DB and update the value Items existingItem = itemRepo./* 27. Retrieve Items entity by id from Items Repository */.get(); /* 28. Copy the value in form object to the existingItem */ /* 29. Use the ItemRepository to persist the existingItem */ //redirect to index page return "redirect:../index"; } //An action for HANDLE delete form send from client /**** 30. You should implement a delete action. You can refer to u5p95 to have an idea ****/ /**** IMPORTANT : Please beware * a. the path to redirect * b. In course material, the delete() is incorrect. Arguments of JpaRepository.delete() * is the entity itself, but the course material pass the ID only. IT IS INCORRECT, * YOU CAN TRY. ****/ //A custom error page /* 31. Controller for custom error page. This time, you can 100% copy and paste from course material. So, find out yourself */ }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!