最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot整合mybatis簡(jiǎn)單案例過程解析

 更新時(shí)間:2019年11月06日 10:46:40   作者:-0-1  
這篇文章主要介紹了SpringBoot整合mybatis簡(jiǎn)單案例過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了SpringBoot整合mybatis簡(jiǎn)單案例過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

1.在springboot項(xiàng)目中的pom.xml中添加mybatis的依賴

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

2.在src/main/resources/application.yml中配置數(shù)據(jù)源信息

# DB Configation
spring:
 datasource:
  driver-class-name: com.mysql.jdbc.Driver
  url: jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT
  username: root
  password: root

# JAPConfigration
 jpa:
  database: mysql
  show-sql: true
  generate-ddl: true

在連接數(shù)據(jù)庫(kù)的過程中可能會(huì)出現(xiàn)SQLException,可能是時(shí)區(qū)問題導(dǎo)致的,加上url路徑后面的“serverTimezone = GMT”即可

3.在主啟動(dòng)類的同級(jí)創(chuàng)建po包和mapper包,在po包中創(chuàng)建實(shí)體類,編寫pojo;在mapper包中創(chuàng)建mapper接口和mapper映射文件

mapper.java

package com.hxy.springbootdemo1.demo.mapper;

import com.hxy.springbootdemo1.demo.pojo.MUser;

import java.util.List;

public interface UserMapper {
  List<MUser> getUserList();
}

mapper.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.hxy.springbootdemo1.demo.mapper.UserMapper">
  <select id="getUserList" resultType="com.hxy.springbootdemo1.demo.pojo.MUser">
    select * from user
  </select>
</mapper>

4.手動(dòng)配置mybatis的包掃描

  在主啟動(dòng)類添加@MapperScan

  如果出現(xiàn)錯(cuò)誤:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.offcn.mapper.UserMapper.getUserList

  有如下兩種方法解決:

  1 把映射文件 放到resources 目錄下 結(jié)構(gòu)目錄一模一樣

  2 修改配置文件pom.xml

<build>
    <resources>
      <resource>
        <directory>src/main/java</directory>
         <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
         </includes>
        <filtering>false</filtering>
      </resource>
    <resource>
      <directory>src/main/resources</directory>
        <includes>
          <include>**/*.*</include>
        </includes>
        <filtering>false</filtering>
    </resource>
  </resources>
 </build>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

淮安市| 法库县| 夏邑县| 华容县| 西藏| 遂平县| 灯塔市| 义马市| 安顺市| 镶黄旗| 根河市| 靖宇县| 马尔康县| 广东省| 大埔区| 常德市| 双鸭山市| 象山县| 北宁市| 镇原县| 武陟县| 文安县| 丹棱县| 耿马| 胶州市| 呈贡县| 隆子县| 南和县| 天门市| 祁东县| 宁都县| 长沙市| 盘山县| 遵义县| 郴州市| 西和县| 富平县| 清水县| 桑植县| 安泽县| 广水市|