Guest User

Untitled

a guest
Aug 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. @Entity
  2. @Table(name = "categories")
  3. public class Category {
  4.  
  5. @Id
  6. @GeneratedValue(generator = "uuid2")
  7. @GenericGenerator(name = "uuid2", strategy = "uuid2")
  8. @Column(columnDefinition = "BINARY(16)")
  9. private UUID id;
  10.  
  11. @Column(name = "category_code")
  12. private String categoryCode;
  13.  
  14. @Column(name = "category_name")
  15. private String categoryName;
  16. ....
  17. }
  18.  
  19. <div class="col-md-8">
  20. <form:form action="saveCategory" modelAttribute="category" method="POST">
  21. <fieldset>
  22. <legend>
  23. <button type="button" class="btn btn-primary btn-xs" id="addCategory"><span class="glyphicon glyphicon-plus"></span>
  24. </button>
  25. </legend>
  26. <div class="row">
  27. <div class="col-md-2">
  28. </div>
  29. <div class="col-md-8">
  30. <table id="catTable" class="table table-striped">
  31. <thead>
  32. <tr>
  33. <th><label> Category Code: </label></th>
  34. <th><label> Category Name: </label></th>
  35. <th><label> Action: </label></th>
  36. </tr>
  37. </thead>
  38. <tbody>
  39.  
  40. </tbody>
  41. </table>
  42. </div>
  43. <div class="col-md-2">
  44. </div>
  45. </div>
  46. </fieldset>
  47. <br><br>
  48. <button type="submit" name="save" value="Save" class="btn btn-primary" style="position:absolute; right:0; bottom:0;">Save</button>
  49. </form:form>
  50. </div>
  51.  
  52. /* <!-- create dynamic table with modal value --> */
  53. $("#createCategory").on("click", function() {
  54.  
  55. if ($(".current-row").length == 0) {
  56. $("#catTable tbody").append('<tr class="current-row"></tr>');
  57. }
  58.  
  59. var id = $("#modal_id").val();
  60. var code = $("#modal_category_code").val();
  61. var name = $("#modal_category_name").val();
  62.  
  63. var html = ""+
  64. '<td class="code">'+ code + '</td>'+
  65. '<td class="name">'+ name + '</td>'+
  66. '<td class="width-80">' +
  67. '<button type="button" class="btn-xs"> <span class="glyphicon glyphicon-edit"></span></button>' +
  68. '<button type="button" onclick="delRow(this);" class="btn-xs"><span class="glyphicon glyphicon-trash"></span></button>' +
  69. '<input name="id[]" type="hidden" class="category-id" value="' + id + '"/>' +
  70. '<input name="category_code[]" type="hidden" class="category-code" value="' + code + '"/>' +
  71. '<input name="category_name[]" type="hidden" class="category-name" value="' + name + '"/>' +
  72. '</td>';
  73.  
  74. $("#catTable tbody .current-row").html(html);
  75. $("tr").removeClass("current-row");
  76. $("#catModal").modal("hide");
  77. });
  78.  
  79. @PostMapping("/saveCategory")
  80. public ModelAndView saveCategory(@ModelAttribute("category") Category category) {
  81.  
  82. //save the category using service
  83. WebResponse response = categoryService.addCategory(category);
  84.  
  85. if(response.getStatus().equals("error")) {
  86. return new ModelAndView("redirect:/admin/category/createCategory");
  87. }
  88.  
  89. return new ModelAndView("category/show-category");
  90.  
  91. }
Add Comment
Please, Sign In to add comment