开发者

Spring MVC very simple design question

开发者 https://www.devze.com 2023-03-25 10:01 出处:网络
I\'m new to Spring MVC and want to ask a very simple question about simplicity of design.. I want to write a very simple project in Spring (3.1) that takes an email address and puts it into a databa

I'm new to Spring MVC and want to ask a very simple question about simplicity of design..

I want to write a very simple project in Spring (3.1) that takes an email address and puts it into a database and if the email address is valid and shows a "thankyou" pages (incorrect email redirects back to initial page showing the email-failure).

The question: Based on this very simple user case - what view technology would you use? I was thinking tiles but thinking this开发者_StackOverflow社区 is overkill? Also - I plan to have a controller that simply writes the value to the DB using the JDBC template (no service tier)...

PS - want to use the Spring MVC for this (and not another framework - e.g. grails)..


For your simple case you don't need any view technology except plain HTML... The form (input.html) simply does a POST to your controller and the controller forwards to the thankyou.html page or back to input.html. To add failure message you might use request parameters and simple JavaScript to add the error message on the client side.

In the controller you make the decision be returning different values and so called view resolver will render the appropriate view. For the future you will of course need some view technology. I worked with JSP, Freemarker and Velocity in Spring MVC - no problems encountered.

P.S.: Spring MVC is a framework. Curiously enough, Grails is built on top of it...


Depends what are your goals? Just to quick finish the application or learn more about web application development using Spring Framework.

In case you just want to get fast results go with JDBC Template.

Make Data Manager with Transactional methods and implement saving and retrieving data to Database. Inject Datamanager in Controller. Now you can put your logic inside Controller and bypass creating Service Layer.

Always you can achieve simple tasks like this using simple form submission with very little usage of php.

If you are not familiar with Spring, there are plenty of maven archetypes that will help to start your project (http://docs.codehaus.org/display/MAVENUSER/Archetypes+List)


I prefer use standard JSP for a view, Hibernate Validator (as JSR303 implementation) for email validation and Hibernate (as JPA implementation) for saving data to database. (Why JPA? Because I can set it up faster than other technologies.)

P.S. And of cause Maven for managing dependencies!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号