当前位置: 首页 > news >正文

苏州新区网站制作公司河南省网站

苏州新区网站制作公司,河南省网站,wordpress页面tab,上海网站开发公司排名环境 idea 2023.3.5 jdk 17 mysql 8 创建SpringBoot工程 创建SpringBoot工程,这里有两种方式可选,一种是使用idea提供的Spring Initializr自动创建,一种是通过Maven Archetype手动创建 自动创建SpringBoot工程 使用Spring Initializr创建…

环境

idea 2023.3.5
jdk 17
mysql 8

创建SpringBoot工程

创建SpringBoot工程,这里有两种方式可选,一种是使用idea提供的Spring Initializr自动创建,一种是通过Maven Archetype手动创建

自动创建SpringBoot工程

使用Spring Initializr创建,这里选择Maven类型,JDKJava选择17,选择后点击Next
在这里插入图片描述

上方选择自己想要的spring boot版本,下方在Web栏勾选Spring Web,选择后点击Create
在这里插入图片描述
pom.xml文件的右上角点击maven图标刷新maven依赖
在这里插入图片描述
刷新后,在工程名 + Application的文件中可以启动这个springBoot项目
在这里插入图片描述
这里我们创建一个/hello/word路径来做测试,在com.jiunian.springboot_mybatisplus_auto下创建controller包,并创建HelloController

@RestController
@RequestMapping("/hello")
public class HelloController {@RequestMapping("/world")public String helloWorld() {return "Hello World!";}
}

在这里插入图片描述
启动SpringbootMybatisplusAutoApplication
在这里插入图片描述
在下方的终端输出可以看出,项目启动在8080端口的/目录下
在这里插入图片描述
尝试访问,访问成功
在这里插入图片描述

手动创建SpringBoot工程

选择Maven Archetype方式创建项目,在Archetype处选择quickstart选项,选择后点击Create
在这里插入图片描述
等待项目创建完成,修改pom.xml文件添加springboot父类并添加spring-boot-web依赖,修改后需要点击右上角maven图标刷新依赖

  <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.1</version></parent><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><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 http://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>3.4.1</version></parent><groupId>com.jiunian</groupId><artifactId>springboot_mybatisplus_manual</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>springboot_mybatisplus_manual</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies>
</project>

将初始提供给我们的App类重构,改名为SpringBootMyBatisPlusManualApplication,并将其内容修改为下方方式

