码迷,mamicode.com
首页 > 编程语言 > 详细

springboot+mybaties

时间:2019-01-12 22:59:55      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:select   amp   classname   int   nis   2.0   static   存储   .so   

1.  开发工具:Intellij idea2018.3

 

2.  file----->new----->project

技术分享图片

 

3.  选择Spring Initializr,点击next

技术分享图片

 

4.  点击next

技术分享图片

 

5.  web中选择web,SQL中选择JAP/MySQL/JDBC,点击next

技术分享图片

 

6.  输入项目名称,选择存储路径,点击finish

技术分享图片

 

7.  application.properties配置文件

spring.datasource.url=jdbc:mysql://139.129.195.206:3306/pmis
spring.datasource.username=root
spring.datasource.password=Jcsg123
spring.datasource.driverClassName=com.mysql.jdbc.Driver
#页面热加载
spring.thymeleaf.cache=false
server.port=8080

 

8.  mapper类,需要加注解@Repository

package com.example.mapper;

import com.example.model.UserModel;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {
    @Select("select * from wx_config where id=#{id}")
    UserModel selectById(int id);
}

 

9.  启动类需要加注解@MapperScan("com.example.mapper"),用来扫描mapper文件,需要注意的是:启动类需要和controller/entity/mapper/service包同级!!!

package com.example;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@MapperScan("com.example.mapper")
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

 

 10.  pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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>
            <version>5.1.26</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>-->
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->







        <!--<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>-->

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 

可能不太完善,后期再改

 

springboot+mybaties

标签:select   amp   classname   int   nis   2.0   static   存储   .so   

原文地址:https://www.cnblogs.com/gxlaqj/p/10261077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!