<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                1. 準備階段 - 數據庫表結構 ```mysql CREATE DATABASE `sys_rbac` CHARACTER SET 'utf8' COLLATE 'utf8_bin'; USE `sys_rbac`; CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用戶ID', `username` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '用戶名', `password` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '密碼', `enabled` tinyint(1) NULL DEFAULT 1 COMMENT '啟用狀態[1:啟用][0:未啟用]', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `index_user_username`(`username`) USING BTREE COMMENT '用戶名唯一索引' ); CREATE TABLE `role` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色ID', `name` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '角色名稱', `desc` char(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '角色描述', PRIMARY KEY (`id`) USING BTREE ); CREATE TABLE `access` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '權限ID', `name` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '權限名稱', `desc` char(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '權限描述', PRIMARY KEY (`id`) USING BTREE ); CREATE TABLE `user_role` ( `user_id` int(11) NOT NULL COMMENT '用戶ID', `role_id` int(11) NOT NULL COMMENT '角色ID', INDEX `fk_user_role_role_id`(`role_id`) USING BTREE, INDEX `fk_user_role_user_id`(`user_id`) USING BTREE, CONSTRAINT `fk_user_role_role_id` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_user_role_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE `role_access` ( `role_id` int(11) NOT NULL COMMENT '角色ID', `access_id` int(11) NOT NULL COMMENT '權限ID', INDEX `fk_role_access_role_id`(`role_id`) USING BTREE, INDEX `fk_role_access_access_id`(`access_id`) USING BTREE, CONSTRAINT `fk_role_access_access_id` FOREIGN KEY (`access_id`) REFERENCES `access` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_role_access_role_id` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ); ``` - 實體類 ```java @Data public class User { private Integer id; private String username; private String password; private Boolean enabled; } @Data public class Role { private Integer id; private String name; private String desc; } @Data public class Access { private Integer id; private String name; private String desc; } @Data public class UserRole { private Integer userId; private Integer roleId; } @Data public class RoleAccess { private Integer roleId; private Integer accessId; } ``` 2. 添加依賴 ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> <relativePath/> </parent> <dependencies> ... </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> ``` > springboot父pom引入 ```xml <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> ``` > 這是mybatis核心依賴以及MySQL連接驅動 ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> ``` > 這是web依賴,以及lombok工具依賴。 3. pom配置編譯資源 ```xml <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>com/gosuncn/dao/*.xml</include> </includes> </resource> </resources> </build> ``` > 目的就是為了能在`src/main/java`下打包到xml文件。 4. 配置文件application.yml ```yaml server: port: 80 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql:///sys_rbac?serverTimezone=UTC username: root password: root mybatis: mapper-locations: classpath*:/com/gosuncn/dao/*Mapper.xml ``` 5. 掃描mapper接口 - 方式一:[`XxxDao`接口上不加`@Mapper`注解] ```java @SpringBootApplication @MapperScan("com.gosuncn.dao") public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } ``` - 方式二:[啟動類上不加`@MapperScan`注解] ```java @Mapper public interface UserDao { int userSave(User user); } ``` 6. 編寫MapperXml文件`UserDaoMapper.xml` ```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.gosuncn.dao.UserDao"> <insert id="userSave" parameterType="com.gosuncn.entity.User"> insert into user (username, password) values (#{username}, #{password}) </insert> </mapper> ``` > 個人習慣放在與dao目錄同級目錄下,方便管理。 接下來就可以通過service調用dao了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看