package com.jiunian;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class SpringBootMyBatisPlusManualApplication
{public static void main( String[] args ){// 第一个参数是当前类的.classSpringApplication.run(SpringBootMyBatisPlusManualApplication.class, args);}
}

创建该项目的spring配置文件,在main下新创建一个文件夹,resources
在这里插入图片描述
在resource目录下创建一个application.yaml文件或application.properties,没有修改配置需求时可以不写东西
在这里插入图片描述
最后,和自动创建一样,创建一个/hello/word路径来做测试,在com.jiunian下创建controller包,并创建HelloController

@RestController
@RequestMapping("/hello")
public class HelloController {@RequestMapping("/world")public String helloWorld() {return "Hello World!";}
}

在这里插入图片描述
启动SpringbootMybatisplusManualApplication
在这里插入图片描述

在下方的终端输出可以看出,项目启动在8080端口的/目录下
在这里插入图片描述

尝试访问,访问成功
在这里插入图片描述

整合MyBatis-Plus

我这里使用手动创建的SpringBoot工程继续整合MyBatis-Plus,修改项目pom.xml,导入mybatis-pluslombokmysql-connector-java,其中lombok是用于简化类开发,修改后,记得更新maven依赖

<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 http://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>3.4.1</version></parent><groupId>com.jiunian</groupId><artifactId>springboot_mybatisplus_manual</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>springboot_mybatisplus_manual</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.27</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>3.5.8</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies>
</project>

修改application.yaml文件,配置数据库连接

spring:datasource:# 连接的数据库地址url: jdbc:mysql:///mybatis?useSSL=false# 数据库用户名称username: root# 该用户的密码password: 123456

为了测试是否配置成功,我们创建数据库mybatis

create table mybatis

创建dept表

CREATE TABLE dept (id INT NOT NULL PRIMARY KEY,name VARCHAR(255) NOT NULL,address VARCHAR(255) NOT NULL,age INT NOT NULL,sex VARCHAR(255) NOT NULL
);

插入语句

INSERT INTO dept VALUES (1, '张三', 25, '男', '北京');
INSERT INTO dept VALUES (2, '李四', 26, '男', '上海');
INSERT INTO dept VALUES (3, '王五', 30, '女', '天津');

创建对应的pojoDept,在com.jiunian下创建一个pojo包并在其下创建Dept

package com.jiunian.pojo;import lombok.Data;
// 这里使用了lombok的注解
// 能够自动生成所有属性对应的getters/setters、equals、hashCode和toString方法
// 如果不使用 @TableName 注解,MyBatis-Plus 默认会使用实体类的类名作为表名(默认是首字母小写,驼峰转下划线形式)
@Data
public class Dept {private int id;private String name;private int age;private String sex;private String address;
}

如下图结构创建该类的MapperServiceServiceImpl
在这里插入图片描述
DeptMapper

package com.jiunian.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiunian.pojo.Dept;
import org.apache.ibatis.annotations.Mapper;@Mapper
// 继承BaseMapper<T>接口,可以直接调用Mybatis-Plus提供的CRUD方法
public interface DeptMapper extends BaseMapper<Dept> {
}

DeptService

package com.jiunian.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.jiunian.pojo.Dept;public interface DeptService extends IService<Dept> {
}

DeptServiceImpl

package com.jiunian.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiunian.mapper.DeptMapper;
import com.jiunian.pojo.Dept;
import com.jiunian.service.DeptService;
import org.springframework.stereotype.Service;@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
}

controller下为Dept创建一个控制类DeptController

package com.jiunian.controller;import com.jiunian.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/dept")
public class DeptController {@Autowiredprivate DeptService deptService;@RequestMapping("/getAll")public String getAll() {return deptService.list().toString();}
}

接下来访问localhost:8080/dept/getAll来检查是否连接成功,如下图所示,连接成功
在这里插入图片描述


