spring - How can I manage dynamic model with AngularJS and springdata mongodb -


i have created project using angularjs + spring-data-mongodb + mongodb. i'd manage crud operations model change dynamically according concept of object inheritance.

the frontend: if user selects "vehicle" form contain attributes of vehicle. if user selects vehicle type "car" form contain attributes of "vehicle" plus attributes of "car". if user selects vehicle type "motorcycle" form contain attributes of "vehicle" plus attributes of "motorcycle".

angularjs form model:

<div ng-controller="vehicleformctrl">    <input type="text" class="form-control" id="inputfielda" ng-model="vehicle.name">    <select class="form-control" ng-model="vehicletype" ng-change="selectvehicletype()" ng-options="k v (k, v) in vehicletypes">   </select>    ...   <input type="text" class="form-control" id="inputfieldcar" ng-model="car.name">    ...   <input type="text" class="form-control" id="inputfieldmotorcyle" ng-model="motorcycle.name">    ... </div> 

java object:

@document public class vehicle {      @id     private string id;     ...     private string type;     private string name;  }  @document public class car extends vehicle {      @id     private string id;     ...     private string carcolor; }  @document public class motorcycle extends vehicle {      @id     private string id;     ...     private string motorcyclecolor; } 

this spring controller method:

@requestmapping(method = requestmethod.post, value = "/save", consumes = "application/json",produces = "application/json") @responsebody public responseentity<void> savevehicle(@requestbody vehicledto vehicle) {     ... } 

this spring repository method:

mongotemplate mongotemplate;  vehicle vehicle = new vehicle(); ... mongotemplate.insert(vehicle, "vehicle"); // vehicle.class or car.class or motorcycle.class ? 

example of mongodb documents ("vehicle" collection):

{"_id":"1", "type":"vehicle", "name":"tesla"} {"_id":"2", "type":"car", "name":"landrover", "carcolor":"red"} {"_id":"3", "type":"motorcycle", "name":"ducati", "motorcyclecolor":"yellow"} 

how can model @document pojo, crud methods , angularjs project in order manage object inheritance? approach choise? alternatives?

i read mongodb documentation , other related questions spring-data mongodb repository , inheritance , inheritance in document database?.

i'm using angularjs 1.2, spring 4.1 , spring-data-mongodb 1.8. thanks.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -