Spring boot 访问template文件夹下的html

第一步:

创建html文件,格式:





Insert title here


	 点击切换语言:
    简体中文   
    English(US)

xmlns不能少,否则会显示不到该界面

第二步:

Controller类必须使用@Controller注解,不能是RestController

第三步:

控制器中return的index.html 只需要index即可,不要写.html

@org.springframework.stereotype.Controller
@RequestMapping("user")
public class Controller
{

	@Autowired
	private UserService userService;

	@RequestMapping("list")
	public String queryUserAll(String name,Model model){
		String content = userService.queryUserByName(name).toString();
		
		return "index";
	}
}

第四步/最终

application.properties中可以不用配置#spring.thymeleaf.prefix=classpath:/templates/  默认就是该文件夹下的内容

访问controller的路径即可,无需项目名字

你可能感兴趣的:(Spring,Boot)