springboot项目创建整个完成过程和注意事项

news2024/10/6 16:18:41

1:application.yml文件配置

server:
  port: 8088
  servlet:
    context-path: /test
spring:
  datasource:
    name: text  #????
    url: jdbc:mysql://localhost:3306/dsdd?serverTimezone=GMT&useUnicode=true&characterEncoding=utf-8&useSSL=true
    username: root  #??
    password: root  #??
    #要添加mysql-connector-java依赖
    driver-class-name: com.mysql.cj.jdbc.Driver  #????com.mysql.jdbc.Driver


mybatis-plus:
  #这个作用是扫描xml文件生效可以和mapper接口文件使用,如果不加这个就是启动类加了@MapperScan
  #或者在mapper接口添加@Mapper都无法使用xml中的sql语句和默认的BaseMapper的语句
  mapper-locations: classpath*:com/example/poi/mapper/**/xml/*Mapper.xml
  global-config:
    # 关闭MP3.0自带的banner
    banner: false
    db-config:
      #主键类型
      id-type: ASSIGN_ID
      # 默认数据库表下划线命名
      table-underline: true
  configuration:
    # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    # 返回类型为Map,显示null对应的字段
    call-setters-on-nulls: true

2:pom.xml文件依赖管理,web服务必须按以下依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>poi</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>poi</name>
    <description>poi</description>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>

        <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.13</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

    </build>

</project>

注意:1-使用web服务controller访问必须导入以下依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

注意:2-使用mybatis必须导入以下依赖

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>

注意:3-打开项目的target目录,观察里面是否有对应的××Mapper.xml文件,若没有,则在pom.xml文件中加入如下配置

		<resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

3:项目结构图

在这里插入图片描述

4:启动类

package com.example.poi;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan(basePackages = "com.example.poi.mapper")
public class PoiApplication {
    public static void main(String[] args) {
        SpringApplication.run(PoiApplication.class, args);
    }
}

5:controller类

package com.example.poi.controller;

import com.example.poi.service.ITest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author xu
 * @create 2023/7/5 01
 */

@RestController
@RequestMapping("/customDemo")
public class DemoTwoController {

    @Resource
    ITest iTest;

    @GetMapping("/export")
    public void exportExcel(HttpServletResponse response) {

        String age = "20";
        String phone = iTest.getPhone(age);
    }
}

6:service和impl类

package com.example.poi.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.poi.entity.EntityDemo;

/**
 * @Author xu
 * @create 2023/7/14 22
 */
public interface ITest extends IService<EntityDemo> {

    String getPhone(String age);

}

package com.example.poi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.poi.entity.EntityDemo;
import com.example.poi.mapper.TestMapper;
import com.example.poi.service.ITest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author xu
 * @create 2023/7/14 22
 */
@Service
public class TestImpl extends ServiceImpl<TestMapper, EntityDemo> implements ITest {

    @Resource
    TestMapper testMapper;

    @Override
    public String getPhone(String age) {

        EntityDemo list = testMapper.selectName();

        this.baseMapper.selectOne(new LambdaQueryWrapper<EntityDemo>().eq(EntityDemo::getAge, age));


        return "entityDemo.getPhone()";
    }
}

7:mapper类和xml文件

package com.example.poi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.poi.entity.EntityDemo;

/**
 * @Author xu
 * @create 2023/7/14 22
 */
//@Mapper
public interface TestMapper  extends BaseMapper<EntityDemo> {


    //@Select("select * from entity_demo where age='20'")
    EntityDemo selectName();
}

<?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.example.poi.mapper.TestMapper">

    <select id="selectName" resultType="com.example.poi.entity.EntityDemo">
        select * from entity_demo where age='20'
    </select>
</mapper>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/767992.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

java模拟MQTT客户端发送消息及EMQX配置

