您好,登錄后才能下訂單哦!
本篇內容介紹了“如何用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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。