• 【无标题】


    项目目录

    在这里插入图片描述

    SQLite中的数据

    在这里插入图片描述

    maven的pom.xml导入所需要的依赖

     <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>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    创建SQLite需要的文件

    在resources目录下创建databases.db,如下图
    在这里插入图片描述

    配置yml文件

    server:
      port: 8888
    spring:
      mvc:
        static-path-pattern: classpath:/**
      # 配置 Oracle
      datasource:
        driver-class-name: org.sqlite.JDBC  #数据库链接驱动
        url: jdbc:sqlite::resource:databases/data.db #数据库链接地址
        username:
        password:
        type: com.alibaba.druid.pool.DruidDataSource
    
    # mybatis配置
    mybatis:
      mapper-locations: classpath:mapper/*.xml    # mapper映射文件位置
      type-aliases-package: cn.xdedm.entity    # 实体类所在的位置
      configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl   #用于控制台打印sql语句
        map-underscore-to-camel-case: true
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    Msg类

    package cn.xdedm.entity;
    
    import java.util.HashMap;
    import java.util.Map;
    
    public class Msg {
        //状态码 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 +
                    '}';
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    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 ;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    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;
    
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    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);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    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);
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    在springboot主运行程序加上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);
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    配置完成在postman上测试

    在这里插入图片描述

  • 相关阅读:
    Android 系统日志关键字
    如何检查域名解析是否生效
    基于前馈式模糊控制的公路隧道通风系统研究
    视觉算法需要哪些知识,视觉算法和图像算法
    nodejs 和 npm 版本对应关系
    【零基础学习03】嵌入式linux驱动中自旋锁功能基本实现
    半导体行业调研:工业芯片市场规模分析及发展前景预测
    使用kepware配置opcua服务端,并使用UaExpert作为opc客户端进行连接
    java计算机毕业设计旅游信息网站源码+系统+mysql数据库+lw文档
    中国经济社会大数据研究平台——国内统计数据
  • 原文地址:https://blog.csdn.net/jiulanyangyang/article/details/132646488