一、自定义View
package cn.edu.tju.view;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
@Component
public class MyView implements View {
@Override
public String getContentType() {
return "text/html";
}
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
response.getWriter().write("hello, world.this is my view");
}
}
二、控制器返回视图名称指向上述View文章来源:https://www.toymoban.com/news/detail-647683.html
package cn.edu.tju.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ViewController {
@RequestMapping("/view")
public String getView(){
return "myView";
}
}
BeanNameViewResolver就会把我自定义的myView这个视图解析到MyVIew这个view类。文章来源地址https://www.toymoban.com/news/detail-647683.html
到了这里,关于SpringBoot复习:(28)【前后端不分离】自定义View的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!