zoukankan      html  css  js  c++  java
  • 超简单的SpringBoot整合mybatis

        1. 创建项目结构
      2. 编写application.yml/application.properties配置文件
      3. 启动类开启映射包扫描
      4. 接口测试

    创建项目结构    

    导入依赖

            <dependencies>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-jdbc</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.mybatis.spring.boot</groupId>
    			<artifactId>mybatis-spring-boot-starter</artifactId>
    			<version>1.3.2</version>
    		</dependency>
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    			<scope>runtime</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-test</artifactId>
    			<scope>test</scope>
    		</dependency>
    

      

    编写application.yml/application.properties配置文件

    启动类开启映射包扫描

        @SpringBootApplication
        @MapperScan({"com.cn.mybatis.zy.zymybatis.dao"})
        public class ZyMybatisApplication {
        
            public static void main(String[] args) {
                SpringApplication.run(ZyMybatisApplication.class, args);
            }
        
        }

    接口测试

     @Resource
        private UserService userService;
    
        @GetMapping("/info")
        public String info(Model model){
            List<User> allUsers = userService.getAllUsers();
            model.addAttribute("user",allUsers);
            allUsers.stream().forEach(a -> {
                System.out.println(a);
            });
            return "index";
        }
    平凡是我的一个标签
  • 相关阅读:
    nyoj 16 矩形嵌套
    nyoj 44 子串和
    nyoj 448 寻找最大数
    nyoj 14 会场安排问题
    hdoj 1008 Elevator
    bzoj1588
    bzoj3224
    bzoj1503
    bzoj1834
    bzoj1066
  • 原文地址:https://www.cnblogs.com/guyanzy/p/10381072.html
Copyright © 2011-2022 走看看