实体类、Mapper、Mapper.xml、Service、ServiceImpl、Controller、application.yml 快捷模版

目录

实体类

Mapper

Mapper.xml

Service

ServiceImpl

Controller

application.yml

Idea 配置方法

使用方法 


实体类

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#parse("Controller Header.java")
@RestController
@RequestMapping("/${NAME}")
public class ${NAME}Controller {
        
}

Mapper

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
#parse("Mapper Header.java")
@Mapper
public interface ${NAME}Mapper extends BaseMapper<${NAME}> {
        
}

Mapper.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="">
    <!-- 实体类 -->
    <resultMap type="${NAME}" id="${NAME}Result">
    </resultMap>
    
    <!-- sql语句 -->
    <sql id="select${NAME}List">
      
    </sql>
    
    <!-- 方法 -->
    <select id="query${NAME}List" parameterType="${NAME}" resultMap="${NAME}Result">
        <include refid="select${NAME}List"/>
        <where>  
            <if test="fieldName != null  and fieldName != ''"> and tableFieldName like concat('%', #{fieldName}, '%')</if>
            <if test="startDate != null  and startDate != ''">and tableFieldName &gt;= #{startDate}</if>
            <if test="endDate != null  and endDate != ''">and tableFieldName &lt;= #{endDate}</if>
        </where>
    </select>
</mapper>

Service

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("Service Header.java")
public interface ${NAME}Service {
        
}

ServiceImpl

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
#parse("ServiceImpl Header.java")
@Service
public class ${NAME}ServiceImpl extends ServiceImpl<${NAME}Mapper, ${NAME}> implements ${NAME}Service {
        
}

Controller

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#parse("Controller Header.java")
@RestController
@RequestMapping("/${NAME}")
public class ${NAME}Controller {
        
}

application.yml

server:
  port: 8081
  tomcat:
    # tomcat的URI编码
    uri-encoding: UTF-8
    # 连接数满后的排队数,默认为100
    accept-count: 1000
    threads:
      # tomcat最大线程数,默认为200
      max: 800
      # Tomcat启动初始化的线程数,默认值10
      min-spare: 100
 
spring:
  profiles: # 指定配置文件 只有一个配置文件就去掉这个配置
    active: dev
  datasource: # 数据源
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    #    driver-class-name: net.sourceforge.jtds.jdbc.Driver
    druid:
      master: # 主数据源
        url: jdbc:sqlserver://localhost:1433;DatabaseName=dataBase
        username: root
        password: root
      slave: # 从库数据源
        # 从数据源开关/默认关闭
        enabled: false
        url:
        username:
        password:
      ekp:
        enabled: true
        url: jdbc:sqlserver://localhost:1433;SelectMethod=cursor;DatabaseName=dataBase
        username: root
        password: root
    hikari:
      connection-test-query: SELECT 1 #测试连接是否可用
  # redis 配置
  redis:
    # 地址
    host: localhost
    # 端口,默认为6379
    port: 6379
    # 数据库索引
    database: 10
    # 密码
    password:
    # 连接超时时间
    timeout: 10s
    lettuce:
      pool:
        # 连接池中的最小空闲连接
        min-idle: 0
        # 连接池中的最大空闲连接
        max-idle: 8
        # 连接池的最大数据库连接数
        max-active: 8
        # #连接池最大阻塞等待时间(使用负值表示没有限制)
        max-wait: -1ms
  banner:
    location: banner.txt # banner样式
  servlet: # 文件上传
    multipart:
      max-file-size:  10MB # 单个文件大小,默认为10MB
      max-request-size: 50MB # 总上传文件大小,默认为50MB
  mvc:
    async:
      request-timeout:  60000
  messages: # 资源信息
    basename: i18n/messages # 国际化资源文件路径
  # 服务模块
  devtools:
    restart:
      # 热部署开关
      enabled: true
 
mybatis-plus:
  mapper-locations: classpath:mapper/**/*Mapper.xml # xml文件路径扫描
  typeAliasesPackage: com.**.**.entity # 实体类包路径扫描
  global-config:
    db-config:
      id-type: AUTO
      logic-delete-value: -1
      logic-not-delete-value: 0
    banner: false
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    mapUnderscoreToCamelCase: true
    jdbc-type-for-null: 'null'
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# PageHelper分页插件
pagehelper:
  helperDialect: sqlserver
  supportMethodsArguments: true
  params: count=countSql
# Swagger配置
swagger:
  # 是否开启swagger
  enabled: true
  # 请求前缀
  pathMapping: /dev-api
# token配置
token:
  # 令牌自定义标识
  header: Authorization
  # 令牌密钥
  secret: abcdefghijklmnopqrstuvwxyz
  # 令牌有效期(默认30分钟)
  expireTime: 30
# 用户配置
user:
  password:
    # 密码最大错误次数
    maxRetryCount: 5
    # 密码锁定时间(默认10分钟)
    lockTime: 10
# 防止XSS攻击
xss:
  # 过滤开关
  enabled: true
  # 排除链接(多个用逗号分隔)
  excludes: /system/notice
  # 匹配链接
  urlPatterns: /system/*,/monitor/*,/tool/*
# 日志配置
logging:
  level:
    com.akesobio: debug
    org.springframework: warn

application.yml 精简

server:
  port: 9093
  tomcat:
    # tomcat的URI编码
    uri-encoding: UTF-8
    # 连接数满后的排队数,默认为100
    accept-count: 1000
    threads:
      # tomcat最大线程数,默认为200
      max: 800
      # Tomcat启动初始化的线程数,默认值10
      min-spare: 100

spring:
  # 切换配置文件
  profiles:
    active: prod
  # banner样式
  banner:
    location: banner.txt
  # 文件上传
  servlet:
    multipart:
      max-file-size:  10MB # 单个文件上传大小,默认为10MB
      max-request-size: 50MB # 总上传文件大小,默认为50MB
  mvc:
    async:
      request-timeout:  60000

mybatis-plus:
  mapper-locations: classpath:mapper/**/*Mapper.xml
  typeAliasesPackage: com.leslie.**.entity
  global-config:
    db-config:
      id-type: auto
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    mapUnderscoreToCamelCase: true
#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl  # 注释后 SQL 查询数据,控制台不打印结果

# 防止XSS攻击
xss:
  # 过滤开关
  enabled: true
  # 排除链接(多个用逗号分隔)
  excludes: /system/notice
  # 匹配链接
  urlPatterns: /system/*,/monitor/*,/tool/*

# 日志配置
logging:
  level:
    com.leslie: debug
    org.springframework: warn

application-prod.yml 

spring:
  datasource:  # 数据源 单数据源时,url、username、password 挪到第一个 datasource 下
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
#    hikari:
#      connection-test-query: SELECT 1 #测试连接是否可用
    dynamic:
      primary: master
      strict: false
      datasource:
        master:
          url: jdbc:sqlserver://ip:1433;DatabaseName=
          username: 
          password: 
        department:
#          enabled: true
          url: jdbc:sqlserver://ip:1433;SelectMethod=cursor;DatabaseName=
          username: 
          password: 

    # 初始连接数
    druid:
      # 初始连接数
      initialSize: 5
      # 最小连接池数量
      minIdle: 10
      # 最大连接池数量
      maxActive: 20
      # 配置获取连接等待超时的时间
      maxWait: 60000
      # 配置连接超时时间
      connectTimeout: 900000
      # 配置网络超时时间
      socketTimeout: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      timeBetweenEvictionRunsMillis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      minEvictableIdleTimeMillis: 900000
      # 配置一个连接在池中最大生存的时间,单位是毫秒
      maxEvictableIdleTimeMillis: 900000
      # 配置检测连接是否有效
      validationQuery: SELECT 1
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false

Idea 配置方法

使用方法 

在需要新建的文件夹路径,右键选择新建

 上图中此内容为头部注释配置

#parse("Controller Header.java")

 头部注释配置

Mybatis-Plus 是一个 Mybatis 的增强工具,在使用 Mybatis-Plus 之前需要先配置 Mybatis。以下是在 Mybatis-Plus 中添加配置的步骤: 1. 添加依赖 在 pom.xml 文件中添加以下依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.2</version> </dependency> ``` 2. 配置数据源 在 application.ymlapplication.properties 文件中配置数据源信息,例如: ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver ``` 3. 配置 Mybatis 在 application.ymlapplication.properties 文件中添加以下配置: ```yaml mybatis: mapper-locations: classpath*:mapper/*.xml configuration: map-underscore-to-camel-case: true ``` 其中,mapper-locations 属性指定了 Mapper 文件的位置,configuration 属性指定了 Mybatis 的全局配置。 4. 配置 Mybatis-Plus 在 application.ymlapplication.properties 文件中添加以下配置: ```yaml mybatis-plus: mapper-locations: classpath*:mapper/*.xml configuration: map-underscore-to-camel-case: true ``` 其中,mapper-locations 属性和 Mybatis 的配置相同,configuration 属性可以配置 Mybatis-Plus 的全局配置。 5. 配置代码生成器(可选) Mybatis-Plus 提供了代码生成器,可以根据数据表生成实体类Mapper 接口和 XML 文件。在 pom.xml 文件中添加以下依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.4.2</version> </dependency> ``` 在 application.ymlapplication.properties 文件中添加以下配置: ```yaml mybatis-plus: generator: # 全局配置 global-config: author: yourname output-dir: src/main/java file-override: true open: false # 数据源配置 datasource: url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver # 包配置 package-info: parent: com.example.demo moduleName: model entity: model.entity mapper: model.mapper service: model.service serviceImpl: model.service.impl controller: model.controller # 策略配置 strategy: naming: underline_to_camel include: sys_user entityLombokModel: true ``` 其中,generator 属性配置了代码生成器的全局配置、数据源配置、包配置和策略配置。需要根据实际情况进行修改。 以上是在 Mybatis-Plus 中添加配置的步骤,根据实际情况可以选择需要的配置。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值