Ir al contenido principal

Entradas

Mostrando entradas de junio, 2017

AngularJS: Modules & Controller

Modules Module contains Controllers Module in AngularJS var app = angular.module( "myModule" , [dependecies, ...] ); The first parameter is the Module's name The second parameter is an array with the dependencies. The array can be empty []  Controller Controller in AngularJS var MyController = function( $scope, $http){    //.... } app .controller( "MyControllerName", MyController ); Include Module To include the module in the HTML use ng-app <body  ng-app="myModule" > </body>

AngularJS: Controller

Controller Takes the controll of a section in the HTML The directive is ng-controller AngularJS invoke the controller Controller use $scope as parameter Attach the model to $scope $http Service Encapsulate HTTP communication GET POST PUT DELETE Can be added in any controller var MyController = function( $scope, $http ){      $scope.user = $http.get("user/123"). } $http works base on PROMISE of fetch some data, therefore the code should be var MyController = function( $scope, $http ){      $scope.user = $http.get("user/123").then (            function( response ){                      $scope.message = response.data;               }      ); } OR var MyController = function( $scope, $http ){     var onRequestComplete = function (response) { ...

AngularJS: Get Started

AngularJS Add angular.js Add tag ng-app in HTML tag <html ng-app> ng-app : start AngulaJS ng = AngularJS {{ }} JavaScript Functions In this example the last line execute all the code. var work = function(){      console.log("working"); }  var dowork = function (f){      try{     f();   }catch(ex){     console.log(ex);   }    } dowork(work); Module Modules allow to create object in JS In this case is creating an object named "worker" and is created by "createWorker" that return an object with 2 methods var createWorker = function() {      var count = 0;      var job1 = function(){     count +=1;     console.log(count);   };      var task2 = function(){     count +=1;     console.log(count);   };  ...

Spring Boot - MySQL / SQL Server

Spring Boot - MySQL Add MySQL dependency <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> Add the properties in application.properties spring.jpa.hibernate.ddl-auto=none spring.datasource.url=jdbc:mysql://localhost:3306/baseband spring.datasource.username=root spring.datasource.password=admin Spring Boot - SQL Server Add dependency                  <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>6.1.0.jre8</version> </dependency> Properties spring.datasource.url=jdbc:sqlserver://146.250.116.35:1433;databaseName=ServiceRecruitment spring.datasource.username=sa spring.datasource.password=N@viembre2514 spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLSer...

Spring Boot - Testing

Frameworks Spring-boot-starter-test Always start with the starter   Integrate the above frameworks < dependency > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-test </ artifactId > < scope > test </ scope > </ dependency > JUnit For unit testing Hamcrest Matching and assertion Mockito Mock objects and verify Spring Test Testing tools & integration testing support Creating a Test First in src/test/java create the following class for test the Controller package  com.ericsson.project; import  org.junit.Test; public   class  AppTest  {     @Test      public   void  testApp()     {     } } Add the following code in testApp() HomeController  hc  =  new  HomeController(); ...

Spring Boot - JPA Entity

JPA Entity In the folder Model create the class Add the annotation @Entity above the class import javax.persistence.Entity; Add the annotation @Id to create the primary key @Id @GeneratedValue (strategy = GenerationType. AUTO ) Long  id ; Specify a column name for a reserved word @Column(name="`condition`") String condition; Repository (Queries) Create a folder name repository in scr/main/java <project> repository Create an interface named <Entity>Repository.java Extends from JpaRepository For customize queries  Add the annotation  @Query algon your query Define the parameters The table name should be the class name that is using @Entity public interface ShipwreckRepository extends JpaRepository<Shipwreck, Long>{        @Query("SELECT p FROM PerformanceLevel p WHERE p.js_id = :js_id") public List<PerformanceLevel> findJs( @Par...

Spring Boot - Migration / Data Source

Implement H2 In this case first will be use H2 Add H2 to pom.xml, in the dependencies section.         <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>         <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> Modify application.properties file adding the following properties: The files is in scr/main/resources spring.h2.console.enabled=true spring.h2.console.path=/h2 The value in path property is the URL to see H2 database console. Ex. http://localhost:8080/h2/ Migration Use Flyway Add in pom.xaml the dependency < dependency >               ...

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:...

Spring Boot - Configuration

Spring Boot For Spring Boot I am using Spring STS (Spring Tool Suite) a customize version of eclipse. 1) Create a Maven project Fill Group Id:  E.x:  com.boot Fill Artifact Id:  Ex.   das.boot 2)  Add in pom.xml, Spring boot. The parent and dependecy: //After packing tag <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.1.RELEASE</version> </parent> <dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-web</artifactId>   </dependency> 3) Create packages as: controller model repository service 4) Create a Controller In the Controller package create a class named: HomeController add to the class @RestController Create the request mapping Run the App.class as Java Application ...

Java Fundamentals: Generics

Implement a Generic Type Eg. MyClassComparator implements Comparator<MyClass> Pass up a Type Parameter Eg. Reverse<T> implements Comparator< T > Type Bounds Ex. SortedMyClass < T extends Comparable <T>> SortedMyClass will received only a class that will be comparable with itself Generics on Methods Eg.- public static <T> T myMethod (  List<T> , Compartor<T>)  <T> - Indicate that the method will return a generic T   -   Indicate that the method is generic

Java Fundamentals - Collections - Defining

Collection (Interface)    --> List Have an order, index   -->Set Have only one element without be duplicated -->SortedSet Have unique elements in an order. You can´t add element in any position   -->Queue Has an order: FIFO Fisrt in First Out   -->Deque Has a doble ending queue: FIFO & LIFO Key Collections Both are collections in pairs: Keys/Values   -->Map   -->SortedMap Can iterate over the Map and see the values in certain order Implementation  -->List      -->ArrayList getElement - ok add - Fail contains - fail next - ok remove - fail      -->LinkedList getElement - fail add - ok contains - fail next - ok remove - ok   -->Set       -->HashSet   -->SortedSet      -->TreeSet   -->Queue      -->PriorityQueue In this case you need to cr...