Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name = "categories")
- public class Category {
- @Id
- @GeneratedValue(generator = "uuid2")
- @GenericGenerator(name = "uuid2", strategy = "uuid2")
- @Column(columnDefinition = "BINARY(16)")
- private UUID id;
- @Column(name = "category_code")
- private String categoryCode;
- @Column(name = "category_name")
- private String categoryName;
- ....
- }
- <div class="col-md-8">
- <form:form action="saveCategory" modelAttribute="category" method="POST">
- <fieldset>
- <legend>
- <button type="button" class="btn btn-primary btn-xs" id="addCategory"><span class="glyphicon glyphicon-plus"></span>
- </button>
- </legend>
- <div class="row">
- <div class="col-md-2">
- </div>
- <div class="col-md-8">
- <table id="catTable" class="table table-striped">
- <thead>
- <tr>
- <th><label> Category Code: </label></th>
- <th><label> Category Name: </label></th>
- <th><label> Action: </label></th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- </div>
- <div class="col-md-2">
- </div>
- </div>
- </fieldset>
- <br><br>
- <button type="submit" name="save" value="Save" class="btn btn-primary" style="position:absolute; right:0; bottom:0;">Save</button>
- </form:form>
- </div>
- /* <!-- create dynamic table with modal value --> */
- $("#createCategory").on("click", function() {
- if ($(".current-row").length == 0) {
- $("#catTable tbody").append('<tr class="current-row"></tr>');
- }
- var id = $("#modal_id").val();
- var code = $("#modal_category_code").val();
- var name = $("#modal_category_name").val();
- var html = ""+
- '<td class="code">'+ code + '</td>'+
- '<td class="name">'+ name + '</td>'+
- '<td class="width-80">' +
- '<button type="button" class="btn-xs"> <span class="glyphicon glyphicon-edit"></span></button>' +
- '<button type="button" onclick="delRow(this);" class="btn-xs"><span class="glyphicon glyphicon-trash"></span></button>' +
- '<input name="id[]" type="hidden" class="category-id" value="' + id + '"/>' +
- '<input name="category_code[]" type="hidden" class="category-code" value="' + code + '"/>' +
- '<input name="category_name[]" type="hidden" class="category-name" value="' + name + '"/>' +
- '</td>';
- $("#catTable tbody .current-row").html(html);
- $("tr").removeClass("current-row");
- $("#catModal").modal("hide");
- });
- @PostMapping("/saveCategory")
- public ModelAndView saveCategory(@ModelAttribute("category") Category category) {
- //save the category using service
- WebResponse response = categoryService.addCategory(category);
- if(response.getStatus().equals("error")) {
- return new ModelAndView("redirect:/admin/category/createCategory");
- }
- return new ModelAndView("category/show-category");
- }
Add Comment
Please, Sign In to add comment