成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

springboot+mybatis

wuyumin / 3212人閱讀

摘要:整合一創(chuàng)建項目二配置文件公共配置與選擇無關指的路徑是不修改相關配置默認必須再下否則掃包掃不到使用數據源三文件模塊模塊線程池模塊四啟動類加注解五創(chuàng)建啟動測試

springboot整合mybatis

一.創(chuàng)建springboot項目

二.配置文件: application.yml

#公共配置與profiles選擇無關 mapperLocations指的路徑是src/main/resources(不修改相關配置默認必須再resources下,否則掃包掃不到)
mybatis:
  typeAliasesPackage: com.rainbow.quartzdemo
  mapperLocations: classpath:com/rainbow/quartzdemo/mapper/*.xml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
    # 使用druid數據源
    type: com.alibaba.druid.pool.DruidDataSource

server:
  port: 8083

三.pom文件

 
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.0.1
        

        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
        
            mysql
            mysql-connector-java
        

        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        


        
        
            com.alibaba
            druid
            1.1.3
        
        
            org.springframework.boot
            spring-boot-test
            2.1.3.RELEASE
            test
        
        
            junit
            junit
            4.12
            test
        
        
            org.springframework
            spring-test
            5.1.7.RELEASE
            test
        

    

四.啟動類加注解

@MapperScan("com.rainbow.quartzdemo.mapper")

五.創(chuàng)建Controller,啟動測試

package com.rainbow.test.controller;

import com.rainbow.test.mapper.PersonMapper;
import com.rainbow.test.model.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RequestMapping("test")
public class TestController {
    @Autowired
    private PersonMapper personMapper;

    @RequestMapping("person")
    public @ResponseBody Person getPerson(Integer id){
        Person person = personMapper.selectByPrimaryKey(id);
        return person;
    }
}

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://systransis.cn/yun/74813.html

相關文章

  • SpringBoot非官方教程 | 第七篇:SpringBoot開啟聲明式事務

    摘要:準備階段以上一篇文章的代碼為例子,即整合,上一篇文章是基于注解來實現(xiàn)的數據訪問層,這篇文章基于的來實現(xiàn),并開啟聲明式事務。創(chuàng)建實體類數據訪問層接口層用戶減塊用戶加塊,聲明事務,并設計一個轉賬方法,用戶減塊,用戶加塊。 springboot開啟事務很簡單,只需要一個注解@Transactional 就可以了。因為在springboot中已經默認對jpa、jdbc、mybatis開啟了事事...

    tyheist 評論0 收藏0
  • 單手擼了個springboot+mybatis+druid

    摘要:配置想想,我們需要哪些數據庫要用到,數據庫連接池要用到橋接器要用到,因此要倉庫點我去倉庫中找到搜索這些加進去。 本文旨在用最通俗的語言講述最枯燥的基本知識 最近身邊的程序員掀起了學習springboot的熱潮,說什么學會了springboot在大街上就可以橫著走、什么有了springboot媽媽再也不擔心我的編程了、什么BAT都喜歡的框架...聽得作者那個心癢癢的,于是找了個時間,下載...

    adie 評論0 收藏0
  • SpringBoot2.0之五 優(yōu)雅整合SpringBoot2.0+MyBatis+druid+Pa

    摘要:當禁用時,所有關聯(lián)對象都會即時加載。不同的驅動在這方便表現(xiàn)不同。參考驅動文檔或充分測試兩種方法來決定所使用的驅動。需要適合的驅動。系統(tǒng)默認值是設置字段和類是否支持駝峰命名的屬性。 ??上篇文章我們介紹了SpringBoot和MyBatis的整合,可以說非常簡單快捷的就搭建了一個web項目,但是在一個真正的企業(yè)級項目中,可能我們還需要更多的更加完善的框架才能開始真正的開發(fā),比如連接池、分...

    hatlonely 評論0 收藏0
  • Springboot項目搭建(四)整合MySQL數據庫(MyBatis + 分頁配置)

    springboot整合MySQL數據庫(MyBatis + 分頁配置) 一、POM文件添加依賴 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1 com.github.pagehelper pagehelper 4.1.0 mysql mysql-connec...

    Alex 評論0 收藏0
  • SpringBoot2.0之四 簡單整合MyBatis

    摘要:從最開始的到后來的,到目前的隨著框架的不斷更新?lián)Q代,也為我們廣大的程序猿提供了更多的方便,一起搭建一個從控制層到持久層的項目可能需要一兩天的時間,但是采用的方式,我們可能只需要分鐘就能輕松完成一個項目的搭建,下面我們介紹一下整合的方法一新建 ??從最開始的SSH(Struts+Spring+Hibernate),到后來的SMM(SpringMVC+Spring+MyBatis),到目前...

    Sanchi 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<