001 简单的springboot整合mybatis

本文详细介绍了如何使用SpringBoot框架整合MyBatis,包括项目搭建、配置、实体类定义、Mapper接口及XML映射文件的使用,以及Service层和Controller层的实现,为快速开发基于MyBatis的SpringBoot应用提供了全面的指南。

首先新建一个springboot项目在这里插入图片描述

在这里插入图片描述
右边可以看到挑选的依赖

  ### 配置application.yml

在这里插入图片描述

 server:
 port: 8080

spring:
 datasource:
   username: root
   password: XXX
   url: jdbc:mysql://XXX:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
   driver-class-name: com.mysql.jdbc.Driver
mybatis:
 mapper-locations: classpath:mapping/*Mapper.xml 
 type-aliases-package: com.example.demo.entity
#showSql
logging:
 level:
   com:
     example:
       mapper : debug

然后分别建

controller entity mapper service 包,以及mapping文件夹
项目结构
在这里插入图片描述

代码

controller
package com.example.demo.controller;

import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/")
public class UserController {

 @Autowired
 private UserService userService;

 @RequestMapping("/{id}")
 public String GetUser(@PathVariable int id){
     return userService.Sel(id).toString();
 }
}
entity
package com.example.demo.entity;

    public class User {
        private String id;
        private String userId;
        private String roleId;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }


        public String getRoleId() {
            return roleId;
        }

        public void setRoleId(String roleId) {
            this.roleId = roleId;
        }
        @Override
        public String toString() {
            return "User{" +
                    "id='" + id + '\'' +
                    ", userId='" + userId + '\'' +
                    ", roleId='" + roleId + '\'' +
                    '}';
        }
}
mapper
package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.springframework.stereotype.Repository;

    @Repository
    public interface UserMapper {
        User Sel(int id);
    }



service
package com.example.demo.service;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    UserMapper userMapper;
    public User Sel(int id){
        User a= userMapper.Sel(id);
        return a;
    }

}

application.run

package com.example.demo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan("com.example.demo")
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

mapping
<?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.example.demo.mapper.UserMapper">

    <select id="Sel" resultType="com.example.demo.entity.User">
        select id ,
               user_id userId,
               role_id roleId
               from sys_user_role where id = #{id}
    </select>
</mapper>

启动成功

在这里插入图片描述

内容概要:本文深入剖析了HTTPS中SSL/TLS握手的全流程,系统讲解了HTTPS的诞生背景及其相较于HTTP在安全性上的优势,重点阐述了SSL/TLS握手各阶段的技术细节,包括ClientHello、ServerHello、证书交换、密钥交换及加密通信建立等环节。文章结合加密基础概念(对称加密、非对称加密、哈希算法)和数字证书机制,解释了数据加密、身份验证与完整性保护的实现原理,并通过Wireshark抓包实例帮助读者直观理解握手过程中的数据交互。同时,归纳了常见握手失败问题及其解决方案,最后对SSL/TLS未来发展趋势进行了展望,涵盖抗量子加密算法和高效协议优化方向。; 适合人群:具备基本网络和安全知识的开发人员、运维工程师、网络安全爱好者,以及希望深入理解HTTPS底层机制的技术从业者;尤其适合1-3年经验、正在向中高级岗位发展的技术人员。; 使用场景及目标:①掌握HTTPS工作原理及SSL/TLS握手全过程,理解加密通信建立机制;②能够分析和排查HTTPS连接中的证书、加密套件、版本兼容等问题;③通过抓包实践提升对网络安全协议的实际分析能力;④为后续学习TLS 1.3、零RTT、前向保密等高级主题打下坚实基础; 阅读建议:此资源理论与实践结合紧密,建议在学习过程中同步使用Wireshark等工具进行抓包实验,对照文档中的握手阶段逐一验证各消息内容,加深对加密协商、证书验证和密钥生成过程的理解。同时关注最新TLS版本的发展趋势,拓展安全视野。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值