EMQX配置 登录地址 首先打开EMQX的管理界面&#xff0c;界面的地址如下&#xff0c; http://192.168.1.110:18083/ 规则是IP就是MQTT的IP&#xff0c;端口是固定的18083&#xff0c;输入该地址后&#xff0c;展示界面如下&#xff1a; 然后输入用户名和密码&#xff0c;用户…

0132 数据的表示和运算1

目录 2.数据的表示和运算 2.1数制与编码 2.1部分习题 2.数据的表示和运算 2.1数制与编码 2.1部分习题 1.若定点整数为64位&#xff0c;含1位符号位&#xff0c;则采用补码表示的最大值最大的负数为&#xff08;&#xff09; A. B. C. D. 2.若x的补…

戴佩妮《随风所遇》世界巡回演唱会内地首站八月启动,乘风归来,相遇之约!

今日&#xff0c;戴佩妮(Penny)《随风所遇2023 Drift World Tour》世界巡回演唱会正式官宣内地首站&#xff0c;8月26日登陆南京太阳宫剧场。自2016年《贼》世界巡回演唱会之后&#xff0c;华语乐坛唱作人戴佩妮乘著所有粉丝期待的“风”回来&#xff0c;并带来曲目、造型等方面…

如何理解操作系统?(Operator System)

文章目录 一.什么是操作系统二.操作系统的层状结构三.操作系统如何管理 一.什么是操作系统 先入为主&#xff0c;操作系统是一款管理软件 操作系统分为两部分 操作系统本身&#xff0c;主要做一些进程管理、内存管理、文件管理、驱动管理等工作&#xff0c;这种核心部分叫做…

归并排序递归与非递归

基本思想 归并排序&#xff08;MERGE-SORT&#xff09;是建立在归并操作上的一种有效的排序算法,该算法是采用分治法&#xff08;Divide andConquer&#xff09;的一个非常典型的应用。将已有序的子序列合并&#xff0c;得到完全有序的序列&#xff1b;即先使每个子序列有序&a…

Jenkins (二)

Jenkins (二) 使用pipeline script 简单编译 发布war工程到远程tomcat中 配置所需 下载 apache-maven-3.9.3.tar.gz 解压 apache-maven-3.9.3-bin.tar.gz 拷贝到 docker jenkins 镜像里 $ docker cp apache-maven-3.9.3 37259c708ca1:/home/下载apache-tomcat-8.5.91.tar.gz …

压测工具之JMeter使用

文章目录 前言压测工具如何使用启动JMeter工具开始创建测试环境1、创建线程组2、配置元件3、构造HTTP请求4、添加HTTP请求头信息 5、添加断言6、添加查看结果树7、添加聚合报告信息8、测试计划创建完成了 执行测试计划 前言 最近公司项目需要进行压测&#xff0c;查验S A A S …

7.18训练总结

考场错误&#xff1a; 今天是一套neerc的题&#xff0c;难度相对较大&#xff0c;我犯的低级错误比较少&#xff0c;但是对于题目顺序的把握能力&#xff0c;应该提高&#xff0c;尝试去做自己擅长的题目&#xff0c;而不是跟着别人的开题顺序&#xff0c;这样能够更顺畅吧。 …

实验室LIMS系统检测工作流程

LIMS系统检测工作流程 检测工作流程是LIMS核心内容&#xff0c;通过检测工作管理可加强协同工作能力、进一步强化质量控制环节、提高数据报出速度&#xff0c;提高工作效率、减低数据出错率&#xff0c;保证质量记录的完整、监控规范的执行&#xff1b;检测流程以样品检测为主…

Jenkins | 获取凭证密码

目录 方法一&#xff1a;查看所有账号及密码 方法二&#xff1a;查看指定账号密码 方法一&#xff1a;查看所有账号及密码 Jenkins > 系统管理 > 脚本命令行 com.cloudbees.plugins.credentials.SystemCredentialsProvider.getInstance().getCredentials().forEach{i…

element-ui message消息提示组件 ①延长提示消息在页面停留时间②提示消息换行

