使用Eclipse进行Spring Boot的初始设置,包括JDBC和MyBatis的环境配置
概要 – 简要概括
使用Eclipse和Spring Starter项目创建Spring Boot项目
通过JDBC驱动程序+MyBatis连接到MySQL的设置和启动确认。
2. 创建Spring Boot项目
在包资源管理器上右键点击,选择“新建”-“其他”。

在中文中进行本地化的改写:
打开向导选择页面,选择[Spring Boot]-[Spring 起始项目],然后点击“下一步”。

新建一个Spring Starter项目并显示界面。
※ 可以使用默认设置,但这次计划使用’Gradle’而不是’Maven’。

将类型更改为”Gradle(Buildship 2.x)”,并相应地更改其他内容(如名称、分组、成果物等),然后点击”下一步”。

可以在『Spring Boot版本』中输入和搜索需要实现功能所需的库,并进行选择,之后还可以随时添加、修改或删除。

生成的URL包含所选库的Spring initializr模板生成Web服务,点击“完成”按钮。

必要的库将从Maven存储库中下载,并同时创建所需的项目目录结构。

3. JDBC和MyBatis的连接设置
在application.properties文件中,要记录有关连接MySQL所需的JDBC类、连接MySQL的字符串、连接用户名和密码。

在/src/main/resources目录下创建一个名为『mybatis-config.xml』的文件,用于描述MyBatis的固有设置信息。

将MyBatis的默认配置信息appUnderscoreToCamelCase设置为true。
如果数据库的列名是以蛇形命名法(用下划线连接多个单词的表达方式)定义的,将会被转换为驼峰命名法(用大写字母连接第二个及之后的单词的表达方式)并进行映射。
如果存在一个名为”user_id”的列,那么它会在Java中被映射为字段名”userId”。

在具有SpringBootApplication注解的PracApplication类中,将根据application.properties的设置生成数据源,并进一步生成配置了MyBatis特定信息的SqlSessionFactory类,以使其成为Bean的自动注册目标。

4. 执行应用程序
点击[窗口]-[视图显示]-[其他]。

在视图显示屏上,选择“Gradle执行”和“Gradle任务”,然后点击。

在Gradle任务选项卡中显示,并双击“bootRun”。

在“Gradle执行”选项卡中,会显示执行情况。
※如果有错误的话,会显示为红色的叉号。

如果在「控制台」选项卡中显示了「Started PracApplication in ・・・」,则说明它已成功启动。

参考网站:
· 在使用Spring Boot进行数据库协作时的配置文件 http://yuuki1413.hatenablog.com/entry/2017/07/25/150521