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

网站建设字体阿里云 网站建设方案书

网站建设字体,阿里云 网站建设方案书,中国百强县市榜单,大宅装修spring boot项目增加 html web页面访问 1. 首先 application.properties 文件中增加配置,指定静态资源目录(包括html的存放) spring.resources.static-locationsclasspath:/webapp/,classpath:/webapp/static/ 2. 项目目录 3. 如果有实现 …

spring boot项目增加 html web页面访问

1. 首先 application.properties 文件中增加配置,指定静态资源目录(包括html的存放)

spring.resources.static-locations=classpath:/webapp/,classpath:/webapp/static/

2. 项目目录

3. 如果有实现 WebMvcConfigurer  类的,增加实现

package yourpack;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import javax.annotation.Resource;/*** @author wangtong*/
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {@Autowiredprivate YourInterceptor yourint;// 拦截器@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(yourint).addPathPatterns("/url").addPathPatterns("/url2");// 不设置拦截器的可以不实现该方法}@Overridepublic void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setStatusCode(HttpStatus.OK);registry.addViewController("/index.jsp").setViewName("index"); // 配置首页registry.addViewController("/").setViewName("index");registry.addViewController("/404").setViewName("404"); // 配置404页面}@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {
// 设置静态资源目录registry.addResourceHandler("/static/**").addResourceLocations("classpath:/webapp/static/").addResourceLocations("classpath:/resources/webapp/static/");}
}

如果访问不到页面的,可以检查下application配置文件是否有以下配置

#spring.web.resources.add-mappings=false
#spring.resources.add-mappings=false

如果有的话,需要进行注释。这两个配置都是不进行静态资源的映射。所以会导致html等无法访问。

增加spring boot web不存在的url返回200状态码

1. application配置文件增加以下配置

spring.mvc.throw-exception-if-no-handler-found=true

2. 增加一个error配置类的实现

package ;import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;@Configuration
public class ErrorConfig implements ErrorPageRegistrar {@Overridepublic void registerErrorPages(ErrorPageRegistry registry) {ErrorPage[] errorPages = new ErrorPage[1];errorPages[0] = new ErrorPage(HttpStatus.NOT_FOUND, "/404.do");registry.addErrorPages(errorPages);}
}

3. 增加一个mapping

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;@RequestMapping(value = {"/404.do"})public ResponseEntity<Map<String, String>> error() {Map<String, String> retMap = new HashMap<>();retMap.put("message", "请求路径不存在");return new ResponseEntity<Map<String, String>> (retMap, HttpStatus.OK);}

访问一下

vue 打包配置:

1. main.js 配置 axios相关,这里没有进行增加前缀路由,注释调的api是增加的,但是打包后,访问的页面里面也加上了,不知道为什么,所有就去掉吧

// var baseURL = '/api';
var baseURL = 'http://localhost:8080';
axios.interceptors.request.use(config=>{config.baseURL= baseURL;config.headers.post["Origin"] = baseURL;config.headers.post["Referer"] = baseURL;return config;
});
axios.defaults.withCredentials = true;
axios.defaults.headers.post["Origin"] = baseURL;
axios.defaults.headers.post["Referer"] = baseURL;Vue.prototype.$request=axios;

2. package.json 文件, scripts 中没有build的可以增加一个,如果执行 npm run build 报错的,可以改成build+后缀的其它。 我这里的话 npm run buildt

{"name": "vue-admin-template","version": "4.4.0","description": "A vue admin template with Element UI & axios & iconfont & permission control & lint","author": "","scripts": {"dev": "vue-cli-service serve","build:prod": "vue-cli-service build","buildt": "npm install && vue-cli-service build","preview": "node build/index.js --preview","svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml","lint": "eslint --ext .js,.vue src","test:unit": "jest --clearCache && vue-cli-service test:unit","test:ci": "npm run lint && npm run test:unit"},

3. vue.config.js文件

module.exports = {publicPath: '/',outputDir: '../your-web/src/main/resources/webapp',assetsDir: 'static',lintOnSave: process.env.NODE_ENV === 'development',productionSourceMap: false,devServer: {port: 2234,open: true,overlay: {warnings: false,errors: true},// proxy: { //   '/api': { //     target: 'http://localhost:8080',//     ws: true,//     changeOrigin: true ,//     pathRewrite:{//       '^/api':''//     }//   } // }},

这里的话,axios没有设置前缀,所以这里的路由也就不需要了。注释掉。

outputDir  要输出的目录路径,这里的话,我这里打包的不在当前这个目录下面。

生成到和当前node父目录同层的指定目录下。

http://www.yayakq.cn/news/560226/

相关文章:

  • 佛山响应式网站建设wordpress 静态页面显示文章
  • 商标查询网站怎么做要建立网站是否要先做网页设计_然后把网页设计与数据库连接起来?
  • 什么网站可以做公共基础知识网站后台登陆密码忘记了
  • 乐从网站制作wordpress修改文件上传大小
  • 做网站网页排版错误中国广东网站建设
  • 怎么管理网站公司网页建立
  • 自己做网站需要多少资金外贸自建站多少钱一个
  • 化妆品网站方案哪个网站能学做微商
  • 小网站下载渠道有哪些dw个人网页制作代码
  • 免费做app的网站有吗卡盟网站顶图怎么做
  • 网上商城建设 网站定制开发怎么创建私人网站
  • 软件网站建设基本流程wordpress获取首页id
  • 中国建设工程鲁班奖查询网站携程网站建设项目
  • 用asp.net做后台网站seo快速优化方法
  • 浅谈马云电子商务网站建设关于网站建设需要的研究方法
  • 网站制作公司哪家好一点wordpress 中文 图片不显示
  • 网站信用认证可以自己做吗营销型网站一个多少钱
  • 《网站建设 补充合同wordpress增加左侧悬浮菜单
  • 局域网内建设网站十大家居家装网站哪个好
  • 做php网站用的软件重庆刚刚发布
  • 做网站免责声明重庆做网站建设
  • 易语言可以做网站管理系统吗建筑模板哪种好
  • 做视频素材网站佛山+客户端官网
  • 西安做兼职网站加强宣传阵地建设 高校 网站
  • 上饶市建设局官方网站深圳网站开发哪些
  • 大型网站维护费一年多少jplayer wordpress
  • 营口网站建设哪家好网页作品展示
  • 优秀网站设计赏析wordpress自定义简码
  • 免费建设展示网站济南网站建设599
  • 做窗帘店的网站网站建设 空间选择