以实现下面的效果为示例 完整代码&#xff1a; let msgList ["数据1被引用", "数据2被引用"];// 使用html的换行标签拼接信息&#xff0c;默认行距太小&#xff0c;此处用两个<br/><br/>let message 以下数据不能删除&#xff0c;原因是&…

【Spring core学习四】Bean作用域和生命周期

目录 一、Bean的作用域 &#x1f308;1、被修改的Bean值现象 &#x1f308;2、 Bean 的 6 种作⽤域 &#x1f308;3、设置作用域 二、Spring的执行流程 三、Bean的生命周期 &#x1f308;1、Bean生命周期的过程 &#x1f308;2、演示生命周期 一、Bean的作用域 &…

[MySql]JDBC编程

JDBC&#xff0c;即Java Database Connectivity&#xff0c;java数据库连接。是一种用于执行SQL语句的Java API&#xff0c;它是Java中的数据库连接规范。这个API由 java.sql.*,javax.sql.* 包中的一些类和接口组成&#xff0c;它为Java开发人员操作数据库提供了一个标准的API&…

全域Serverless化,华为云引领下一代云计算新范式

近日&#xff0c;华为开发者大会2023&#xff08;Cloud&#xff09;在东莞成功举办&#xff0c;期间“全域Serverless化&#xff0c;引领下一代云计算新范式”专题论坛人气满满。华为云首席产品官方国伟携手业界专家、客户、伙伴&#xff0c;面向广大开发者&#xff0c;分享了在…

Authing 身份云上线数据对象管理(元数据),助力企业构建唯一身份源

在身份管理领域&#xff0c;元数据具有重要的作用和价值。元数据有助于理解数据的结构和意义&#xff0c;提升数据处理效率&#xff1b;促进跨部门、跨组织的数据共享和协作&#xff1b;以及支持数据分析&#xff0c;为业务决策提供支持等。当前&#xff0c;Authing 身份云已经…

在ICC/ICC2/FC中运行Calibre

1. which calibre找到calibre的安装目录 > which calibre > /eda/mentor/ixl_cal_version/bin/calibre 2. 在 /eda/mentor/ixl_cal_version目录下使用find ./* -name "icc_calibre.tcl",找到icc_calibre.tcl 3. 打开icc_calibre.tcl里面有不同工具(ICC2/FC/…

《Linux0.11源码解读》理解(五) head之开启分页

先回顾一下地址长度以及组合的演变&#xff1a;16位cpu意味着其数据总线/寄存器也是16位&#xff0c;但是地址总线&#xff08;寻址能力&#xff09;与此无关&#xff0c;可能是20位。可以参考&#xff1a;cpu的位宽、操作系统的位宽和寻址能力的关系_cpu位宽_brahmsjiang的博客…

C++——map和set(multimap和multiset)

目录 1.关联式容器 2.键值对 3.树形结构的关联式容器 3.1 set 3.1.1 set的介绍 3.1.2 set的使用 3.2 multiset 3.2.1 multiset的介绍 3.2.2 multiset的使用 3.3 map 3.3.1 map的介绍 3.3.2 map的使用 3.4 multimap 3.4.1 multimap的介绍 3.4.2 multimap的使用 …

抖音小店选品攻略:10个技巧助你选择助轻松学会选品技巧

抖音小店是目前非常火爆的电商平台之一&#xff0c;许多商家都希望能在抖音上开设自己的小店。而在开设抖音小店之前&#xff0c;选品是一个非常重要的环节。下面是不若与众总结的一些抖音小店选品技巧&#xff0c;希望能帮助到你。 1. 确定目标受众&#xff1a;在选品之前&…

数据库应用:MySQL高级语句

目录 一、理论 1.常用查询 2.函数 3.进阶查询 二、实验 1.普通查询 2.函数 3.进阶查询 三、问题 1.MySQL || 运算符不生效 四、总结 一、理论 1.常用查询 常用查询包括&#xff1a;增、删、改、查&#xff1b; 对 MySQL 数据库的查询&#xff0c;除了基本的查询外…