Thank you guys, I got it solved. Instead of using the return type as string i have used ModelAndView and it got fixed.
package com.learning.SpringBootWeb;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HomeController {
@RequestMapping("/")
public ModelAndView home()
{
return new ModelAndView( "index");
}
@RequestMapping("/add")
public ModelAndView add(@RequestParam("input1") int num1, @RequestParam("input2") int num2, Model model) {
int result = num1+num2;
model.addAttribute("result", result);
return new ModelAndView("result");
}
}