"SSM Distributed architecture e-commerce project-09" Backend Management System Commodity specification parameters

Source: Internet
Author: User
Tags bind data structures json trim
What is a product specification parameter


Analysis:
The format (content) of the specifications of the commodity under the same commodity category is the same as the specific data.
The format of commodity specification parameters for different class purposes is different.
how it is implemented.
Programme one:
Create a table for each product category to store the specification data. You need to store many tables.

Feasibility: Not recommended. There are too many tables to maintain.

Scenario Two:
The idea of using templates is realized.

Scenario Two specific implementation:
1, how to store the template.
A) store to database
b) field cannot be fixed
I. Map
II. Json
2. Stored JSON structure
A) template structure

b) Final data structure
database table Structure

2 sheets are required:
1, the Template table, the need and commodity category related
2, Specification data table, need and Commodity association Template table

Final Data Sheet

Implement Import Pojo

package Com.taotao.manage.pojo;
Import Javax.persistence.Column;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.GenerationType;
Import Javax.persistence.Id;

Import javax.persistence.Table; @Table (name = "Tb_item_param") public class Itemparam extends Basepojo {@Id @GeneratedValue (strategy = Generatio

    ntype.identity) private Long ID;

    @Column (name = "item_cat_id") private Long Itemcatid;

    @Column (name = "Param_data") private String paramdata;
    Public Long GetId () {return id;
    } public void SetId (Long id) {this.id = ID;
    } public Long Getitemcatid () {return itemcatid;
    } public void Setitemcatid (Long itemcatid) {this.itemcatid = Itemcatid;
    } public String Getparamdata () {return paramdata;
    } public void Setparamdata (String paramdata) {this.paramdata = Paramdata; }

}
Package Com.taotao.manage.pojo;

Import Javax.persistence.Column;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.GenerationType;
Import Javax.persistence.Id;
Import javax.persistence.Table;

@Table (name = "Tb_item_param_item") public
class Itemparamitem extends Basepojo {

    @Id
    @GeneratedValue ( Strategy = generationtype.identity)
    private Long ID;

    @Column (name = "item_id")
    private Long itemId;

    @Column (name = "Param_data")
    private String paramdata;

    Public Long getId () {
        return ID;
    }

    public void SetId (Long id) {
        this.id = ID;
    }

    Public Long Getitemid () {
        return itemId;
    }

    public void Setitemid (Long itemId) {
        this.itemid = itemId;
    }

    Public String Getparamdata () {
        return paramdata;
    }

    public void Setparamdata (String paramdata) {
        this.paramdata = paramdata;
    }

}
Create mapper

Package com.taotao.manage.mapper;

Import Com.github.abel533.mapper.Mapper;
Import Com.taotao.manage.pojo.ItemParam;

Public interface Itemparammapper extends mapper<itemparam>{

}
Package com.taotao.manage.mapper;

Import Com.github.abel533.mapper.Mapper;
Import Com.taotao.manage.pojo.ItemParamItem;

Public interface Itemparamitemmapper extends mapper<itemparamitem>{

}
Create service

Package com.taotao.manage.service;

Import Org.springframework.stereotype.Service;

Import Com.taotao.manage.pojo.ItemParam;

@Service public
class Itemparamservice extends baseservice<itemparam>{

}
Package com.taotao.manage.service;


Import Org.springframework.stereotype.Service;

Import Com.taotao.manage.pojo.ItemParamItem;

@Service public
class Itemparamitemservice extends baseservice<itemparamitem> {

}
Create a controller

Package Com.taotao.manage.controller;

Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;

Import Com.taotao.manage.service.ItemParamService;


@RequestMapping ("Item/param")
@Controller public
class Itemparamcontroller {

    @Autowired
    Private Itemparamservice itemparamservice;


}
Package Com.taotao.manage.controller;

Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;

Import Com.taotao.manage.service.ItemParamItemService;

@RequestMapping ("Item/param/item")
@Controller public
class Itemparamitemcontroller {

    @Autowired
    Private Itemparamitemservice itemparamitemservice;


}
Page Features Select Category

Based on the chosen class, if the template exists for that category, remind the user that it exists, and if the template does not exist, you can create a template.
background Development interface for finding templates based on class ID

Package Com.taotao.manage.controller;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.http.HttpStatus;
Import org.springframework.http.ResponseEntity;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.PathVariable;
Import org.springframework.web.bind.annotation.RequestMapping;

Import Org.springframework.web.bind.annotation.RequestMethod;
Import Com.taotao.manage.pojo.ItemParam;


