Ir al contenido principal

Spring Boot - Web Apps

Web Apps


  • Create a folder resources for the view in
<PROJECT>\src\main
  • Create a subfolder names public. In this folder put the JS files, html files, images, etc
<PROJECT>\
          ->  src\
                  ->main
                             ->java
                             ->resources
                                      ->public
                                            ->index.html


  • Ex. Add a file named index.html
To access the file you start the project and then access though the explorer as:
http://localhost:8080/index.html#/



SPRING MVC REST Controller


  • GET   /api/v1/<elements>  (list)
  • POST /api/v1/<elements>  (add)
  • GET /api/v1/<elements>/{id}  (view)
  • PUT /api/v1/<elements>/{id}  (update)
  • DELETE /api/v1/<elements>/{id}  (delete)

Creating a Controller

  • Create them in controller folder

    • Name the file as 
      • <Entity>Controller.java

    • Add the annotation to create the controller

      • @RestController

    • Add a second annotaion to define the URL

      • @RequestMapping("<BASE_url>/")    
      • Ex  @RequestMapping("api/v1")

  • Add a list endpoint (methods)

    • Add the method with the annotion @RequestMapping

@RestController
@RequestMapping("api/v1")
public class EvaluationController {


@Autowired
private EvaluationRepository evaluationRepository;

@RequestMapping(value = "evaluation", method = RequestMethod.GET)
public List<Shipwreck> list() {

return shipwreckRepository.findAll();
}


        @RequestMapping(value = "shipwrecks", method = RequestMethod.POST)
public Shipwreck create(@RequestBody Shipwreck shipwreck) {
return shipwreckRepository.saveAndFlush(shipwreck);
}

@RequestMapping(value = "shipwrecks/{id}", method = RequestMethod.GET)
public Shipwreck get(@PathVariable Long id) {
return shipwreckRepository.findOne(id);
}

@RequestMapping(value = "shipwrecks/{id}", method = RequestMethod.PUT)
public Shipwreck update(@PathVariable Long id, @RequestBody Shipwreck shipwreck) {
Shipwreck existingShipwreck = shipwreckRepository.findOne(id);
BeanUtils.copyProperties(shipwreck, existingShipwreck);
return shipwreckRepository.saveAndFlush(existingShipwreck);

}


}
  • Create the entities to return the Result in the folder MODEL
    •  scr/main/java/<project>/model


Invoke from AngularJS



  • Create a service

    • This contains the URL to your endpoint
    • include $resource


(function() {

var app = angular.module('app');

app.factory("evaluationService", function($resource) {

return $resource('/api/v1/evaluation/:id', {
id : '@id'
}, {
update : {
method : 'PUT'
}
});

});

}());


  • Invoke from the controller

    • Pass the service previously created
    • evaluationService.query();   
      • Get all the results
      • query() is a function from $resource

(function() {

var experienceEvaluationController = function($scope, $location, $anchorScroll, evaluationService) {
$scope.evaluationService = evaluationService.query();
}

var app = angular.module('app');

app.controller("experienceEvaluationController", experienceEvaluationController);

}());





Mapping with $resource


  • GET   /api/v1/<elements>  (list)
    • evaluationService.query();

  • POST /api/v1/<elements>  (add)
 $scope.evaluationService  = new evaluationService ();  //create new evaluationService instance. Properties will be set via ng-model on UI

  $scope.addEvaluation = function() { 
           evaluationService .$save(function() {

    });
  };

  • GET /api/v1/<elements>/{id}  (view)

evaluationService.evaluationService


  • PUT /api/v1/<elements>/{id}  (update)

 $scope.updateShipwreck = function() { 
    evaluationService.$update(function() {

    });
  };

  • DELETE /api/v1/<elements>/{id}  (delete)
 evaluationService.$delete(function() {
        $state.go('evaluation');
      });



Configuring App


All the properties are in Spring Properties

  • Create a properties file in the folder resources
    • application.properties - This is the default properties file to be used by Spring Boot

  • Creating  a log
    • Now you can create a log directly
    • logging.level.org.springframework.web = DEBUG

  • Server Port
    • server.port=8180

  • Productive / Test configuration
Name the files as follows:
    • application-prod.properties
    • application-test.properties
Then in the Run Configuration, pass as VM argument the profile
    • -Dspring.profiles.active=prod

































Comentarios

Entradas populares de este blog

Android - Basic Steps (Service)

Service Run in the main thread of the hosting application Android can kill the Service if need the resources Purpose Supporting inter-application method execution Performing background processing Start a Service Call Context.startService(Intent intent)\ To call from a Fragment use getActivity().getApplicationContext().startService( intentService); Executing the service After call startService(...)  In the Service is executed the method onStartCommand(...) If the method returns the constant START_NOT_STICKY then Android will not restart the service automatically if the the process is killedp Foreground To execute the service foreground call the method startForeground() Use this if the user is aware of the process Bind to a Service Call the method Context.bindService( Intent service ServiceConnection con int flags ) Send Toast from the Service On the method onStartCommand receive the message   ...

BI - SSIS ( Basics I )

SSIS - Basic Concepts Tasks Bulk Insert Task—Loads data into a table by using the BULK INSERT SQL command. Data Flow Task—This is the most important task that loads and transforms data into an OLE DB Destination. Execute Package Task—Enables you to execute a package from within a package, making your SSIS packages modular. Execute Process Task—Executes a program external to your package, like one to split your extract file into many files before processing the individual files. Execute SQL Task—Executes a SQL statement or stored procedure. File System Task—This task can handle directory operations like creating, renaming, or deleting a directory. It can also manage file operations like moving, copying, or deleting files. FTP Task—Sends or receives files from an FTP site. Script Task—Runs a set of VB.NET or C# coding inside a Visual Studio environment. Send Mail Task—Sends a mail message through SMTP. Analysis Services Processing Task—This task processes a SQL Server A...

TOGAF9

Kinds of Architectures Business Architecture / Business Process Architecture    Define the business strategy, governance, organization and key business processes Data Architecture    Describe the structure of an organization logical and physical data assets and data resources Application Architecture    Describe a blueprint for the individual application systems to be deploy, interactions and  their relationships to the core business processes of the organization Technology Architecture    Describe the logical software and hardware capabilities that are required to support the deployment of business data and application services. This includes middle-ware infrastructure, networks, communications, processing standards  Architecture Governance Increase transparency of accountability, and informed delegation of authority Controlled risk management Protection of the existing asset base through maximizing  re-us...