本篇内容介绍了“如何用OAuth 2.0实现权限认证mybatis连接mysql数据库”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.18</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.3</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.5</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>2.0.5</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.3</version> </dependency>
添加配置信息
spring: redis: host: 127.0.0.1 port: 6379 datasource: name: url: jdbc:mysql://mysqlurl:3306/hongyuan?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=UTC username: root password: root server: port: 9090 mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.hongyuan.dao
编辑相关的mapper文件
package com.hongyuan.dao; import com.hongyuan.pojo.UserInfo; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; import java.util.List; /** * @ClassName UserDao * @PaceageName com.hongyuan.dao * @Description: 用户信息表 * @Author: liuxinzhou * @Date: 2020/9/22 5:26 下午 * @Version V1.0.0 */ @Mapper public interface UserMapper { //根据用户信息获取对应的本用户所有信息 public UserInfo getUserInfo(UserInfo userInfo); // 查询所有用户信息 public List<UserInfo> getUserList(); }
添加关联的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.hongyuan.dao.UserMapper"> <sql id="table">user</sql> <select id="getUserInfo" resultType="com.hongyuan.pojo.UserInfo"> select * from <include refid="table"/> where 1=1 <if test="username != null and username != ''">and username = #{username}</if> </select> <select id="getUserList" resultType="com.hongyuan.pojo.UserInfo"> select * from <include refid="table"/> </select> </mapper>
“如何用OAuth 2.0实现权限认证mybatis连接mysql数据库”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。