zoukankan      html  css  js  c++  java
  • springboot 梳理1--简单整合mybatis

    1. pom.xml添加

            <!--mybatis起步依赖-->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.1.2</version>
            </dependency>
            <!--mysql连接驱动-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>    

    2. application.yml

    #db Configuration:
    spring:
      #默认datasource hikaricp
      datasource:
        url: jdbc:mysql://127.0.0.1:3306/ssm?characterEncoding=utf8&&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
        driver-class-name: com.mysql.jdbc.Driver
        username: root
        password: 123456
    
    mybatis:
      mapper-locations: mapper/*.xml
      type-aliases-package: com.xinzhi.studyspringboot.entity

    3. entity层User

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class User {
        private int id;
        private String username;
        private String password;
    }

    3. dao层UserMapper

    @Mapper
    public interface UserMapper {
        /**
         * 查询用户
         * @return
         */
        public List<User> queryUserList();
    }

    4. resources/mapper/UserMapper.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.xinzhi.studyspringboot.dao.UserMapper">
        <select id="queryUserList" resultType="User">
            select * from user
        </select>
    </mapper>

    5. service层

    (1)IUserService = UserMapper

    (2)UserServiceImpl 实现IUserService,私有变量UserMapper,方法实现

    @Service
    public class UserServiceImpl implements IUserService {
        @Resource
        private UserMapper userMapper;
    
        @Override
        public List<User> queryUserList() {
            return userMapper.queryUserList();
        }
    }

    6. controller层UserController实现,私有变量IUserService

    @Controller
    @RequestMapping("/user")
    public class UserController {
    
        @Resource
        private IUserService userService;
    
        @GetMapping
        @ResponseBody
        public List<User> getUsers(){
            return userService.queryUserList();
        }
    }
  • 相关阅读:
    利用加载模块之外的地址绕过SafeSEH
    C++ 单实例运行
    添加程序以DLL函数
    HOOK地址还原
    利用未启用SafeSEH模块绕过SafeSEH
    SafeSEH基本概念+ 从堆区绕过SafeSEH学习
    替换.DATA的COOKIE突破GS
    虚函数绕过 GS保护 学习
    攻击虚函数学习
    虚函数学习
  • 原文地址:https://www.cnblogs.com/Master-Sun/p/14344423.html
Copyright © 2011-2022 走看看