springboot+mybatisPluse

项目的步骤如下图

在这里插入图片描述

在这里插入图片描述
项目创建完之后,穿件几个文件夹
在这里插入图片描述
配置文件内容如下
application.yml

# Tomcat
server:
  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
    min-spare-threads: 30
  port: 9999
  #connection-timeout: 5000ms
  servlet:
    context-path: /media

spring:
  # 环境 dev|test|prod
  profiles:
    #active: test
    active: prod
  # jackson时间格式化
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
  servlet:
    multipart:
      max-file-size: 100MB
      max-request-size: 100MB
      enabled: true
  mvc:
    throw-exception-if-no-handler-found: true
  #  resources:
  #    add-mappings: false

#mybatis
mybatis-plus:
  mapper-locations: classpath*:/mapper/**/*.xml
  #实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage: com.springboot.model
  global-config:
    #数据库相关配置
    db-config:
      #主键类型  AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
      id-type: AUTO
      logic-delete-value: -1
      logic-not-delete-value: 0
    banner: false
  #原生配置
  configuration:
    map-underscore-to-camel-case: false
    #mybatis缓存
    cache-enabled: false
    call-setters-on-nulls: true
    jdbc-type-for-null: 'null'
    #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

redis:
  open: false
  common:
    timeout: 86400
  token:
    #timeout: 1800
    timeout: 86400
  shiro:
    redis: false

application-prod.yml

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8
      username: root
      password: root333
      initial-size: 10
      max-active: 1000
      min-idle: 100
      max-wait: 60000
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 300000
      #Oracle需要打开注释
      #validation-query: SELECT 1 FROM DUAL
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        #login-username: admin
        #login-password: admin
      filter:
        stat:
          log-slow-sql: true
          slow-sql-millis: 1000
          merge-sql: false
        wall:
          config:
            multi-statement-allow: true
  rabbitmq:
    host: 192.168.12.90
    port: 5672
    username: admin
    password: 802317
    virtual-host: dnake
    publisher-confirm: true
    publisher-returns: true
    listener:
      simple:
        default-requeue-rejected: true
  redis:
    open: false  # 是否开启redis缓存  true开启   false关闭
    database: 1
    host: 192.168.12.91
    port: 6379
    password:    # 密码(默认为空)
    timeout: 6000ms  # 连接超时时长(毫秒)
    jedis:
      pool:
        max-active: 1000  # 连接池最大连接数(使用负值表示没有限制)
        max-wait: -1ms      # 连接池最大阻塞等待时间(使用负值表示没有限制)
        max-idle: 10      # 连接池中的最大空闲连接
        min-idle: 5       # 连接池中的最小空闲连接

##多数据源的配置
dynamic:
  datasource:
    slave1:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/zh_yule?useUnicode=true&characterEncoding=utf8
      username: dnk
      password: Dnk2017!
    slave2:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/zh_yule?useUnicode=true&characterEncoding=utf8
      username: dnk
      password: Dnk2017!

model

@Data
@Table(name = "user",schema = "demo",catalog = "")
public class User {

  private long id;
  private String name;
  private String passWord;
  private String perms;
  private String ps;

@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
  public long getId() {
    return id;
  }

  public void setId(long id) {
    this.id = id;
  }

@Basic
@Column(name = "name")
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

dao

@Mapper
@Repository
public interface userDao  {

    User getById(Integer id);
}

mapper

<?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="com.lq.dao.userDao">
    <!-- 根据主键查询-->
    <select id="getById" resultType="com.lq.module.User" parameterType="java.lang.Integer" >
        select  *
        from user
        where id = #{id}
    </select>
</mapper>

service

@Service
public class userService {
    @Autowired
   private userDao usero;

    public User getById(Integer id){
        return usero.getById(id);
    }

}

controller

@Controller
@RequestMapping("/demo")
public class userController {
    @Autowired
    private userService service;

    @GetMapping(value = "/get")
    @ResponseBody
    public User test(HttpServletRequest request) {
        int id=Integer.parseInt(request.getParameter("id"));
        System.out.println(id);
        return service.getById(id);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值