初始化Java Angular web项目小结

仲孙飞文
2023-12-01

有时候想写个web小程序,需要用到某些以前用过的库/框架,就要打开以前的项目或者翻收藏夹好烦。现在将一些web常用的东西整理合并起来。

常用maven依赖

spring

<parent>
	<groupId>org.springframework.boot</groupId>
	 <artifactId>spring-boot-starter-parent</artifactId>
	 <version>2.1.5.RELEASE</version>
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-security</artifactId>
 </dependency>
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-data-jpa</artifactId>
 </dependency>

数据库

<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>8.0.13</version>
 </dependency>

玩具程序可以用h2db:

<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <version>1.4.200</version>
</dependency>

工具类

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.4</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.58</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.8.1</version>
</dependency>
<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.11.3</version>
</dependency>
<dependency>
    <groupId>org.antlr</groupId>
    <artifactId>antlr4</artifactId>
    <version>4.7.2</version>
</dependency>

简单GUI小程序

弹框:

JOptionPane.showMessageDialog(null, "message");

输入:

String output = JOptionPane.showInputDialog("message");

打包

<build>
	 <finalName>app-name</finalName>
	 <plugins>
	     <plugin>
	         <groupId>org.springframework.boot</groupId>
	         <artifactId>spring-boot-maven-plugin</artifactId>
	     </plugin>
	 </plugins>
</build>

用spring打包插件最少要依赖spring-boot-xxxxx,最小(没比较过)jar包用是

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

路径问题

获取jar包所在路径有好几种方式,不同打包方式使用的方法不一样,todo 待总结

String path = SettingProgram.class.getProtectionDomain().getCodeSource().getLocation().getPath();
path = URLDecoder.decode(path, "UTF-8");
path = path.substring(1, path.lastIndexOf("/"));
String path = System.getProperty("java.class.path");
path = path.substring(0, path.lastIndexOf("\\"));

yml(properties)

读取外部配置:
static静态方法使用yml配置文件的值:
yml分解成小文件:

log4j slf4j问题

启动后事件

CommandLineRunner

自定义banner

日志

npm淘宝镜像

阿里云maven仓库

 类似资料: