2021年2月16日
使用 Node 运行 ES6 模块 由于 Node 的模块组织方式和 ES6 的模块组织方式不同,因此 ES6 的模块导入和导出语法在 Node 命令行程序执行下会报错 另外,某些 ES6 关键字的用法亦不兼容,因此需要使用 Babel 进行转换后执行 比如: 有个 ES6 写的 logger.js 直接上代码: const Level = { DEBUG: 1, INFO: 2, ERROR: 3, NONE: 4, }; class Logger { constructor(level) { this.level = level || Level.INFO; } } // 执行默认构造行数并打印 const……
阅读全文
2021年2月16日
使用 parcel 的 watch 整合单页应用和 JAVA WEB 由于通常情况下使用 NODE 进行前端开发时,会启动相应的应用服务器。而使用 JAVA WEB 开发时也有相应的应用服务器要启动。这在本机开发时要通过 Proxy 的方式进行整合。 如果不需要那么多麻烦的整合就好了,本着能省就省的方式。既然 JAVA WEB 的应用服务器必须要启用,那可否直接利用 JAVA 的应用服……
阅读全文
2021年1月25日
非 WEB 环境下运行 SpringBootApplication 前言 有时候一些项目并不需要提供 Web 服务,例如跑定时任务的项目等。因为启动一个 Tomcat 这样的 WEB 服务器容器也比较消耗资源,浪费内存及算力。 非 WEB 项目可以修改 maven 依赖为: <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> </dependencies> 当然,不修改也是没有问题的,可以仍旧依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 首次尝试 不过 SpringBoot 的启动类的 main 方法需要做一些改变 package com.sample.api; import……
阅读全文
2021年1月24日
使用 mvn 进行 springboot 2.2.5+mybatis-plus 3.3 开发 使用 https://start.spring.io 生成新项目框架 数据源配置 /resources/application.properties spring.datasource.username=root spring.datasource.password= spring.datasource.url = jdbc:mysql://127.0.0.1:3306/hotel spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver spring.datasource.type = com.zaxxer.hikari.HikariDataSource 主启动文件 import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication @EnableTransactionManagement @EnableCaching @MapperScan("com.localhost.mapper") public class ApiApplication { public static void main(String[] args) { SpringApplication.run(ApiApplication.class, args); } } 当启动时报错如下时 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 原因是标准的 mvn 项目不会将位于 src/main/java 下的 Mapper.xml 文件进行编译,即在 target/classes 下无法找到对应的 Mapper.xml 文件,因此请将 mvn 的 pom.xml 增加如下内容 <build> <resources>……
阅读全文
2021年1月23日
整合 spring-boot 和 mybatis-plus 进行 Api 开发 使用 idea 社区版作为开发工具,gradle 作为构建工具 主要配置: 首先使用 SpringBoot 初始化项目进行项目模版配置,选择 web ,mysql,lombok 即可 build.gradle 配置 plugins { id 'org.springframework.boot' version '2.1.6.RELEASE' id 'java' id 'war' } apply plugin: 'io.spring.dependency-management' group = 'io.github.joy.fxz' version = '0.0.2' sourceCompatibility = '1.8' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' // 无需添加mybatis的依赖,防止与mybatis-plus整合的版本不一致 implementation 'com.baomidou:mybatis-plus-boot-starter:3.1.2'……
阅读全文
2021年1月21日
使用 junit 对 springboot 应用进行单元测试 使用 springboot 2.2.5 开发 web 应用的时候,需要进行单元测试。 普通的 java 的单元测试比较简单,对于采用 REST 方式开发的微服务,则需要使用 WEB 环境进行测试。 示例代码如下: package com.sample.api; import com.sample.api.controller.TestController; import com.sample.api.entity.User; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class TestControllerTest { @Resource private TestRestTemplate restTemplate; @Test public void test(){ User user = restTemplate.getForObject("/users/abc", User.class); System.out.println(user); Assert.assertNotNull(user); Assert.assertEquals("abc", user.getUsername()); } } 需要注意的是对于 SpringBoot 里……
阅读全文
2021年1月12日
Vue 单页项目发布到 Nginx 独立目录 Nginx 配置 对于 Nginx 的配置与原来 Nginx 和 Tomcat 搭配配置完全一样,无需任何改动。例如: server { listen 80; # listen somename:8080; charset utf-8; server_name localhost; gzip on; location / { proxy_pass http://localhost:8080/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header ABCXYZ-REAL-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Nginx-Proxy true; proxy_set_header Connection ""; #limit_req zone=limitdashi burst=5 nodelay; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } 通过这样一个代理将请求转发给后端的 Tomcat 服务器 目录说明 现有使用 Vue 3.3 生成的 VuePro……
阅读全文
2021年1月11日
VSCode 如何避免 es6 import {} 自动换行 import { Message } from "element-ui"; // 格式化后立马变成下面这样,丑死了 import { Message } from "element-ui"; 其实只要设置 VsCode 的设置即可。 在 MacBook Pro 下: Code -> 首选项 -> 设置 然后搜索 beautify 并点击在 json 中编辑,在 json 配置文件的末尾加入如下配置即可: "beautify.config": { "brace_style": "collapse,preserve-inline" } 测试过确实可行! 问题参考链接: es6 import 格式化 GitHub issue 链接:https://git……
阅读全文
2021年1月11日
我的 .eslintrc.js 配置 module.exports = { root: true, env: { node: true, }, extends: ["plugin:vue/essential", "@vue/standard"], rules: { "no-console": process.env.NODE_ENV === "production" ? "error" : "off", "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off", semi: 0, "no-throw-literal": 0, "keyword-spacing": [ "error", { before: true, after: true, }, ], "space-before-function-paren": 0, quotes: [0, "double"], }, parserOptions: { parser: "babel-eslint", }, };……
阅读全文
2021年1月10日
Vue 开发时如何忽略 ES Lint 校验 使用.eslintignore 文件 在 Vue 工程的根目录下,打开 eslint 的忽略文件.eslintignore(若无则创建一个) 不想校验什么文件,就写进去。 假如不想校验所有的 js 文件,写上*.js 就可以了。……
阅读全文