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

資訊專欄INFORMATION COLUMN

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

gotham / 540人閱讀

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

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

目錄解釋

controller 定義路由

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

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

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

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

相關(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)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/75246.html

相關(guān)文章

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

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

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

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

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

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

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

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

    gghyoo 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<