Import Com.taotao.manage.service.ItemParamService; @RequestMapping ("Item/param") @Controller public class Itemparamcontroller {@Autowired private itemparamservice

    Itemparamservice; /** * According to the Product Category ID query specification parameter template * * @param itemcatid * @return */@RequestMapping (value = "{Itemcatid } ", method = requestmethod.get) public responseentity<itemparam> Querybyitemcatid (@PathVariable (" Itemcatid ") Lo
         ng Itemcatid) {try {Itemparam record = new Itemparam ();   Record.setitemcatid (Itemcatid);
            Itemparam Itemparam = This.itemParamService.queryOne (record); if (null = = Itemparam) {//404 return Responseentity.status (Httpstatus.not_found). Body (nu
            ll);
        } return Responseentity.ok (Itemparam);
        } catch (Exception e) {e.printstacktrace ();
    } return Responseentity.status (Httpstatus.internal_server_error). body (null);
 }

}
JS Implementation


Execute the incoming function:
Click Submit Event

$ ("#itemParamAddTable. Submit"). Click (function () {var params = [];
            var groups = $ ("#itemParamAddTable [Name=group]");
                Groups.each (function (i,e) {var p = $ (E). Parentsuntil ("UL"). Parent (). Find ("[Name=param]");
                var _ps = [];
                    P.each (function (_i,_e) {var _val = $ (_e). Siblings ("input"). Val ();                     
                    if ($.trim (_val). length>0) {_ps.push (_val);
                }
                });
                var _val = $ (E). Siblings ("input"). Val (); if ($.trim (_val). length>0 && _ps.length > 0) {params.push ({"Grou                 
                P ": _val," params ": _ps});
            }
            });
            var url = "/rest/item/param/" +$ ("#itemParamAddTable [Name=cid]"). Val (); $.post (url,{"Paramdata": Json.stringify (paraMS)},function (data) {$.messager.alert (' hint ', ' new product specification succeeded! '), Undefined,function () {$ (". Panel
                    -tool-close "). Click ();
                $ ("#itemParamList"). DataGrid ("Reload");
            });
        }); });

View Submission Data:

Submitted Data structures:
back-end implementations

Package Com.taotao.manage.controller;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.http.HttpStatus;
Import org.springframework.http.ResponseEntity;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.PathVariable;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestMethod;

Import Org.springframework.web.bind.annotation.RequestParam;
Import Com.taotao.manage.pojo.ItemParam;


Import Com.taotao.manage.service.ItemParamService; @RequestMapping ("Item/param") @Controller public class Itemparamcontroller {@Autowired private itemparamservice

    Itemparamservice; /** * According to the Product Category ID query specification parameter template * * @param itemcatid * @return */@RequestMapping (value = "{Itemcatid } ", method = requestmethod.get) public responseentity<itemparam> Querybyitemcatid (@PathVariable (" Itemcatid ") Lo ng Itemcatid) {TRy {itemparam record = new Itemparam ();
            Record.setitemcatid (Itemcatid);
            Itemparam Itemparam = This.itemParamService.queryOne (record); if (null = = Itemparam) {//404 return Responseentity.status (Httpstatus.not_found). Body (nu
            ll);
        } return Responseentity.ok (Itemparam);
        } catch (Exception e) {e.printstacktrace ();
    } return Responseentity.status (Httpstatus.internal_server_error). body (null); }/** * NEW specification Template * * @param itemcatid * @param paramdata * @return * * * @RequestMap Ping (value = "{Itemcatid}", method = requestmethod.post) public responseentity<void> Saveitemparam (@PathVariable ("Itemcatid")  Long Itemcatid, @RequestParam ("Paramdata") String Paramdata) {try {Itemparam Itemparam =
            New Itemparam ();
            Itemparam.setid (NULL); Itemparam.setitemcatiD (Itemcatid);
            Itemparam.setparamdata (Paramdata);
            This.itemParamService.save (Itemparam);
        Return Responseentity.status (httpstatus.created). build ();
        } catch (Exception e) {e.printstacktrace ();
    } return Responseentity.status (Httpstatus.internal_server_error). build ();
 }


}

Test results:

Then we re-select the phone category:

Clicking OK will reopen the Select Class box:
Apply template input data when new product is added trigger Load template When class is selected

Dynamically Generate form Contents:

After adding a product selection category (select phone) The effect is as follows:
Click the Submit button to generate the JSON data from the user's input .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.