spring boot基础

项目搭建

在这里插入图片描述
在这里插入图片描述

热部署

1.安装JRebel
2.下载一个反向代理软件
3.激活:
选择JRebel activated中的 connect to online licensing service
第一行输入 http://127.0.0.1:8888/d3545f42-7b88-4a77-a2da-5242c46d4bc2
第二行输入正确的邮箱格式,例如: test@123.com
再点击以下change liense 按钮验证激活
提示:d3545f42-7b88-4a77-a2da-5242c46d4bc2为UUID,可以自己生成,并且必须是UUID才能通过验证
4.设置为离线模式

代码生成器

1.依赖

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>
        <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
        <verbose>true</verbose>
        <overwrite>true</overwrite>
    </configuration>
</plugin>

2.配置文件:generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <!-- 数据库驱动包位置 -->
    <classPathEntry location="D:\apps\file\ideafile\maven\Repository\mysql\mysql-connector-java\8.0.31\mysql-connector-j-8.0.31.jar" />
    <context id="DB2Tables" targetRuntime="MyBatis3">

        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!-- 数据库链接URL、用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/xiaozhao?characterEncoding=utf8" userId="root" password="root">
<!--            去重8.0以上默认是关闭的-->
            <property name="nullCatalogMeansCurrent" value="true" />
        </jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- 生成实体类的包名和位置,这里配置将生成的实体类放在com.xinzhi.model这个包下 -->
        <javaModelGenerator targetPackage="com.xiaozhao.model" targetProject="src\main\java\">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!-- 生成的SQL映射文件包名和位置,这里配置将生成的SQL映射文件放在com.xiaozhao.mapping这个包下 -->
        <sqlMapGenerator targetPackage="com.xiaozhao.dao" targetProject="src\main\java\">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置,这里配置将生成的dao类放在com.xiaozhao.mapping这个包下 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.xiaozhao.dao" targetProject="src\main\java\">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>


        <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
        <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="person" domainObjectName="Person" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />

    </context>
</generatorConfiguration>

日志

logback-spring.xml

需要注意以后要修改包名,其他的不用动

在这里插入图片描述

怎么打印日志

Log log = LogFactory.getLog(类名.class);

log.info(日志内容)

接口文档

  • 引入插件
 <plugin>
     <groupId>com.github.shalousun</groupId>
     <artifactId>smart-doc-maven-plugin</artifactId>
     <version>1.1.7</version>
     <configuration>
         <!--指定生成文档的使用的配置文件,配置文件放在自己的项目中-->
         <configFile>./src/main/resources/smart-doc.json</configFile>
         <!--指定项目名称-->
         <projectName>sboot</projectName>
         <!--smart-doc实现自动分析依赖树加载第三方依赖的源码,如果一些框架依赖库加载不到导致报错,这时请使用excludes排除掉-->
         <excludes>
             <!--格式为:groupId:artifactId;参考如下-->
             <exclude>com.alibaba:fastjson</exclude>
         </excludes>
         <!--自1.0.8版本开始,插件提供includes支持-->
         <!--smart-doc能自动分析依赖树加载所有依赖源码,原则上会影响文档构建效率,因此你可以使用includes来让插件加载你配置的组件-->
         <includes>
             <!--格式为:groupId:artifactId;参考如下-->
             <include>com.alibaba:fastjson</include>
         </includes>
     </configuration>
</plugin>
  • 指定配置文件
    在这里插入图片描述

  • 记得要将实体类和controller的注解都补充完整

  • 生成指定格式文件

日期

  • 导入依赖
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.10.1</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.10.1</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.10.1</version>
</dependency>
  • 消息转换器
package com.xinzhi.config;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@Component
public class DateConverter implements Converter<String, Date> {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public Date convert(String source) {
        try {
            return sdf.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
  • 配置文件中添加
spring.jackson.date-format =yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值