基于SpringBoot从零构建博客网站 - 技术选型和整合开发环境
技术选型和整合开发环境
1、技术选型
博客网站是基于SpringBoot整合其它模块而开发的,那么每个模块选择的技术如下:
- SpringBoot版本选择目前较新的2.1.1.RELEASE版本
- 持久化框架选择Mybatis
- 页面模板引擎选择Freemarker
- 前台框架选择Bootstrap
- 后台框架选择AdminLTE
- 数据库选择Mysql
- 数据库版本管理选择Flyway
技术选型概览图,如下:

2、代码分包
首先确定本工程为sw-blog(即:守望博客),基础包名为:
com.swnote
通过前面同系列的两篇文章可知,本博客网站主要分成3个模块,即用户管理及权限相关模块、文章及专栏等博文相关模块和公共模块。为此这3个模块分别所属的包为auth、blog和common,即:
com.swnote.auth
com.swnote.blog
com.swnote.common
然后每个模块下都是有本模块的controller、service、dao和domain,所以本工程包的结构如下:

3、整合开发环境
根据前面所确定的技术,那么工程的pom文件内容如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.swnote</groupId>
<artifactId>sw-blog</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>sw-blog</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</project>
application.yml的配置内容如下:
spring:
application:
name: swblog
datasource:
url: ${SWBLOG_DB_URL:jdbc:mysql://localhost:3306/swblog?characterEncoding=utf8}
username: ${SWBLOG_DB_USERNAME:root}
password: ${SWBLOG_DB_PWD:12345678}
driver-class-name: com.mysql.cj.jdbc.Driver
flyway:
clean-disabled: true
enabled: true
locations: classpath:db/migration
baseline-on-migrate: true
freemarker:
suffix: .ftl
content-type: text/html
charset: UTF-8
cache: false
template-loader-path:
- classpath:/templates
mvc:
static-path-pattern: /static/**
server:
port: ${SWBLOG_PORT:80}
mybatis:
mapper-locations: classpath:com/swnote/*/dao/*.xml
type-aliases-package: com.swnote.auth.domain,com.swnote.blog.domain,com.swnote.common.domain
其中配置主要数据库的配置、flyway的配置、freemarker的配置和mybatis的配置,同时还设置4个以“SWBLOG_”开头环境变量,为后期注入值用的,如果还需要有其它的环境变量后期也会慢慢的加。
4、测试
为了检测开发环境是否正确,为此测试从数据库中获取一条数据,然后将数据传递到页面上显示。
利用comm_config表测试,首先往该表中插入一条记录,即:

Dao的Mapper文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.swnote.common.dao.ConfigDao">
<sql id="fields">
configId, configValue, description
</sql>
<!-- 根据主键获取配置信息 -->
<select id="retrieve" parameterType="String" resultType="Config">
select <include refid="fields"/> from comm_config where configId = #{configId}
</select>
</mapper>
Service层代码:
package com.swnote.common.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.swnote.common.dao.ConfigDao;
import com.swnote.common.domain.Config;
import com.swnote.common.service.IConfigService;
/**
* 站点相关配置信息服务类
*
* @author lzj
* @since 1.0
* @date [2019-04-04]
*/
@Transactional
@Service
public class ConfigService implements IConfigService {
@Autowired
private ConfigDao configDao;
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Override
public Config retrieve(String configId) {
return configDao.retrieve(configId);
}
}
Controller层的测试代码:
package com.swnote.common.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.swnote.common.domain.Config;
import com.swnote.common.service.IConfigService;
@Controller
@RequestMapping("/test")
public class TestController {
@Autowired
private IConfigService configService;
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String test(ModelMap model) {
Config config = configService.retrieve("name");
model.addAttribute("config", config);
return "test";
}
}
页面代码:
<!doctype html>
<html>
<head>
<title>测试</title>
<meta charset="utf-8">
</head>
<body>
<h2>${config.configValue}</h2>
</body>
</html>
启动工程后,访问:http://127.0.0.1/test/index,结果如下:

结果是正确的,所以开发环境整合完成了。
关注我
以你最方便的方式关注我:
微信公众号:

基于SpringBoot从零构建博客网站 - 技术选型和整合开发环境的更多相关文章
- 基于SpringBoot从零构建博客网站 - 整合lombok和mybatis-plus提高开发效率
在上一章节中<技术选型和整合开发环境>,确定了开发的技术,但是如果直接这样用的话,可能开发效率会不高,为了提高开发的效率,这里再整合lombok和mybatis-plus两个组件. 1.l ...
- 基于SpringBoot从零构建博客网站 - 确定需求和表结构
要确定一个系统的需求,首先需要明确该系统的用户有哪些,然后针对每一类用户,确定其需求.对于博客网站来说,用户有3大类,分别是: 作者,也即是注册用户 游客,也即非注册用户 管理员,网站维护人员 那么从 ...
- 基于SpringBoot从零构建博客网站 - 新增创建、修改、删除专栏功能
守望博客是支持创建专栏的功能,即可以将一系列相关的文章归档到专栏中,方便用户管理和查阅文章.这里主要讲解专栏的创建.修改和删除功能,至于专栏还涉及其它的功能,例如关注专栏等后续会穿插着介绍. 1.创建 ...
- 基于SpringBoot从零构建博客网站 - 设计可扩展上传模块和开发修改头像密码功能
上传模块在web开发中是很常见的功能也是很重要的功能,在web应用中需要上传的可以是图片.pdf.压缩包等其它类型的文件,同时对于图片可能需要回显,对于其它文件要能够支持下载等.在守望博客系统中对于上 ...
- 基于SpringBoot从零构建博客网站 - 集成editor.md开发发布文章功能
发布文章功能里面最重要的就是需要集成富文本编辑器,目前富文本编辑器有很多,例如ueditor,CKEditor.editor.md等.这里守望博客里面是集成的editor.md,因为editor.md ...
- 基于SpringBoot从零构建博客网站 - 开发设置主页标识和修改个人信息功能
由于守望博客系统中支持由用户自己设置个人主页的URL的后半段,所以必须要用户设置该标识的功能,而且是用户注册登录之后自动弹出的页面,如果用户没有设置该标识,其它的操作是不能够操作的,同时要求主页标识只 ...
- 基于SpringBoot从零构建博客网站 - 开发文章详情页面
文章详情页面是博客系统中最为重要的页面,登录用户与游客都可以浏览文章详情页面,只不过只有登录用户才能进行其它的一些操作,比如评论.点赞和收藏等等. 本次的开发任务只是将文章详情页面展示出来,至于一些收 ...
- 基于SpringBoot从零构建博客网站 - 整合ehcache和开发注册登录功能
对于程序中一些字典信息.配置信息应该在程序启动时加载到缓存中,用时先到缓存中取,如果没有命中,再到数据库中获取同时放到缓存中,这样做可以减轻数据库层的压力.目前暂时先整合ehcache缓存,同时预留了 ...
- 基于SpringBoot从零构建博客网站 - 分页显示文章列表功能
显示文章列表一般都是采用分页显示,比如每页10篇文章显示.这样就不用每次就将所有的文章查询出来,而且当文章数量特别多的时候,如果一次性查询出来很容易出现OOM异常. 后台的分页插件采用的是mybati ...
随机推荐
- Web安全工具大汇聚
http://www.owasp.org/index.PHP/Phoenix/Tools http://sebug.net/paper/other/Web安全工具大汇聚.txt =========== ...
- how to select checkbox on cli environment?
generally , u can focus on this checkbox and press blank key Ok,that's shit.
- Android layout_margin 无效的解决办法
http://www.aichengxu.com/view/31025 1.如果LinearLayout中使用Android:layout_marginRight不起作用,通过测试原来在android ...
- RabbitMQ Linux(Redhat6.5)安装(二 )
一.安装erlang 由于RabbitMq的linux运行环境需要erlang环境,所以需要先安装erlang: 1.erlang下载: http://erlang.org/download/(我下载 ...
- Lintcode401 Kth Smallest Number in Sorted Matrix solution 题解
[题目描述] Find the kth smallest number in at row and column sorted matrix. 在一个排序矩阵中找从小到大的第 k 个整数. 排序矩阵的 ...
- oracle 触发器,当一个表更新或插入时将数据同步至另个库中的某个表中
有两个表分别是 A用户下的 T_SRC_WEATHER_TSPG字段如图, B用户下的t_src_weather 表,如图: 要求,当A用户下的T_SRC_WEATHER_TSPG表有插入或者更新数据 ...
- 如何更好的编写async函数
2018年已经到了5月份,node的4.x版本也已经停止了维护 我司的某个服务也已经切到了8.x,目前正在做koa2.x的迁移 将之前的generator全部替换为async 但是,在替换的过程中,发 ...
- 在C++98基础上学习C++11新特性
自己一直用的是C++98规范来编程,对于C++11只闻其名却没用过其特性.近期因为工作的需要,需要掌握C++11的一些特性,所以查阅了一些C++11资料.因为自己有C++98的基础,所以从C++98过 ...
- keystonejs开发中解决bug--版本要对应
今天要调试bug,先说明一下背景!有需求要修改keystonejs的后台管理页面,然后是看官方文档知道后台管理也是react+redux.然后为了加强后台管理页的功能(如汉化),然后将keystone ...
- mac下nginx安装
一.安装 Nginx 终端执行: brew search nginx brew install nginx 当前版本 1.10.2,通过brew可以把nginx需要的pcre,openssl,zlib ...