0%

问题

今天发现对产品业务不够了解的债,要还了。〒▽〒
做的工具对后面一个系统来说是没问题的,但是到再后面的系统,问题就放大了。

小结

详细的了解别的产品业务也是很有必要的,免得后期做好了再还债。

步骤一

新建一个页面,命名为 tags 。命令如下:

1
$ hexo new page "tags"

步骤二

编辑刚新建的页面,将页面的类型设置为 tags ,主题将自动为这个页面显示标签云。页面内容如下:

1
2
3
4
title: tags
date: 2017-11-6 22:19:52
type: "tags"
---

注意:如果有启用多说 或者 Disqus 评论,默认页面也会带有评论。需要关闭的话,请添加字段 comments 并将值设置为 false,如:

1
2
3
4
5
title: tags
date: 2017-11-6 22:19:52
type: "tags"
comments: false
---

步骤三

在菜单中添加链接。编辑NexT的配置文件 ,添加 tags 到 menu 中,如下:

1
2
3
4
5
6
menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive

添加 分类 categories

1
$ hexo new page "categories"
1
2
3
4
5
6
---
title: categories
date: 2017-11-06 22:07:29
type: "categories"
comments: false
---

备注

如果页面显示不正常,一般都是有地方拼写错了,或者需要清理浏览器缓存

框架/工具 关键字

Maven SpringBoot Myatis MySQL Tomcat IDEA

部分操作

  1. 新建父工程,New > Project > Maven,不使用原型(不勾选Create from archetype) -> 填写项目信息(GroupID:项目组织唯一标识,ArtifactID:项目唯一标识)

  2. 删除父工程下src目录

  3. 右键项目,新建子模块(New -> Module),填写项目名称,其他默认即可
    |–> 非web模块,不使用原型新建Maven模块
    |–> web模块
    |-> 使用maven-archetype-webapp构建
    |-> Spring Initializr构建Spring相关项目

新建模块:
新建模块

简单MVC项目结构如下所示:
项目结构

  1. 在各个子模块的pom文件中添加互相的依赖(父工程在前一步自动添加了对应的子模块<modules>

模块依赖

  1. 添加依赖到父工程的pom中(Spring Initializr构建web模块的,把web模块的pom.xml中的依赖改到父工程)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

然后在父工程pom.xml后添加下面内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<build>
<plugins>
<plugin>
<!-- The plugin rewrites your manifest -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.8.RELEASE</version>
<configuration><!-- 指定该Main Class为全局的唯一入口 -->
<mainClass>com.like.DemoWebApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
<!--可以生成不含依赖包的不可执行Jar包-->
<!-- configuration>
<classifier>exec</classifier>
</configuration> -->
</execution>
</executions>
</plugin>
</plugins>
</build>

web模块pom.xml添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<build>
<!-- 为jar包取名 -->
<finalName>demo-start</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
  1. 右键父项目 > Open Module Settings进入Project Structure > 子模块 > Dependencies > + > Module Dependency,添加子模块需要引用的其他子模块

  2. maven打包

  3. 配置启动设置,配置为启动web子模块的配置即可

模块依赖

记录

  1. maven统一打包命令(跳过测试)

    1
    mvn package —Dmaven.test.skip=true
  2. 编译/打包报错程序包xxx.xxx.xxx不存在,尝试

    1
    mvn clean
  3. 子模块间的引用要写在各自的pom文件里的 <dependencies>中,父工程配置<modules>即可

  4. 引用的jar包写在父工程pom的 <dependencies>

虽然现在不在用Java开发,但是决定了解一下Java Web开发在用的比较新的东西
在这记录一下,SpringBoot搭建一个小型项目框架

工具清单

JDK IDEA MySQL

框架工具组成

SpringBoot + Mybatis + Thymeleaf + Maven

搭建过程

  1. 新建工程 -> 选择Spring Initializr -> 选好JDK -> 填好项目信息
  2. 选择要集成的框架,这里选基本的SpringBoot项目需要的
    Web -> Web
    Template Engines -> Thymeleaf
    SQL -> MyBatis JDBC MySQL
  3. IDEA搭建好基本框架,Maven添加依赖包
  4. 删除application.properties,新建application.ymlapplication-dev.ymlapplication-prod.yml,分别作为主配置、开发配置、生成配置文件
    application.yml:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    spring:
    thymeleaf:
    mode: HTML5
    encoding: utf-8
    content-type: text/html
    cache: false
    profiles:
    active: dev # 表示使用application-dev.yml
    datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8
    username: root
    password:
    tomcat:
    initialSize: 1
    min-idle: 1
    max-idle: 20
    max-wait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 30000
    validationQuery: SELECT 1
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    logging:
    file: logs/demo.log

application-dev.yml:

1
2
server:
port: 8080

application-prod.yml:

1
2
3
4
5
6
7
server:
port: 443
ssl:
key-store: classpath:xxx.jks
key-store-password: xxx
keyStoreType: JKS
keyAlias: xxx

  1. 然后按照我的SpringBootDemo仓库来建controller什么的,就好了。
  2. 好吧,前面好多别人写了很多遍的东西,需要的话看我参考的博客就好了。
    Thymeleaf之前只撇过几眼,好像跟JSTL有点像,就没注意

Thymeleaf它是一个XML/XHTML/HTML5模板引擎,使用各种包含th:*属性的标签,格式其实和HTML有点不一样,head、body什么的都不一样。

Thymeleaf的url,因为模板里好像不能用&符号,需要&amp;替换,但是官方有对应的标签的

1
2
<!-- <a href="/test?id=1&name=2">a</a> -->
<a th:href="@{/test(id=1, name=2)}">a</a>

  1. 配置启动设置,添加SpringBoot启动配置,集成了Tomcat的,不用想SpringMVC等等以前的配置Tomcat的配置,Main class就是XxxApplication,选上Use classpath of moduleJRE,就可以启动了。
  2. 为了开发看起来舒服点,在Project StructureModules中设置一下对应文件目录作用,设置一下Main class为Spirng配置文件

小结:

框架用起来越来越简单了,但是框架解决的还是那些问题,只是省去了很多复杂的配置,写东西越来越简便,让我这样的“搬砖工”,写逻辑什么的更专注一点吧,或许有一天AI可以写逻辑了,大概就失业了:)

重装折腾win7,没关闭更新,更新100+补丁还失败还原,各种dll丢失。报错大致如下:

D3DCompiler_47.dll、api-ms-win-core-libraryloader-l1-2-1.dll、gfx.dll……丢失

启动Word2016、SS和MSSQL Server MS的时候(依赖都比较新的软件)报错,缺少net46。报错大致如下:

“的类型初始值设定项引发异常
缺少”.Net Framework 4.6”

原因:
D3DCompiler_47.dll丢失,因为更新补丁失败还原的缘故
其他的是卸载了或者本来就缺新的.Net Framework

解决方法:

  1. 打补丁Windows6.1-KB4019990-x64.msu,应该是补上D3DCompiler_47.dll一系列的库的。
    Win32Exception (0x80004005): 找不到指定的模块

  2. 重装电脑里版本需要的.Net框架,打完补丁就可以装了,一般运行的话装个比较高版本的就好,我装的是.Net Framework4.7,会修复版本.Net框架“缺少”之类的问题。

注:.Net Fx出现无法安装之类的问题见本文最后
以上。结果弄了好几天。(╯‵□′)╯︵┻━┻

插曲1 2017-11-2 15:00:26

今天本来以为已经搞定了,结果发现VS2015里没有.Net Framework 4.5,于是又开始折腾。。。目前更糟糕了,VS起不来了,报没有.Net Fx4.6,然而卸载程序里面明明有的。
未完待续,好烦。

插曲2 2017-11-2 16:49:13

  • 首先,卸载明明安装着的.Net Fx 4.6是不明智的
  • 其次,修复VS更是浪费青春
  • 然后,重装电脑里最新的.Net Fx,我的是4.7,然后4.6的问题就解决了。
    但是并不能解决.Net Fx 4.5没有的问题,正在去官网下载4.5.2的Dev-Pack,328M,感觉装完有应该就会有4.5了
  • 最后,吐槽一下,公司网真烂,太烂了,下载页好久才打开,加上电脑也烂,不然早弄好了

插曲终 2017-11-3 14:03:10

问题原因:
本机上有 net45 的文件没删干净,所以安装不了,但是肯定缺少文件了
解决办法:
.net framework 的安装目录在 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5
清理干净,或者直接从其他电脑拷一份过来就好了。

完结撒花。

C#中预编译SQL方法如下:

1
2
// System.Data.Entity.Database
int ExecuteSqlCommand(string sql, params object[] parameters);

使用EF6框架,仓库使用生成的数据库上下文:

1
private EFDbContext dbctx = new EFDbContext();

使用示例:

1
2
3
4
5
// 删除tableA中,name以"$"结尾的数据
string sql = "DELETE FROM tableA WHRER name like \"%@sign\"";
int result = dbctx.Database.ExecuteSqlCommand(sql,
new SqlParameter("sign", "$")
);

查询方法,如下:

1
2
3
4
5
6
7
8
var parameters = new SqlParameter[] {
new SqlParameter("name", name),
new SqlParameter("age", age)
};

string sql = $"select * from user where name = @name and age = @age";

var l = db.Database.SqlQuery<User>(sql, parameters).ToList();

这两天稍微有点时间,简单看了看设计模式,感觉比上次理解多了,或许是要自己实际解决的问题更多了吧。

除了工厂模式、单例模式、MVC模式等等很经常使用的模式以外,享元、适配器等等各种模式也都有了自己理解的应用场景,我想,下次再看应该会更有感触吧。

回想很多大学里学的知识,也都是慢慢的觉得很有用处,当然这里也没有得后悔当初为什么没有好好学了,只能叹息有时间再补吧。

设置记录

sublime.setting-user

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"color_scheme": "Packages/Theme - Afterglow/Afterglow-markdown.tmTheme",
"expand_tabs_on_save": true,
"font_size": 13,
"ignored_packages":
[
"Markdown",
"Vintage"
],
"tab": 2,
"translate_tabs_to_spaces": true,
"default_encoding": "UTF-8",
"update_check": false
}

无论是用Sublime写前端,还是写Markdown,经常要用到终端,每次Win+R再cmd也是麻烦

  1. Package Control -> Terminal

  2. 设置Setting-Default,就是有"termainal":这个参数的设置文件,改成下面设置,即可Ctrl+Alt+T启动普通cmd了(不改的话,默认为启动Power Shell)

    1
    2
    3
    4
    5
    {
    // Replace with your own path to cmder.exe
    "terminal": "cmd",
    "parameters": ["/START", "%CWD%"]
    }

Sublime插件-Terminal的Github