Spring MVC Notes

June 11, 2019 | Author: VKM2013 | Category: Java Servlet, Software Design, Computing Platforms, Software Engineering, Java Platform
Share Embed Donate


Short Description

Java Servlet MVC Model...

Description

Spring MVC Notes: >Change Perspective to JavaEE > Get a server view. (Window->Showview->server >se!ect a server " #rowse $ead%&nsta!!ed 'ocation. >inish --------------------------------------------------i!e>new>)*na+ic We# Pro,ect. Provide Pro,ect na+e>net>net> Chec we#.+! generation >inish ---------------------------Sa+p!e Prora+:  J/0S: Cop* and paste a!! Spring-J/0S in !i# 1o!der. 1o!der. --------------------------------------Step 2: Con3g4re )ispatcherServ!et in we#.+! step 5: creating spring con3g 3!e: na+e r4!e: 67serv!et-na+e>8-serv!et.+! 'ocation: %WE9-&N% !ocation. Step : Con3g4re / view 0eso!ver C!ass. With pre3 and s4;. Step Create a Java c!ass.

>=se an annotation Contro!!er (Sterio t*pe annot.  >Ena#!e annotations in con3g 3!e (4se contet sche+a 1or #ase paage and annotation con3g >Writre a re?4est +ethod. (0e?4estMapping(@%4r!@ e: 0e?4estMapping(@%ho+e@ -- GEA t*pe 0e?4estMapping(va!4eB@%a#cd@"+ethodB0e?4est Method.PSA > 0et4rn a Mode!/ndView #,ect. e: ret4rn new Mode!/ndView(@$o+ePage@D

Step : V&EW : create a 1o!der str4ct4re 1or pre3 (i1 not eist e: %WE9-&N%,sps -------------------------------------Note: 0e?4estMethod is en4+" which de3ne na+ed constans 1or re?4est +ethods !ie GEA"PSA"P=A"A0/CE...etc

We#.+! sample org.springframework.web.servlet.ispatcher!ervlet sample

!ample-servlet.xml

omeontroller.,ava

pacage com.app.controller i+port ,ava."til.0rra%List i+port ,ava."til.List i+port org.springframework.stereot%pe.ontroller i+port org.springframework.web.bind.annotation.1e2"est3apping i+port org.springframework.web.bind.annotation.1e2"est3ethod i+port org.springframework.web.servlet.3odel0nd4iew 5ontroller p4#!ic c!ass omeontroller 6 51e2"est3apping78/home89 p4#!ic 3odel0nd4iew show4iew796 //3odel0nd4iew mav=new 3odel0nd4iew78omeage89 //ret"rn mav !tring s;=8hello8 'mplo%ee emp=new 'mplo%ee79 emp.set'mp)d7;;9 emp.set'mp*ame780(89 List listata= new 0rra%List79 listata.add78hello89 listata.add78b%e89 listata.add78ok89

ret4rn new 3odel0nd4iew78omeage88listata8listata9  51e2"est3apping7val"e=8/home8method=1e2"est3ethod.45ST  9 p4#!ic 3odel0nd4iew show4iew;796

ret4rn n4!!

  'mplo%ee.,ava pacage com.app.controller

p4#!ic c!ass 'mplo%ee 6 private int emp)d private !tring emp*ame p4#!ic int get'mp)d79 6 ret4rn emp)d  p4#!ic void set'mp)d7int emp)d9 6 this.emp)d = emp)d  p4#!ic !tring get'mp*ame79 6 ret4rn emp*ame  p4#!ic void set'mp*ame7!tring emp*ame9 6 this.emp*ame = emp*ame 



View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF