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

Springboot整合Mybatis和SQLite的詳細(xì)過程

 更新時間:2024年07月16日 10:46:30   作者:orzdh  
這篇文章主要介紹了Springboot整合Mybatis和SQLite的詳細(xì)過程,本文通過圖文示例相結(jié)合給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧

項(xiàng)目目錄

SQLite中的數(shù)據(jù)

maven的pom.xml導(dǎo)入所需要的依賴

 <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.8.11.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

創(chuàng)建SQLite需要的文件

在resources目錄下創(chuàng)建databases.db,如下圖

配置yml文件

server:
  port: 8888
spring:
  mvc:
    static-path-pattern: classpath:/**
  # 配置 Oracle
  datasource:
    driver-class-name: org.sqlite.JDBC  #數(shù)據(jù)庫鏈接驅(qū)動
    url: jdbc:sqlite::resource:databases/data.db #數(shù)據(jù)庫鏈接地址
    username:
    password:
    type: com.alibaba.druid.pool.DruidDataSource
# mybatis配置
mybatis:
  mapper-locations: classpath:mapper/*.xml    # mapper映射文件位置
  type-aliases-package: cn.xdedm.entity    # 實(shí)體類所在的位置
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl   #用于控制臺打印sql語句
    map-underscore-to-camel-case: true

Msg類

package cn.xdedm.entity;
import java.util.HashMap;
import java.util.Map;
public class Msg {
    //狀態(tài)碼 10001 成功 10002失敗
    private int code;
    private String msg;
    private Map<String,Object> extend=new HashMap<String,Object>();
    /**
     * 返回成功
     * @return
     */
    public static  Msg Success (){
        Msg result = new Msg();
        result.setCode(10001);
        result.setMsg("成功");
        return result;
    }
    /***
     * 返回失敗
     * @return
     */
    public static  Msg fail (){
        Msg result = new Msg();
        result.setCode(10002);
        result.setMsg("失敗");
        return result;
    }
    public Msg Add(String key,Object value){
        this.getExtend().put(key,value);
        return this;
    }
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public Map<String, Object> getExtend() {
        return extend;
    }
    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }
    @Override
    public String toString() {
        return "Msg{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", extend=" + extend +
                '}';
    }
}

User類

package cn.xdedm.entity;
import lombok.Data;
@Data
public class User {
    private Integer id ;
    private String  nickName ;
    private String  account ;
    private String  password ;
    private String  createTime;
    private Integer vaildFlag ;
}

controller類

   package cn.xdedm.controller;
import cn.xdedm.entity.Msg;
import cn.xdedm.entity.User;
import cn.xdedm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/query")
    public Msg QueryUser(@RequestBody User user){
        Msg msg=userService.QueryUser(user);
        return msg;
    }
}

service類

package cn.xdedm.service;
import cn.xdedm.dao.UserMapper;
import cn.xdedm.entity.Msg;
import cn.xdedm.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    public Msg QueryUser(User user) {
        User user_db=userMapper.QueryUser(user);
        return Msg.Success().Add("user",user_db);
    }
}

dao類

package cn.xdedm.dao;
import cn.xdedm.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
@Component
@Mapper
public interface UserMapper {
    User QueryUser(User user);
}

maper.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="cn.xdedm.dao.UserMapper">
    <select id="QueryUser" parameterType="cn.xdedm.entity.User">
        select * from passwordsystem_user where 1=1
        <if test="id !=null and id !='' or id == 0">
            and id=#{id}
        </if>
        <if test="nickName !=null and nickName !='' or nickName == 0">
            and nick_name=#{nickName}
        </if>
        <if test="vaildFlag !=null and vaildFlag !='' or vaildFlag == 0">
            and vaild_flag=#{vaildFlag}
        </if>
        <if test="account !=null and account !='' or account== 0">
            and account=#{account}
        </if>
    </select>
</mapper>

在springboot主運(yùn)行程序加上MapperScan注解

package cn.xdedm;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("cn.xdedm.dao")
public class PasswordsystemApplication {
    public static void main(String[] args) {
        SpringApplication.run(PasswordsystemApplication.class, args);
    }
}

配置完成在postman上測試

到此這篇關(guān)于Springboot整合Mybatis和SQLite的文章就介紹到這了,更多相關(guān)Springboot整合Mybatis內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring根據(jù)XML配置文件 p名稱空間注入屬性的實(shí)例

    Spring根據(jù)XML配置文件 p名稱空間注入屬性的實(shí)例

    下面小編就為大家分享一篇Spring根據(jù)XML配置文件 p名稱空間注入屬性的實(shí)例,具有很好的參考價值。希望對大家有所幫助
    2017-11-11
  • redisson使用lock導(dǎo)致死鎖問題解決

    redisson使用lock導(dǎo)致死鎖問題解決

    本文主要介紹了redisson使用lock導(dǎo)致死鎖問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-12-12
  • JMagick實(shí)現(xiàn)基本圖像處理的類實(shí)例

    JMagick實(shí)現(xiàn)基本圖像處理的類實(shí)例

    這篇文章主要介紹了JMagick實(shí)現(xiàn)基本圖像處理的類,實(shí)例分析了java圖像處理的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • Java 動態(tài)代理深入理解

    Java 動態(tài)代理深入理解

    這篇文章主要介紹了Java 動態(tài)代理深入理解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Java 數(shù)組分析及簡單實(shí)例

    Java 數(shù)組分析及簡單實(shí)例

    這篇文章主要介紹了Java 數(shù)組分析及簡單實(shí)例的相關(guān)資料,在Java中它就是對象,一個比較特殊的對象,需要的朋友可以參考下
    2017-03-03
  • 使用Spring Boot搭建Java web項(xiàng)目及開發(fā)過程圖文詳解

    使用Spring Boot搭建Java web項(xiàng)目及開發(fā)過程圖文詳解

    這篇文章主要介紹了使用Spring Boot搭建Java web項(xiàng)目及開發(fā)過程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-06-06
  • Java中反射的一個簡單使用

    Java中反射的一個簡單使用

    一直感覺Java的反射機(jī)制很強(qiáng)大,JAVA反射技術(shù)在平時我們的開發(fā)中雖然很少會用到,但在我們所使用的框架源碼中是經(jīng)常會用到的。這篇文中就給大家介紹了關(guān)于Java中反射的一個簡單使用,有需要的朋友們下面來一起看看吧。
    2016-11-11
  • Springboot+mybatis plus找不到mapper.xml的問題解決

    Springboot+mybatis plus找不到mapper.xml的問題解決

    本文主要介紹了Springboot+mybatis plus找不到mapper.xml的問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • Hibernate hql查詢代碼實(shí)例

    Hibernate hql查詢代碼實(shí)例

    這篇文章主要介紹了Hibernate hql查詢代碼實(shí)例,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02
  • Springboot 緩存@Cacheable 的引入和使用

    Springboot 緩存@Cacheable 的引入和使用

    @Cacheable是Spring緩存抽象的核心注解,作用是將方法的返回結(jié)果緩存起來,本文給大家介紹Springboot緩存@Cacheable的引入和使用,感興趣的朋友跟隨小編一起看看吧
    2026-03-03

最新評論

含山县| 曲周县| 宜春市| 哈巴河县| 石台县| 望都县| 黄大仙区| 宣恩县| 贵定县| 西林县| 伽师县| 乐陵市| 屏边| 吉安市| 长汀县| 武川县| 久治县| 屏山县| 广水市| 抚州市| 乐陵市| 博爱县| 文成县| 灵石县| 辰溪县| 威信县| 密山市| 荃湾区| 格尔木市| 万全县| 兴国县| 芮城县| 航空| 黑水县| 汉中市| 青浦区| 延庆县| 湖南省| 叶城县| 红原县| 岑溪市|