亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

springboot 整合 mybatis(無spring開發(fā)經(jīng)驗版本)

gotham / 588人閱讀

摘要:相關(guān)代碼開始駝峰命名與下劃線命名的轉(zhuǎn)換

springboot 整合 mybatis(無spring開發(fā)經(jīng)驗版本) 目錄結(jié)構(gòu)

目錄解釋

controller 定義路由

service 業(yè)務(wù)邏輯處理

entity 實體類 與數(shù)據(jù)庫中的表一一對應(yīng)

mapper 數(shù)據(jù)庫操作,定義對數(shù)據(jù)庫各種CUDR的接口,myBatis框架會自動生成實體類

mapping 數(shù)據(jù)庫操作的XML文件,通過namespace 與 mapper一一對應(yīng),通過每一項中的id對應(yīng)接口類中定義的方法,通過每一項中的resultType對應(yīng)實體類,表明數(shù)據(jù)返回的對象。

相關(guān)代碼

application.yml

spring:
  profiles:
    active: dev

application-dev.yml

server:
  port: 8080

spring:
  datasource:
    username: root
    password: 19961110
    url: jdbc:mysql://47.95.110.227:3308/news?useUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver

mybatis:
  mapper-locations: classpath:mapping/*Mapper.xml
  configuration:
    # 開始駝峰命名與下劃線命名的轉(zhuǎn)換
    map-underscore-to-camel-case: true

#showSql
logging:
  level:
    com:
      example:
        mapper : debug

indexController.Java

package com.crxk.myBatisTset.controller;

import com.crxk.myBatisTset.service.catService;
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;

@Controller
@ResponseBody
public class indexController {

    @Autowired
    private catService catService;

    @RequestMapping("/getCat")
    public String getCat(int id){
        return catService.getCat(id).toString();
    }
}

catService.java

package com.crxk.myBatisTset.service;

import com.crxk.myBatisTset.entity.Cat;
import com.crxk.myBatisTset.mapper.catMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class catService {
    @Autowired
    catMapper catMapper;
    public Cat getCat(int id){
        return catMapper.getCat(id);
    }
}

cat.java

package com.crxk.myBatisTset.entity;

public class Cat {
    int catId;
    String catName;

    public Cat() {
    }

    public Cat(int catId, String catName) {
        this.catId = catId;
        this.catName = catName;
    }

    public int getCatId() {
        return catId;
    }

    public void setCatId(int catId) {
        this.catId = catId;
    }

    public String getCatName() {
        return catName;
    }

    public void setCatName(String catName) {
        this.catName = catName;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "catId=" + catId +
                ", catName="" + catName + """ +
                "}";
    }
}

catMapper.java

package com.crxk.myBatisTset.mapper;


import com.crxk.myBatisTset.entity.Cat;
import org.apache.ibatis.annotations.Mapper;


@Mapper
public interface catMapper {
    Cat getCat(int id);
}

catMapper.xml





    

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

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/75246.html

相關(guān)文章

  • SpringBoot2.0之五 優(yōu)雅整合SpringBoot2.0+MyBatis+druid+Pa

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

    hatlonely 評論0 收藏0
  • 新手也能實現(xiàn),基于SpirngBoot2.0+ 的 SpringBoot+Mybatis 多數(shù)據(jù)源配

    摘要:下面基于,帶著大家看一下中如何配置多數(shù)據(jù)源。注意版本不一致導(dǎo)致的一些小問題。配置配置兩個數(shù)據(jù)源數(shù)據(jù)庫和數(shù)據(jù)庫注意事項在配置數(shù)據(jù)源的過程中主要是寫成和。五啟動類此注解表示啟動類這樣基于的多數(shù)據(jù)源配置就已經(jīng)完成了,兩個數(shù)據(jù)庫都可以被訪問了。 在上一篇文章《優(yōu)雅整合 SpringBoot+Mybatis ,可能是你見過最詳細的一篇》中,帶著大家整合了 SpringBoot 和 Mybatis...

    shiina 評論0 收藏0
  • 寫這么多系列博客,怪不得找不到女朋友

    摘要:前提好幾周沒更新博客了,對不斷支持我博客的童鞋們說聲抱歉了。熟悉我的人都知道我寫博客的時間比較早,而且堅持的時間也比較久,一直到現(xiàn)在也是一直保持著更新狀態(tài)。 showImg(https://segmentfault.com/img/remote/1460000014076586?w=1920&h=1080); 前提 好幾周沒更新博客了,對不斷支持我博客的童鞋們說聲:抱歉了!。自己這段時...

    JerryWangSAP 評論0 收藏0
  • 基于 SpringBoot2.0+優(yōu)雅整合 SpringBoot+Mybatis

    摘要:基于最新的,是你學(xué)習(xí)的最佳指南。驅(qū)動程序通過自動注冊,手動加載類通常是不必要。由于加上了注解,如果轉(zhuǎn)賬中途出了意外和的錢都不會改變。三的方式項目結(jié)構(gòu)相比于注解的方式主要有以下幾點改變,非常容易實現(xiàn)。公眾號多篇文章被各大技術(shù)社區(qū)轉(zhuǎn)載。 Github 地址:https://github.com/Snailclimb/springboot-integration-examples(Sprin...

    gghyoo 評論0 收藏0

發(fā)表評論

0條評論

gotham

|高級講師

TA的文章

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