Implement Index controller in Spring Roo

Written on June 28th, 2010 by Thorone shout

Recently been using Spring roo to produce a rapid prototype. I must say that Spring roo is a very good framework, although still lacking of some features but the potentials are there.

When you start a new Spring roo project, the default page will be “index.jspx”, what if we want to implement a controller to it?

First of all, locate the webmvc-config.xml in your project folder. Find and remove the following line
<mvc:view-controller path="/index"/>

Then, create a Java class file in the source folder, in my case, will be the web folder. Let’s call it IndexController

package com.justthor.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping("/")
@Controller
public class IndexController {
  @RequestMapping(value = "/index", method = RequestMethod.GET)
  public String index(ModelMap modelMap) {
          /* Implement logic here...*/
          return "index";
  }
}

That’s it. To test it, you can implement a logger in your controller. Its quite useful if we want to load some data on the index page.

Happy coding :)

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Live
  • Reddit
Filed under Uncategorized Tags:, , ,

One Comments to “Implement Index controller in Spring Roo”

Leave a Reply

(required)

(required)