当前位置: 首页 > news >正文

彩票网站建设开发新发布的新闻

彩票网站建设开发,新发布的新闻,wordpress贴代码,三亚器车出行有限公司网上的文章五花八门,不写SpringBoot的版本号,导致代码拿来主义不好使了。 本文采用的版本 SpringBoot 2.7.7 Java 1.8目录1、默认访问路径2、整个项目增加路由前缀3、通过注解方式增加路由前缀4、按照目录结构添加前缀参考文章1、默认访问路径 packag…

网上的文章五花八门,不写SpringBoot的版本号,导致代码拿来主义不好使了。

本文采用的版本

SpringBoot 2.7.7
Java 1.8

目录

    • 1、默认访问路径
    • 2、整个项目增加路由前缀
    • 3、通过注解方式增加路由前缀
    • 4、按照目录结构添加前缀
    • 参考文章

1、默认访问路径

package com.example.demo.controller.api;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/api")
public class AppIndexController {@GetMapping("/index")public String index() {return "app";}
}

访问地址:http://localhost:8080/api/index

2、整个项目增加路由前缀

application.yml

server:servlet:context-path: /prefix

访问地址:http://localhost:8080/prefix/api/index

注意:该方案会将所有的路由都增加一个前缀

3、通过注解方式增加路由前缀

注解

package com.example.demo.annotation;import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;import java.lang.annotation.*;/*** controller层统一使用该注解*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RestController
public @interface ApiRestController {/*** Alias for {@link Controller#value}.*/@AliasFor(annotation = Controller.class)String value() default "";
}

配置

package com.example.demo.config;import com.example.demo.annotation.ApiRestController;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;/*** 配置统一的后台接口访问路径的前缀*/
@Configuration
public class CustomWebMvcConfig implements WebMvcConfigurer {@Overridepublic void configurePathMatch(PathMatchConfigurer configurer) {configurer.addPathPrefix("/api", c -> c.isAnnotationPresent(ApiRestController.class));}}

使用注解

package com.example.demo.controller.api;import com.example.demo.annotation.ApiRestController;
import org.springframework.web.bind.annotation.GetMapping;@ApiRestController
// @RestController
// @RequestMapping("/api")
public class AppIndexController {@GetMapping("/index")public String index() {return "app";}
}

访问地址:http://localhost:8080/api/index

4、按照目录结构添加前缀

没有成功,可能是版本的问题

Neither PathPatterns nor String patterns condition

参考文章

  • SpringBoot2.x 给Controller的RequestMapping添加统一前缀
  • SpringBoot - 根据目录结构自动生成路由前缀
http://www.dt0577.cn/news/36393.html

相关文章:

  • vue做单页面网站站长工具浪潮
  • 常州网站建设托管加盟教育培训哪个好
  • 网站如何做下拉菜单网站做成app
  • 个人博客网站建设预算网站建设的方法有哪些
  • 做网站首页ps网站seo推广员招聘
  • 国内做网站最大的公司有哪些云客网平台
  • 互动网站全球网站流量排名100
  • 有口碑的常州网站建设广告接单有什么平台
  • 无锡网站建设选众鼎网络推广培训课程内容
  • 网站制作步骤流程图推广链接点击器安卓版
  • 医院网站建设案例云资源软文发布平台
  • 美国一特级a做爰片免费网站 视频网络营销渠道有哪三类
  • 成都市房产透明网官网沈阳关键词优化费用
  • aspcms 网站统计湖北seo
  • 学网页设计与制作需要什么软件青岛seo关键词优化公司
  • 知彼网络网站建设天津seo推广
  • 新乡专业网站建设公司关键词的选取原则有
  • 免费网站香港空间下载班级优化大师并安装
  • 餐饮外哪个网站做推广市场营销策划包括哪些内容
  • 城乡建设局网站排名优化服务
  • 知名高端网站建设企业怎么样做seo
  • 移动端网站设计制作网站的友情链接是什么意思
  • .电子商务网站的开发原则包括百度收录入口提交查询
  • 如何建立网站会员系统吗网络营销制度课完整版
  • 重庆 机械有限公司 沙坪坝网站建设国际军事新闻最新消息
  • 东莞免费企业网站模板推广百度竞价排名规则及费用
  • 有代源码怎么做自己网站合肥做网络推广的公司
  • 网站建设策划方案模板发布外链
  • 怎么做盗版视频网站吗线上营销推广方案有哪些
  • 网站建设字图百度收录提交入口