`
zysnba
  • 浏览: 179761 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

简单开发springboot搭建

 
阅读更多
1需要引入的jar
repositories {
//    mavenCentral()

    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    //Hikaricp 代号光
    implementation 'com.zaxxer:HikariCP:2.4.7'
    //swagger
    implementation 'io.springfox:springfox-swagger2:2.7.0'
    implementation 'io.springfox:springfox-swagger-ui:2.7.0'
    // mysql
       implementation 'mysql:mysql-connector-java'
    //mybatis
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.2'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}
2配置文件
student.name=nba
student.age=23


swagger.enable=true
#\u65E5\u5FD7
#logging.file.path=./log/文件夹
logging.file=./log/logback.log
logging.level.root=info
logging.register-shutdown-hook=false
logging.config=classpath:logback-spring.xml
logging.file.name
## 数据库配置
#datasource
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/demo?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
##  Hikari 连接池配置 ------ 详细配置请访问:https://github.com/brettwooldridge/HikariCP
## 最小空闲连接数量
spring.datasource.hikari.minimum-idle=5
## 空闲连接存活最大时间,默认600000(10分钟)
spring.datasource.hikari.idle-timeout=180000
## 连接池最大连接数,默认是15
spring.datasource.hikari.maximum-pool-size=15
## 此属性控制从池返回的连接的默认自动提交行为,默认值:true
spring.datasource.hikari.auto-commit=true
## 连接池名称
spring.datasource.hikari.pool-name=DatebookHikariCP
## 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
spring.datasource.hikari.max-lifetime=1800000
## 数据库连接超时时间,默认30秒,即30000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1

#server http://localhost:8080/swagger-ui.html#/

server.port=8080
server.tomcat.max-threads=800
server.tomcat.uri-encoding=UTF-8
#mybatis
mybatis.type-aliases-package=com.test.entity
mybatis.mapper-locations=classpath:mapper/*.xml



3,log日志logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration >
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />



<springProfile name="dev">
     <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
    <root level="INFO">
        <appender-ref ref="FILE" /> <!--将日志输出到文件中-->
        <appender-ref ref="CONSOLE" /> <!--将日志输出到控制台中-->
    </root>
     </springProfile>

      <springProfile name="test">
         <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
     <root level="INFO">
        <appender-ref ref="FILE" />
        <appender-ref ref="CONSOLE" />
    </root>
     </springProfile>
<springProfile name="pro">
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="CONSOLE" />
</root>
</springProfile>
</configuration>




4加入Swagger
package com.test.config;

import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Value("${swagger.enable}")
    private boolean enableSwagger;
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).securitySchemes(Lists.newArrayList(apiKey())).enable(enableSwagger)
                .genericModelSubstitutes(ResponseEntity.class)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.test.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    //token
    private ApiKey apiKey(){
return new ApiKey("token", "authentication", "header");
}
  
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("gradle+springboot 整合swaager2 构建api文档")
                .description("XXX科技有限公司 ,http://www.baidu.com/")
                .termsOfServiceUrl("https://blog.csdn.net/u013783065")
                .version("1.0")
                .build();
    }
}

5,dao接口
public interface UserInfoMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(UserInfo record);

    int insertSelective(UserInfo record);

    UserInfo selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(UserInfo record);

    int updateByPrimaryKey(UserInfo record);
}

5,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.test.dao.UserInfoMapper">
  <resultMap id="BaseResultMap" type="com.test.UserInfo">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="user_id" jdbcType="BIGINT" property="userId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="company_id" jdbcType="BIGINT" property="companyId" />
  </resultMap>
  <sql id="Base_Column_List">
    id, user_id, name, code, company_id
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user_info
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from user_info
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.etonkids.assets.entity.UserInfo">
    insert into user_info (id, user_id, name,
      code, company_id)
    values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
      #{code,jdbcType=VARCHAR}, #{companyId,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="com.etonkids.assets.entity.UserInfo">
    insert into user_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="userId != null">
        user_id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="code != null">
        code,
      </if>
      <if test="companyId != null">
        company_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="companyId != null">
        #{companyId,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.etonkids.assets.entity.UserInfo">
    update user_info
    <set>
      <if test="userId != null">
        user_id = #{userId,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        code = #{code,jdbcType=VARCHAR},
      </if>
      <if test="companyId != null">
        company_id = #{companyId,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.etonkids.assets.entity.UserInfo">
    update user_info
    set user_id = #{userId,jdbcType=BIGINT},
      name = #{name,jdbcType=VARCHAR},
      code = #{code,jdbcType=VARCHAR},
      company_id = #{companyId,jdbcType=BIGINT}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>

















分享到:
评论

相关推荐

    springboot搭建webjsp

    SpringBoot 是一款基于 Spring Framework 的轻量级框架,它简化了 Spring 应用的初始搭建以及开发过程。本篇文章将详细讲解如何利用 SpringBoot 搭建一个支持 JSP(JavaServer Pages)的 Web 应用。 1. **Spring ...

    springboot搭建activiti技术

    SpringBoot 基于 Spring 框架,旨在简化 Spring 应用的初始搭建以及开发过程。它通过自动配置、起步依赖和命令行接口等特性,让开发者能够快速构建可生产的 Spring 应用。 **三、SpringBoot 集成 Activiti** 1. **...

    SpringBoot搭建内容发布系统

    本内容发布系统采用流行的SpringBoot搭建,支持静态化、标签化建站。不需要专业的后台开发技能,会HTML就能建站,上手超简单;只需使用系统提供的标签就能轻松建设网站。全面支持各类表单字段,真正实现“0”代码...

    SpringBoot简单搭建Demo

    在“SpringBoot简单搭建Demo”中,我们可以理解为这是一个演示如何使用SpringBoot快速构建应用的实例。以下是一些关于SpringBoot的关键知识点: 1. **起步依赖(Starter Dependencies)**:SpringBoot的核心特性之...

    基于springboot搭建的个人博客

    1. **起步依赖(Starter Dependencies)**:Spring Boot通过“起步依赖”提供了一种简单的方式来添加所需的库。例如,为了搭建数据库连接,我们可以添加`spring-boot-starter-data-jpa`依赖,这会自动引入JPA、...

    SpringBoot简单搭建教程

    ### SpringBoot简单搭建教程 #### 一、SpringBoot概述与特点 **SpringBoot**是一个由Pivotal团队提供的全新框架,旨在简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式(如通过约定优先于配置)来...

    简单的springboot框架的搭建

    SpringBoot 是一个由 Pivotal 团队开发的框架,旨在简化 Spring 应用程序的初始搭建以及开发过程。它集成了大量常用的第三方库配置,如 JDBC、MongoDB、JPA、RabbitMQ、Quartz 等,使得开发者能够快速地创建一个独立...

    基于SpringBoot搭建的个人博客系统

    【标题】"基于SpringBoot搭建的个人博客系统"揭示了这个项目的核心技术栈,即SpringBoot,这是一种由Pivotal团队提供的快速开发框架,用于简化Spring应用的初始搭建以及开发过程。SpringBoot通过自动化配置、内嵌式...

    springboot+netty开发简易式游戏源码

    在本项目中,"springboot+netty开发简易式游戏源码"是一个使用Spring Boot和Netty框架构建的轻量级游戏服务器的示例。这个项目结合了两个强大的技术,旨在提供一个高效、可扩展的游戏后端解决方案。下面将详细阐述...

    idea springboot环境搭建 mybatis mysql数据库增删改查.zip

    在本教程中,我们将深入探讨如何使用IntelliJ IDEA(简称Idea)搭建SpringBoot环境,并结合MyBatis框架和MySQL数据库实现数据的增、删、改、查操作。这个项目是一个非常适合初学者上手的实例,包含了所有必要的组件...

    idea下,使用SringBoot搭建SSM和JPA和不用SpringBoot搭建SSM和Mybatis映射数据库

    本话题主要探讨如何在IntelliJ IDEA(Idea)环境下,使用SpringBoot搭建基于SSM(Spring、SpringMVC、Mybatis)的传统架构,以及使用JPA(Java Persistence API)进行数据库操作,同时也会对比不使用SpringBoot搭建...

    springboot搭建简单增删查改

    总的来说,"springboot搭建简单增删查改"这个项目涵盖了Spring Boot的基础使用,数据库连接,以及基本的Web开发流程。通过学习和实践这个项目,初学者能够掌握Spring Boot的基本概念,以及如何构建一个简单的CRUD...

    vue UI + SpringBoot 搭建项目框架

    本文将深入探讨如何使用Vue UI与SpringBoot搭建一个完整的项目框架。 Vue.js是一个轻量级的JavaScript框架,它以组件化、易学习、高性能著称。Vue UI则是基于Vue.js的一系列UI组件库,它提供了丰富的界面元素,帮助...

    简单的springboot+mybatisplus搭建

    现在,让我们一起按照以下步骤来搭建这个简单的SpringBoot+MybatisPlus项目。 首先,我们需要创建一个新的Maven项目。在IntelliJ IDEA中,选择"New Project",然后选择"Maven"并填写项目的GroupId、ArtifactId和...

    SpringBoot框架简单搭建并运行

    SpringBoot框架简单搭建并运行是初学者和开发者进入微服务开发领域的常见步骤。Spring Boot是由Pivotal Team创建的一个框架,旨在简化Spring应用的初始搭建以及开发过程,它集成了大量常用的第三方库配置,如数据源...

    简单的SpringBoot+mybatis搭建

    SpringBoot和Mybatis是Java开发中的两个重要框架,SpringBoot简化了Spring应用的初始搭建以及开发过程,而Mybatis则是一个轻量级的持久层框架,专注于SQL映射。本项目是一个适合初学者理解这两种技术如何结合使用的...

    springboot搭建

    在这个项目中,我们将学习如何使用SpringBoot来搭建一个简单的应用程序。 首先,我们需要在本地环境中安装Java开发工具(JDK),因为SpringBoot是建立在Java平台上的。确保你的系统已安装了JDK 8或更高版本,并正确...

    springboot搭建的简单系统wstro-myjob.zip

    该项目利用了基于springboot + vue + mysql的开发模式框架实现的课设系统,包括了项目的源码资源、sql文件、相关指引文档等等。 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理...

    Springboot项目搭建以及整合mybatis——eclipse

    SpringBoot 是一个由 Pivotal 团队开发的框架,旨在简化 Spring 应用的初始搭建以及开发过程。它集成了大量常用的第三方库配置,如 JDBC、MongoDB、JPA、RabbitMQ、Quartz 等,让你可以快速地创建一个独立运行的、...

    基于SpringBoot搭建的一个通用的OA管理系统,以车辆管理为例。技术罗列:SpringBoot,Mybatie.zip

    SpringBoot简化了Spring应用的初始搭建以及开发过程,通过内嵌Tomcat服务器、自动配置Spring组件以及一系列starter,使得开发者可以快速构建出可部署的应用程序。在本项目中,SpringBoot作为基础框架,提供了快速...

Global site tag (gtag.js) - Google Analytics