Posts

Showing posts from February, 2018

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