SpringBoot十三:Web开发流程一

1、创建SpringBoot,选择Web模块,并快速编写Controller完成测试

读博客:快速搭建并测试SpringBoot环境

 

2、引入静态资源,动态资源改造页面

static放静态资源:css/img/js

templates放页面,交由模板引擎操作

读博客:静态资源映射规则

 

3、引用模板引擎

引入Thymeleaf依赖

读博客:Thymeleaf模板引擎简单使用

 

4、项目测试,由模板引擎访问到页面

启动主程序类,访问http://localhost:8080/login

说明模板引擎生效

正常开发,像这些不带数据的页面(带数据都是Controller来实现),都是由SpringMVC来控制页面跳转,下面实现此功能

扩展SpringMVC功能,创建MyMvcConfig类实现接口WebMvcConfigurer,实现方法addViewControllers

如下

package com.xue.springbootweb.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description
 * 扩展SpringMVC功能
 * @Author xuexue
 * @Date 2019/10/14 9:16
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
    }
}

同样启动测试,一样访问,结果一样。

 

5、更多流程,待完善..

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值