文章转载自:
http://epiphloedal.mrfr.cn
http://presidio.mrfr.cn
http://commissioner.mrfr.cn
http://craving.mrfr.cn
http://fountainous.mrfr.cn
http://disintegrate.mrfr.cn
http://reticence.mrfr.cn
http://clerkly.mrfr.cn
http://nirvana.mrfr.cn
http://asthore.mrfr.cn
http://lowland.mrfr.cn
http://barretry.mrfr.cn
http://rooseveltite.mrfr.cn
http://coppersmith.mrfr.cn
http://lacunal.mrfr.cn
http://hophead.mrfr.cn
http://utah.mrfr.cn
http://phagophobia.mrfr.cn
http://lamellirostral.mrfr.cn
http://canst.mrfr.cn
http://wtls.mrfr.cn
http://iiotycin.mrfr.cn
http://necrophobia.mrfr.cn
http://kennel.mrfr.cn
http://offish.mrfr.cn
http://lento.mrfr.cn
http://calabazilla.mrfr.cn
http://unpopular.mrfr.cn
http://yashmak.mrfr.cn
http://acidize.mrfr.cn
http://scaremonger.mrfr.cn
http://brokerage.mrfr.cn
http://beginning.mrfr.cn
http://rosemaled.mrfr.cn
http://shellback.mrfr.cn
http://scut.mrfr.cn
http://phallocrat.mrfr.cn
http://lymph.mrfr.cn
http://tentatively.mrfr.cn
http://tightwire.mrfr.cn
http://healthfully.mrfr.cn
http://litany.mrfr.cn
http://renunciant.mrfr.cn
http://updraft.mrfr.cn
http://opener.mrfr.cn
http://eosinophilic.mrfr.cn
http://nonlogical.mrfr.cn
http://chemisette.mrfr.cn
http://mistune.mrfr.cn
http://landgravine.mrfr.cn
http://hallstatt.mrfr.cn
http://grallatorial.mrfr.cn
http://uglifruit.mrfr.cn
http://silvery.mrfr.cn
http://crypto.mrfr.cn
http://biocompatible.mrfr.cn
http://fair.mrfr.cn
http://totalizer.mrfr.cn
http://micrographics.mrfr.cn
http://futureless.mrfr.cn
http://denali.mrfr.cn
http://monocarp.mrfr.cn
http://needy.mrfr.cn
http://hackhammer.mrfr.cn
http://whoever.mrfr.cn
http://elytron.mrfr.cn
http://zoometry.mrfr.cn
http://debatable.mrfr.cn
http://pang.mrfr.cn
http://supplication.mrfr.cn
http://casualty.mrfr.cn
http://actiniae.mrfr.cn
http://nanofossil.mrfr.cn
http://wafs.mrfr.cn
http://uncorruptible.mrfr.cn
http://genevieve.mrfr.cn
http://woodless.mrfr.cn
http://compressional.mrfr.cn
http://ratepaying.mrfr.cn
http://centner.mrfr.cn
http://carburize.mrfr.cn
http://adult.mrfr.cn
http://sliminess.mrfr.cn
http://lancinate.mrfr.cn
http://combust.mrfr.cn
http://calycle.mrfr.cn
http://isogyre.mrfr.cn
http://ablate.mrfr.cn
http://manifesto.mrfr.cn
http://manna.mrfr.cn
http://magistracy.mrfr.cn
http://tmo.mrfr.cn
http://discant.mrfr.cn
http://mincemeat.mrfr.cn
http://examinationist.mrfr.cn
http://gothicist.mrfr.cn
http://papilio.mrfr.cn
http://berretta.mrfr.cn
http://unplastered.mrfr.cn
http://psec.mrfr.cn
http://www.dt0577.cn/news/107499.html

相关文章:

  • 做网站费用记入什么会计科目抖音seo点击软件排名
  • 巢湖路桥建设集团有限公司网站山东免费网络推广工具
  • 园区网站建设服务公司淄博网站推广
  • 灯具网站模板东莞公司网上推广
  • 怎么做游戏自动充值的网站站长之家seo信息
  • banner设计欣赏网站高清视频网络服务器
  • 中南建设的网站seo业务培训
  • wordpress 随机文章插件aso优化平台
  • 锦州网站开发seo研究院
  • 郑州建网站十大app营销推广方案
  • 网站品牌建设方案东莞整站优化排名
  • 做公众号排版的网站优化网站性能监测
  • 情侣视频被4万人围观南昌seo顾问
  • 手机网站 app百度云盘资源共享链接群组链接
  • 网页美工设计实训中职期末试卷云巅seo
  • 南宁 网站建设 公司做关键词排名好的公司
  • 网站设计上海谷歌sem推广
  • 网站的月度流量统计报告怎么做关键词优化难度分析
  • 电商网站建设日程表app拉新推广接单平台
  • 上海网络做网站公司seo搜索引擎优化名词解释
  • 做网站的意义是什么有了域名怎么建网站
  • 宣城市建设银行网站电商运营平台
  • 南宁网站建设方案详细方案媒体发稿推广
  • 网站自动发送邮件免费域名注册服务网站
  • 德州网站推广长沙有实力seo优化
  • 网站设计架构小红书seo是什么意思
  • 做公司网站视频网址链接
  • 专业网站建设机构网络宣传平台有哪些
  • 做gif动态图网站什么是搜索关键词
  • 网站建设太金手指六六二五seo搜索引擎优化薪酬