技术选型和整合开发环境

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从零构建博客网站 - 技术选型和整合开发环境的更多相关文章

  1. 基于SpringBoot从零构建博客网站 - 整合lombok和mybatis-plus提高开发效率

    在上一章节中<技术选型和整合开发环境>,确定了开发的技术,但是如果直接这样用的话,可能开发效率会不高,为了提高开发的效率,这里再整合lombok和mybatis-plus两个组件. 1.l ...

  2. 基于SpringBoot从零构建博客网站 - 确定需求和表结构

    要确定一个系统的需求,首先需要明确该系统的用户有哪些,然后针对每一类用户,确定其需求.对于博客网站来说,用户有3大类,分别是: 作者,也即是注册用户 游客,也即非注册用户 管理员,网站维护人员 那么从 ...

  3. 基于SpringBoot从零构建博客网站 - 新增创建、修改、删除专栏功能

    守望博客是支持创建专栏的功能,即可以将一系列相关的文章归档到专栏中,方便用户管理和查阅文章.这里主要讲解专栏的创建.修改和删除功能,至于专栏还涉及其它的功能,例如关注专栏等后续会穿插着介绍. 1.创建 ...

  4. 基于SpringBoot从零构建博客网站 - 设计可扩展上传模块和开发修改头像密码功能

    上传模块在web开发中是很常见的功能也是很重要的功能,在web应用中需要上传的可以是图片.pdf.压缩包等其它类型的文件,同时对于图片可能需要回显,对于其它文件要能够支持下载等.在守望博客系统中对于上 ...

  5. 基于SpringBoot从零构建博客网站 - 集成editor.md开发发布文章功能

    发布文章功能里面最重要的就是需要集成富文本编辑器,目前富文本编辑器有很多,例如ueditor,CKEditor.editor.md等.这里守望博客里面是集成的editor.md,因为editor.md ...

  6. 基于SpringBoot从零构建博客网站 - 开发设置主页标识和修改个人信息功能

    由于守望博客系统中支持由用户自己设置个人主页的URL的后半段,所以必须要用户设置该标识的功能,而且是用户注册登录之后自动弹出的页面,如果用户没有设置该标识,其它的操作是不能够操作的,同时要求主页标识只 ...

  7. 基于SpringBoot从零构建博客网站 - 开发文章详情页面

    文章详情页面是博客系统中最为重要的页面,登录用户与游客都可以浏览文章详情页面,只不过只有登录用户才能进行其它的一些操作,比如评论.点赞和收藏等等. 本次的开发任务只是将文章详情页面展示出来,至于一些收 ...

  8. 基于SpringBoot从零构建博客网站 - 整合ehcache和开发注册登录功能

    对于程序中一些字典信息.配置信息应该在程序启动时加载到缓存中,用时先到缓存中取,如果没有命中,再到数据库中获取同时放到缓存中,这样做可以减轻数据库层的压力.目前暂时先整合ehcache缓存,同时预留了 ...

  9. 基于SpringBoot从零构建博客网站 - 分页显示文章列表功能

    显示文章列表一般都是采用分页显示,比如每页10篇文章显示.这样就不用每次就将所有的文章查询出来,而且当文章数量特别多的时候,如果一次性查询出来很容易出现OOM异常. 后台的分页插件采用的是mybati ...

随机推荐

  1. FFPLAY的原理(六)

    显示视频 这就是我们的视频线程.现在我们看过了几乎所有的线程除了一个--记得我们调用schedule_refresh()函数吗?让我们看一下实际中是如何做的: static void schedule ...

  2. RA layer request failed

    新整的Eclipse环境出现这个问题,细化内容是不能connect,后来想起切换Eclipse底层库的事情,然后打开Eclipse的SVN设置.把SVN Client借口由JavaHL改为PureJa ...

  3. Angularjs Post传值后台收不到的原因

    如果你给AngularJS的post方法的data参数创一个key-value对象,那传给后台服务的就是JSON字符串,而正常的POST解析是需要像get?后面的那种&name=value这样 ...

  4. 解决Select标签的Option在IE浏览中display:none不生效的问题

    页面的Select标签,需要控制Select的Option不需要显示,根据条件来隐藏某些Option选项. 正常情况下使用hide()就能实现,hide()方法实际是给Option加上display属 ...

  5. 面向对象的WebAPI框架XXL-HEX

    <面向对象的WebAPI框架XXL-HEX>    一.简介 1.1 概述 XXL-HEX 是一个简单易用的WebAPI框架, 拥有 "面向对象.数据加密.跨语言" 的 ...

  6. cxf webservice生成客户端代码及调用服务端遇到的问题

    1.  从网上下载cxf开发的工具 apache-cxf-3.1.4.zip, 解压文件,找到apache-cxf-3.1.4\bin目录,里面包含一个wsdl2java文件 2. 设置环境变量 1. ...

  7. 在C++98基础上学习C++11新特性

    自己一直用的是C++98规范来编程,对于C++11只闻其名却没用过其特性.近期因为工作的需要,需要掌握C++11的一些特性,所以查阅了一些C++11资料.因为自己有C++98的基础,所以从C++98过 ...

  8. JaveScript基础(3)之正则表达式

    1.创建正则表达式的两张方法: A.var reg=/pattern/;  注意:斜杠内不能加单引号或双引号 B.vae reg=new RegExp('pattern'); 注意:括号内要用单引号括 ...

  9. Qtp自动测试工具

    QTP是基于GUI界面的自动化测试工具,用于系统的功能测试. QTP录制的是鼠标和键盘的消息.QTP录制回放时基于windows操作系统的消息机制.QTP在录制时监听应用程序的消息,监听到之后把消息放 ...

  10. 网络IO和磁盘IO详解

    1. 缓存IO 缓存I/O又被称作标准I/O,大多数文件系统的默认I/O操作都是缓存I/O.在Linux的缓存I/O机制中,数据先从磁盘复制到内核空间的缓冲区,然后从内核空间缓冲区复制到应用程序的地址 ...