# myBlog **Repository Path**: zwtgit/my-blog ## Basic Information - **Project Name**: myBlog - **Description**: 由Docker + SpringBoot2.0 + Mybatis + thymeleaf + pagehelper+Druid + swagger等技术实现, 功能齐全、部署简单及完善的代码。 - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 0 - **Created**: 2021-08-24 - **Last Updated**: 2022-08-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 我的博客 由Docker + SpringBoot2.0 + Mybatis + thymeleaf 等技术实现, 功能齐全、部署简单及完善的代码。 启动成功之后访问: http://localhost:8080 访问首页 http://localhost:8080/admin 访问后台 默认账密:admin 123456 访问swagger: http://localhost:8080/swagger-ui.html # 项目架构 - JDK版本:至少1.8及以上; - springboot; - thymeleaf; - mybatis; - pagehelper; - druid; - swagger; # 效果 ![1629809065383](README.assets/1629809065383.png) ![1629809021039](README.assets/1629809021039.png) # 配置 可以设置多个环境方便开发 ## application-dev.yml ```yml server: port: 8080 spring: datasource: name: mysql_test type: com.alibaba.druid.pool.DruidDataSource #druid相关配置 druid: #监控统计拦截的filters filters: stat driver-class-name: com.mysql.jdbc.Driver #基本属性 url: jdbc:mysql://127.0.0.1:3306/lu_tale?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true username: root password: 123456 #配置初始化大小/最小/最大 initial-size: 1 min-idle: 1 max-active: 20 #获取连接等待超时时间 max-wait: 60000 #间隔多久进行一次检测,检测需要关闭的空闲连接 time-between-eviction-runs-millis: 60000 #一个连接在池中最小生存的时间 min-evictable-idle-time-millis: 300000 validation-query: SELECT 'x' test-while-idle: true test-on-borrow: false test-on-return: false #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false pool-prepared-statements: false max-pool-prepared-statement-per-connection-size: 20 thymeleaf: prefix: classpath:/templates/ check-template-location: true suffix: .html encoding: UTF-8 mode: LEGACYHTML5 cache: false aop: auto: true proxy-target-class: true servlet: multipart: max-file-size: 10Mb max-request-size: 100Mb mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: cn.luischen.model #pagehelper pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql returnPageInfo: check logging: level: cn.luischen.dao : DEBUG swagger: show: true qiniu: accesskey: "" serectkey: "" bucket: "" cdn: url: "" ``` ## application-prod.yml ```yml server: port: 443 ssl: key-store: classpath:luischen.cn.pfx key-store-password: l29df164yf5d4z key-store-type: PKCS12 spring: datasource: name: mysql_test type: com.alibaba.druid.pool.DruidDataSource #druid相关配置 druid: #监控统计拦截的filters filters: stat driver-class-name: com.mysql.jdbc.Driver #基本属性 url: jdbc:mysql://127.0.0.1:3306/lu_tale?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true username: root password: 240055 #配置初始化大小/最小/最大 initial-size: 1 min-idle: 1 max-active: 20 #获取连接等待超时时间 max-wait: 60000 #间隔多久进行一次检测,检测需要关闭的空闲连接 time-between-eviction-runs-millis: 60000 #一个连接在池中最小生存的时间 min-evictable-idle-time-millis: 300000 validation-query: SELECT 'x' test-while-idle: true test-on-borrow: false test-on-return: false #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false pool-prepared-statements: false max-pool-prepared-statement-per-connection-size: 20 thymeleaf: prefix: classpath:/templates/ check-template-location: true suffix: .html encoding: UTF-8 mode: LEGACYHTML5 cache: true aop: auto: true proxy-target-class: true servlet: multipart: max-file-size: 10Mb max-request-size: 100Mb mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: cn.luischen.model #pagehelper pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql returnPageInfo: check swagger: show: false ``` ## model层以及数据库的设计 attach ```java /** 主键编号 */ private Integer id; /** 文件名称 */ private String fname; /** 文件类型 */ private String ftype; /** 文件的地址 */ private String fkey; /** 创建人的id */ private Integer authorId; /** 创建的时间戳 */ private Integer created; ``` comments ```java /** * comment表主键 */ private Integer coid; /** * contents表主键,关联字段 */ private Integer cid; /** * 评论生成时的GMT unix时间戳 */ private Integer created; /** * 评论作者 */ private String author; /** * 评论所属用户id */ private Integer authorId; /** * 评论所属内容作者id */ private Integer ownerId; /** * 评论者邮件 */ private String mail; /** * 评论者网址 */ private String url; /** * 评论者ip地址 */ private String ip; /** * 评论者客户端 */ private String agent; /** * 评论类型 */ private String type; /** * 评论状态 */ private String status; /** * 父级评论 */ private Integer parent; /** * 评论内容 */ private String content; ``` contents ```java /** * 文章的主键编号 */ private Integer cid; /** * 内容标题 */ private String title; /** * 标题图片 */ private String titlePic; /** * 内容缩略名 */ private String slug; /** * 内容生成时的GMT unix时间戳 */ private Integer created; /** * 内容更改时的GMT unix时间戳 */ private Integer modified; /** * 内容文字 */ private String content; /** * 内容所属用户id */ private Integer authorId; /** * 内容类别 */ private String type; /** * 内容状态 */ private String status; /** * 标签列表 */ private String tags; /** * 分类列表 */ private String categories; /** * 点击次数 */ private Integer hits; /** * 内容所属评论数 */ private Integer commentsNum; /** * 是否允许评论 */ private Integer allowComment; /** * 是否允许ping */ private Integer allowPing; /** * 允许出现在聚合中 */ private Integer allowFeed; ``` logs ```java /** * 日志主键 */ private Integer id; /** * 产生的动作 */ private String action; /** * 产生的数据 */ private String data; /** * 发生人id */ private Integer authorId; /** * 日志产生的ip */ private String ip; /** * 日志创建时间 */ private Integer created; ``` metas ```java /** * 项目主键 */ private Integer mid; /** * 名称 */ private String name; /** * 项目缩略名 */ private String slug; /** * 项目类型 */ private String type; /** * 对应的文章类型 */ private String contentType; /** * 选项描述 */ private String description; /** * 项目排序 */ private Integer sort; ``` options ```java /** 名称 */ private String name; /** 内容 */ private String value; /** 备注 */ private String description; ``` relationships ```java /** * 文章主键编号 */ private Integer cid; /** * 项目编号 */ private Integer mid; ``` users ```java /** 主键编号 */ private Integer uid; /** 用户名 */ private String username; /** 密码 */ private String password; /** email */ private String email; /** 主页地址 */ private String homeUrl; /** 用户显示的名称 */ private String screenName; /** 用户注册时的GMT unix时间戳 */ private Integer created; /** 最后活动时间 */ private Integer activated; /** 上次登录最后活跃时间 */ private Integer logged; /** 用户组 */ private String groupName; ``` ## dao层 ```java @Mapper @Component public interface XXXDao { ``` 所有的都叫给Spring管理 ## service层 具体的一些细致的业务 ## controller层 **BaseController** ```java public abstract class BaseController { @Autowired private ContentService contentService; @Autowired private MetaService metaService; @Autowired private SiteService siteService; protected MapCache cache = MapCache.single(); public BaseController title(HttpServletRequest request, String title) { request.setAttribute("title", title); return this; } /** * 获取blog页面需要的公共数据 * @param request * @return */ public BaseController blogBaseData(HttpServletRequest request, ContentCond contentCond){ List links = metaService.getMetaList(Types.LINK.getType(), null,WebConst.MAX_POSTS); request.setAttribute("links", links); return this; } /** * 获取请求绑定的登录对象 * @param request * @return */ public UserDomain user(HttpServletRequest request) { return TaleUtils.getLoginUser(request); } public Integer getUid(HttpServletRequest request){ return this.user(request).getUid(); } /** * 数组转字符串 * * @param arr * @return */ public String join(String[] arr) { StringBuilder ret = new StringBuilder(); String[] var3 = arr; int var4 = arr.length; for (int var5 = 0; var5 < var4; ++var5) { String item = var3[var5]; ret.append(',').append(item); } return ret.length() > 0 ? ret.substring(1) : ret.toString(); } } ``` ```java //协议集描述@Api用在Conntroller类上,swagger @Api("文章管理") @Controller @RequestMapping("/admin/article") //Spring 事务 -- @Transactional @Transactional(rollbackFor = BusinessException.class) public class XXXController extends BaseController { ``` ## constant 将一些常用的变量写入常量