springboot学习笔记-Mac
自学springboot一些简单的记录,具体的为什么选择springboot什么的就不多提了,现实需要而已,仅供参考。
配置参数
各主要参数:
- SpringBoot-v:2.1.9.RELEASE;
- IDE :Intellij IDEA ;
- 数据库: MySQL -v:8.0.15;
- 数据库管理工具:Navicat Premium ;
构建单模块项目
/src/main/resources:资源配置文件,环境变量配置、JDBC数据源、Shiro配置、端口配置
/application.properties:配置文件
server.port=9099 #指定端口
server.servlet.context-path=/single/sb/ #指定上下文路径
#数据前后端交互的格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
logging.level.com.debug.steadyjack=debug #日志的打印
#数据源配置
datasource.url=jdbc:mysql://127.0.0.1:3306/db_springboot_teach_02?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
datasource.username=root
datasource.password=linsen
mybatis.type-aliases-package=com.debug.steadyjack.entity
mybatis.mapper-locations=classpath:mappers/*.xml
/src/main/java:源码文件,启动入口类;默认扫描当前包及当前包的子包
@SpringBootApplication(scanBasePackages={“com…controller”})可替换下两个组合
- 自动配置@EnableAutoConfiguration
- 扫描对应包@ConponentScan(“com…controller”)指明controller所在包并实例化
/java/com/…/controller:控制配置文件,实现具体功能的@RestController可替换下两个组合,每个功能返回的都是Restful内容时使用@RestController
- @Controller
@RequestMapping("/功能对应域名")或(value = “/hello/world”,method = RequestMethod.GET) - @ResponseBody加上表示返回的是Restful内容,不加会进行跳转
构建多模块项目
父模块
- /application.properties:
- 数据源配置:
- datasource.url=
- datasource.username=
- datasource.password=
- datasource.druid.pool.initialSize=10
- 数据源配置:
子模块-api:接口
子模块-model:面向ORM-数据访问控制层,mybatis,
- /java/com…/mapper
- /java/com…/entity
子模块-server:最重要的整个项目/服务的核心开发逻辑所在,springboot的主模块,应用的启动类,打包成可执行的jar、war等配置;
- /java/com…/ServerAppilcation:@ImportResource(locations=“${classpath:spring/spring-jdbc.xml}”)加载数据源
- /resources/spring/spring-jdbc.xml:DruidDataSource德鲁伊数据库连接词,进行事务性管理
- /pom.xml:
- /resources/spring/spring.jdbc.xml:
SpringBoot整合mybatis
-
加入依赖Jar:MySQL,数据库连接词Druid,Controller分页插件PageHelper,起步依赖Spring-Boot-Mybatis
-
~/starry-web/src/components/three.vue对比/1/src/components/Exhibition.vue: