Posts

Swift Initialization

Image
Swift has introduced new type of variables called Optional . These are used to hold nil value in swift. Because of these variable, there are some changes regarding initialization of variables. Here are details for the same:   1. It is must to have initializer in swift if using non-optional property.   2. You need to UnWrap optional variables before using them: 3. If Property can be nil then use ? after property, before setting any value: 4. If you unwrap the property while declaring, then you can use it directly. Please note that it is not considered as good practice as it may cause crash at run time. 5.  With Swift new version, you need to implement initWithCoder method if using init method. 6. Before accessing self properties ( eg view), you must call super class method during init and initWithCoder . 7.  You can create object before calling super method and after that can assign values to that object: 8.  You can

#4 Working with Spring MVC

Image
MVC stands for Model-View-Controller. MVC in spring required: Some JSP pages ( views) which need to be displayed. Controller which used to access views Model to set for views So lets start with MVC. Before starting I hope you have idea of basic REST api development. If not then you can follow steps here . For MVC, we need to follow steps below: 1. Create a ModelController class. Add annotation  @Controller on top ( with @RestController it will not work). 2. Create JSP page, let say index.jsp . Please check hierarchy in folder structure for index . jsp page as we will require to tell our application that from where JSP pages need to pick. 3. Create HelloConfig.java  to register InternalResourceViewResolver .  InternalResourceViewResolver  is used at application level to tell application path of JSP/CSS files. I have set path to "/WEB-INF/pages" and added suffix as .jsp . So now I won't require to specify .jsp explicity.

#5 Passing argument in Spring MVC

Image
This tutorial is next step of my previous tutorial . In this tutorial we will simply create: One login form. One success page One failure page Controller for redirection 1. Lets start with Login form as given below: Please note that in form I have defined action as login_authenticate . This will be the REST api name which we will require to develop. Once login will press it will search for  login_authenticate api. 2. Create Error page as below: 3.Create Welcome page as below: Please note that I have used ${name} . It will pick value set via ModelMap ( see login_authenticate api below in blog.) 4. Create  login  api in ModelController to display login page: 5. Now create  login_authenticate api which will be called for authentication. Please note that in below api we added some constant username/password for authentication. You can use your Db for the same: In above api I just read value of JSP email and password field. Af

#3 Passing Query Paramater In REST API

Image
Please go through series 1 and series 2 before starting this tutorial. In my last tutorials I have explained that how can we create simple hello world API and how can we access DB by using JDBCTemplate . JDBCTemplate is spring framework's library which make easy to access the DB. So now let me continue to the topic. Lets extends EmployeeDao to another method which will fetch Employee data based on email id passed. Please see the example below: Please note that I have added another method with email parameter. Now lets implement this method in interface implementation class ( named as EmployeeDaoImpl ): Now lets write REST api to access employee data with email passed. Write following method in your Controller class: We write another REST api names getemployee with request parameter email.  I have used  @RequestParam for parameter. You can make parameter as required OR optional . Now to access api you can call rest url as given below, by passin

#2 Simple Spring Rest Api with JDBC connection

Image
Before starting this tutorial, I am assuming that you guys have basic idea of Spring. If you don't have basic idea of simple Spring API then no worry :), I have written simple tutorial here to start with Spring Boot . This tutorial is next version of my first tutorial . In my first tutorial I explained that how can we make a simple REST api with Spring Boot .  So lets start with JDBC connection in some very simple steps: 1. Create DB schema and table I prefer MySqlWorkBench for this purpose ( you can use any way to create schema). For this tutorial I have named my db as test_db . This DB contains one Employee table with below schema: Table contains id, name and email of employee ( This is just for tutorial, You make table as per your requirement). Once you created table, Insert some dummy data for your REST api. Your api will be fetching this data and will return it as JSON. I have made some of dummy entries as below: 2. Add Maven depen

#1 My First Rest API With Spring Boot Freamwork

Image
I hope you must be familiar with Java . Spring is a Java framework which is used for Rest api development by using Java as language. If you want to have basic idea about spring then you can visit here . In this tutorial I will be focusing on simple rest api using Get method. Please follow steps below to create your first Rest api: 1. Create project schema: While creating project schema, we can simply create via eclipse by going file -> new -> Maven Project .  If we are using above method to create project schema then for Maven dependencies we will need to make entry in Pom.XML. To avoid that we can refer  start.spring.io . In this tutorial I will be creating project via this interface only. So lets avoid any more delay and start development in some very simple steps: Open website  start.spring.io  and enter group (package), Artifact (name). After this add all required dependencies. Initially we will required only Spring MVC dependency as in screenshot bel