J2EE & SAP Portal & Swift
Friday, February 07, 2014
Continue: How the Controllers Look Like
Here is one of the controllers.
package com.mycomp.app1.controllers; import java.util.Collection; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.context.request.WebRequest; @Controller public class MyApp1Controller { private static final String SESSION_ATTRIBUTE_ABC = "ABC"; private MyApp1Service myApp1Service; @Autowired public void setMyApp1Service(MyApp1Service myApp1Service) { this.myApp1Service = myApp1Service; } @RequestMapping(value = "/myapp1m1.do", method = RequestMethod.GET, produces = "application/json; charset=utf-8") public @ResponseBody RequestBoxWrapper myapp1m1(WebRequest webRequest) { ... return myapp1(some, webRequest); } @RequestMapping(value = "/myapp1m1.do", method = RequestMethod.POST, consumes = "application/json; charset=utf-8", produces = "application/json; charset=utf-8") public @ResponseBody RequestBoxWrapper myapp1m1(@RequestBody Some some, WebRequest webRequest) { webRequest.setAttribute(SESSION_ATTRIBUTE_ABC, some, WebRequest.SCOPE_SESSION); ... return ...; } @RequestMapping(value = "/myapp1m2.do", method = RequestMethod.GET, produces = "application/json; charset=utf-8") public @ResponseBody ResponseBoxWrapper myapp1m2( @RequestParam("myparam") Param param, WebRequest webRequest) { Some some = (Some) webRequest.getAttribute( SESSION_ATTRIBUTE_ABC, WebRequest.SCOPE_SESSION); ... return ...; } }
The myApp1Service matches the bean myApp1Service. Name matching is the most simple way of autowire.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
Blog Archive
►
2016
(3)
►
August 2016
(3)
►
2015
(2)
►
March 2015
(2)
▼
2014
(11)
▼
February 2014
(11)
Separate Properties from WAR
Use Maven to Manage Javascript Libraries
MyEclipse Install/Uninstall Zip File to Maven Loca...
Continue: How the CastorMarshaller Mapping Look Like
Continue: How WebServiceTemplate Look Like
Continue: How the Data Access Bean Look Like
Continue: How the Controllers Look Like
Example: Spring-MVC Spring-JDBC Spring-WS CastorMa...
RESTClient to Test JSON Web Services
Example: JBoss and LDAP
MyEclipse Enable Maven Dependencies in the Build Path
►
2013
(2)
►
December 2013
(1)
►
January 2013
(1)
►
2012
(6)
►
September 2012
(1)
►
July 2012
(1)
►
June 2012
(1)
►
April 2012
(1)
►
March 2012
(1)
►
February 2012
(1)
►
2011
(2)
►
September 2011
(2)
►
2010
(25)
►
October 2010
(2)
►
September 2010
(2)
►
August 2010
(1)
►
July 2010
(1)
►
June 2010
(2)
►
May 2010
(4)
►
April 2010
(1)
►
March 2010
(9)
►
February 2010
(1)
►
January 2010
(2)
►
2009
(61)
►
December 2009
(2)
►
November 2009
(4)
►
October 2009
(4)
►
September 2009
(2)
►
August 2009
(1)
►
July 2009
(3)
►
June 2009
(2)
►
May 2009
(25)
►
April 2009
(2)
►
March 2009
(2)
►
February 2009
(9)
►
January 2009
(5)
►
2008
(30)
►
December 2008
(2)
►
November 2008
(2)
►
October 2008
(3)
►
September 2008
(1)
►
August 2008
(5)
►
May 2008
(1)
►
April 2008
(6)
►
March 2008
(8)
►
January 2008
(2)
►
2007
(61)
►
December 2007
(3)
►
November 2007
(9)
►
October 2007
(10)
►
September 2007
(7)
►
August 2007
(6)
►
July 2007
(1)
►
June 2007
(1)
►
May 2007
(6)
►
April 2007
(6)
►
March 2007
(1)
►
February 2007
(10)
►
January 2007
(1)
►
2006
(113)
►
December 2006
(7)
►
November 2006
(4)
►
October 2006
(15)
►
September 2006
(33)
►
August 2006
(3)
►
July 2006
(51)
J2EE Fans
No comments:
Post a Comment