Python 官方文档:入门教程 => 点击学习
目录配置项目访问路径URL的根路径1.SpringBoot在2.0之前版本2.springBoot在2.0之后版本设置默认访问路径1.继承WEBmvcConfigurerAdapte
使用server.context-path
server.context-path=/api
使用server.servlet.context-path
server.servlet.context-path=/api
一共有两种方法。
创建一个config包,然后在包内创建MyMvcConfig类。
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerReGIStry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
注意:如果用这个方法html页面需要在static下,不然会出现404错误,找不到页面。
在controller层中创建一个IndexController类
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping({"/","/index"})
public String index(){
return "index";
}
}
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: SpringBoot配置项目访问路径URL的根路径方式
本文链接: https://www.lsjlt.com/news/164013.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0