Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Creating Controllers and Views Serve a Thymeleaf View from a Controller

Request Mapping with Index

Continuing our previous contact manager application, take a look at ContactController.java. Notice that currently it's returning a string as the response body. Change that controller method so that instead it serves a view named "index".

I don't feel as though this was addressed at all in the previous video. I'm not really sure what I am supposed to do other than what I've written.

Thank you for any help!

com/teamtreehouse/contactmgr/controller/ContactController.java
package com.teamtreehouse.contactmgr.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ContactController {
    @RequestMapping("/index")
    @ResponseBody
    public String index() {
      return "Hello, Contact Manager!";
    }
}

1 Answer

Isaiah Duncan
Isaiah Duncan
3,241 Points

Remove this line:

@ResponseBody

And change this line:

return "Hello, Contact Manager!";

To:

return "index";

The @ResponseBody is used if you are not processing the request any further and just want to return something (a String in this case) back to the browser.