title: Insert into database using AngularJS and SPRING
body: <p>I am pretty new to AngularJS, I am trying to figure out how I can call a method from my SPRING controller, or is there another way to achieve this?</p>
  
  <p>My app.js looks like this:</p>
  
  <pre><code> //  Define a module
  var myApp = angular.module('createWorkshopApp', []);
  
  //  Create controller
  myApp.controller('mainController',
          function ($scope, $http) {
  
              $scope.workshop = {};
  
              $scope.createWorkshop = function () {
                  if ($scope.workshopName == "" || $scope.workshopDescription == "") {
                      alert("Insufficient Data! Please provide values for workshop name and description");
                  }
                  else {
                      $http({
                          method: 'POST',
                          url: '/create',
                          data: $scope.workshop
                      }).
                              success(function (data, status, headers, config) {
                                  // Into database.. ??
  
                                  alert('Workshop saved!');
                              }).
                              error(function (data, status, headers, config) {
                                  if (status == 400) {
                                      alert('404');
                                  } else {
                                      alert('Unexpected server error.');
                                  }
  
                              });
                  }
  
              };
  
          });
  </code></pre>
  
  <p>And my WorkshopController.java looks like this:</p>
  
  <pre><code>&gt;  /**
  &gt;      *
  &gt;      * @param workshop
  &gt;      * @param result
  &gt;      * @return view of the workshop
  &gt;      */
  &gt;     @RequestMapping(value = "/workshop/create", method = RequestMethod.POST, headers = "Accept=application/json")
  &gt;     public String addWorkshop(@Valid Workshop workshop, BindingResult result) throws ParseException {
  &gt;         if (result.hasErrors()) {
  &gt;             return BASE_URL + "create";
  &gt;         } else {
  &gt;             this.workshopService.addWorkshop(workshop);;
  &gt;             return "redirect:" + BASE_URL + "view/" + workshop.getId();
  &gt;         }
  &gt;     }
  </code></pre>
  
  <p>I also have a java file named workShopService.java which looks like this</p>
  
  <pre><code>@Service
  @Transactional
  public class WorkshopService {
  
      @Autowired
      private WorkshopDAO workshopDAO;
  
  
      public void addWorkshop(Workshop workshop) {
          workshopDAO.addWorkshop(workshop);
      }
  
      public Workshop getWorkshop(int id) {
          return workshopDAO.getWorkshop(id);
      }
  
      public List&lt;Workshop&gt; getWorkshops() {
          return workshopDAO.getWorkshops();
      }
  
  }
  </code></pre>
  
  <p>I started out with SPRING(MVC) and HIBERNATE, now I am confused on what role the Controller has, since with AngularJS you already create a controller.</p>