java—有没有任何方法可以使用SpringBootRest控制器返回html页面作为响应?

ki0zmccv  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(396)

我得到一个成功的字符串作为回应。
请提供答案,仅供参考 @RestController .

@RestController    
// here is method call. verify_success,verify_fail are html pages 
@PreAuthorize("permitAll()")
@Operation(summary = "email_Verification", tags = { "auth" })
@RequestMapping(value = "/verify", method = RequestMethod.GET)
public String verifyUser(@Param("code") String code) {
    if (emailService.verify(code)) {
        return "verify_success";
        //i want html response instead of string 
    } else {
        return "verify_fail";
        //i want html response instead of string 
    }
}
izj3ouym

izj3ouym1#

@Controller
public class ControllerClass {

@PreAuthorize("permitAll()")
@Operation(summary = "email_Verification", tags = { "auth" })
@RequestMapping(value = "/verify", method = RequestMethod.GET)
public ModelAndView verifyUser() {
     if (emailService.verify(code)) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("verify_success.html");
        return modelAndView;
            } else {
ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("verify_fail.html");
        return modelAndView;
            }

    }
}## replace rest controler with controler ##

相关问题