79343815

Date: 2025-01-09 19:34:40
Score: 1
Natty:
Report link

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");
    }

}
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Kireeti Nunna