1.@Controller+RequestMapping+GetMapping

@Controller返回的是页面

package com.exa.de.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ViewController {
    public static final String PAGE ="view";
//本来是“view.html”如果要用“view”则要在application.properties中加入(
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html
)


    @RequestMapping("/view")//url://http://localhost:8080/view
    public String view(){

        return PAGE;
    }
    @RequestMapping("/data")//url://http://localhost:8080/data
    public ModelAndView dats(){//它既能返回视图(html页面),还能携带该html页面所需要的数据. 它既能返回视图(html页面),还能携带该html页面所需要的数据.

        ModelAndView view = new ModelAndView(PAGE);
        view.addObject ("str1","我叫霖、");//在容器view中对象中添加对象
view.addObject ("str2","我是张三");

        return view;
    }
}

 

2.application.properties:
  spring.mvc.view.prefix=/
  spring.mvc.view.suffix=.heml

 


3.引入freemarker,,,在
<dependencies></dependencies>之间
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

 

4.application.properties中配置freemarker相关配置:
spring.freemarker.suffix=.html
spring.freemarker.template-loader-path=classpath:/static/

 

 
 
posted on 2022-04-26 00:05  阿霖找BUG  阅读(157)  评论(0)    收藏  举报