当前位置: 首页 > news >正文

千助做网站怎么样360广告推广平台

千助做网站怎么样,360广告推广平台,东莞东城网站建设,郑州品牌营销网站建设本文记录一下完整的 SpringBoot3 整合 Mybatis 的步骤。 只要按照本步骤来操作&#xff0c;整合完成后就可以正常使用。1. 添加数据库驱动依赖 以 MySQL 为例。 当不指定 依赖版本的时候&#xff0c;会 由 springboot 自动管理。 <dependency><groupId>com.mysql&l…
本文记录一下完整的 SpringBoot3 整合 Mybatis 的步骤。
只要按照本步骤来操作,整合完成后就可以正常使用。

1. 添加数据库驱动依赖

以 MySQL 为例。
当不指定 依赖版本的时候,会 由 springboot 自动管理。

<dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><!-- <version>8.0.32</version> -->
</dependency>

2. 添加 MyBatis 依赖

第三方的依赖库,需要明确的指定版本号。推荐使用最新的即可。

<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version>
</dependency>

3. 配置数据源信息

在 application.yaml 文件中添加数据源的信息

spring:datasource:# 数据库连接驱动driver-class-name: com.mysql.cj.jdbc.Driver# 数据源类型: 默认的是 Hikaritype: com.zaxxer.hikari.HikariDataSource# 数据库连接地址url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai# 数据库连接用户名username: root# 数据库连接密码password: 12345678

4. 配置 mybatis

在 application.yaml 文件中添加mybatis的相关配置。

# mybatis 的配置
mybatis:# 配置 mybatis 的xml文件的扫描路径mapper-locations: classpath:mybatis/**/*.xml# 配置实体类的扫描路径type-aliases-package: com.testabc.demo.ssmtestconfiguration:# 开启驼峰命名转换map-underscore-to-camel-case: true# 开启日志#log-impl: org.apache.ibatis.logging.stdout.StdOutImpllog-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl# 指定日志级别 : 对mybatis的日志输出
logging:level:com.testabc.demo.ssmtest: debug

5. 功能开发

5.1 建表

简单创建一张表。包含了普通属性,标准的下划线属性。

CREATE TABLE `test`.`student`  (`id` int NOT NULL,`name` varchar(20) NOT NULL,`age` int NOT NULL,`other_message` varchar(100) NULL,PRIMARY KEY (`id`)
);

5.2 创建普通的bean类

结合表结构,创建普通的一个bean类。此时属性用标准的驼峰命名

package com.testabc.demo.ssmtest;public class Student {private int id;private String name;private int age;private String otherMessage;。。。。。。构造方法getter/settertoString 方法}

5.3 创建mapper接口

注意 : 此处的接口用到了 @Mapper 注解。先写上吧,没有副作用。

package com.testabc.demo.ssmtest;import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;@Mapper
public interface StudentMapper {// 根据id查询student的方法Student getStudentById(@Param("id") int id);
}

5.4 创建xml文件

classpath:/resources/mybatis/ 目录下新增 StudentMapper.xml 文件。

<?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.testabc.demo.ssmtest.StudentMapper"><select id="getStudentById" resultType="com.testabc.demo.ssmtest.Student">select * from student where id = #{id}</select></mapper>

5.5 创建controller类

package com.testabc.demo.ssmtest;@RestController
public class StudentController {/*** 通过构造方法的方式注入 StudentMapper*/private final StudentMapper studentMapper;public StudentController(StudentMapper studentMapper) {this.studentMapper = studentMapper;}@GetMapping("/getStudentById/{id}")public Student getStudentById(@PathVariable("id") int id){Student student = null;student = studentMapper.getStudentById(id);return student;}
}

5.6 配置扫描的包

在 项目的 启动类上添加注解 MapperScan(xxxx), 指定要扫描的 mapper 接口的包路径。

package com.testabc.demo;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.testabc.demo.ssmtest")
public class DemoApplication {public static void main(String[] args) {// 这个工具会返回一个 ApplicationContext 的对象var ioc = SpringApplication.run(DemoApplication.class, args);}}

6. 功能测试

浏览器中访问测试。

在这里插入图片描述
在这里插入图片描述
成功,至此,已经完成了 SpringBoot3 整合 Mybatis 的步骤。

http://www.zhongyajixie.com/news/63543.html

相关文章:

  • 关于做一动物网站的界面个电商平台怎么注册
  • 杭州建设企业网站的搜索引擎付费推广
  • 网站宣传模式百度网盘搜索引擎
  • 网站备案需要哪些材料网页分析工具
  • 发布悬赏任务的推广平台优化内容
  • 买域名可以自己做网站吗地推
  • 开发一个交友app多少钱windows优化大师怎么使用
  • 大连 网站建设seo是广告投放吗
  • 网络广告网站怎样自己制作网站
  • 图派科技做网站怎么样现在做网络推广都有什么方式
  • 东莞微信网站建设信息业务推广平台
  • 直接做网站的软件企业seo外包公司
  • 怎样建立网站卖东西网站推广策划思路
  • 做网站的企业网络维护公司
  • 昆明网站建设平台网站推广的几种方法
  • 哪里找做网站的公司百度一下百度下载
  • 研发项目备案在哪个网站做seo搜索
  • 快速搭建网站推荐网络小说排行榜
  • 网站 css抓关键词的方法10条
  • 有学做衣服的网站吗网站关键词如何快速上首页
  • wordpress安装文件鼓楼网页seo搜索引擎优化
  • 产品推广目标云优化
  • h5免费网站设计全网营销与seo
  • 科技公司网站模板官网网文推广怎么做
  • 沈阳专业做网站拼多多关键词排名查询
  • 联通公网ip申请 做网站自媒体运营
  • 阜阳中国建设银行官网站个人博客网页设计
  • 建立学校网站需要多少钱?淄博网站推广
  • 政府网站建设与维护国内10大搜索引擎
  • vivo官网网站服务app拉新一手渠道