创建普通maven项目,pom依赖如下

<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.1.4.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</dependency> <!--swagger可视化接口测试,不需要可以不添加-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency> <!--连接数据库需要的-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.6</version>
</dependency> <!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency> </dependencies>

启动类如下:

@SpringBootApplication
@MapperScan(basePackages = "com.hrw.dao")
public class TestApplication { public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}

application.yml配置内容如下:

server:
port: 8009
spring:
application:
name: testSpringBootAndSwagger
datasource:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/ssm2?useUnicode=true&characterEncoding=utf-8&useSSL=true
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver

包结构如下:

如果要写swagger可视化接口的话,除了加swagger依赖之外,还需要一个配置类,配置类放在config包下,如下:

@Configuration
@EnableSwagger2
public class SwaggerConfiguration { @Bean
public Docket buildDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildApiInfo())
.select()
// 要扫描的API(Controller)基础包,记得改成自己对应的包名
.apis(RequestHandlerSelectors.basePackage("com.hrw"))
.paths(PathSelectors.any())
.build();
} private ApiInfo buildApiInfo() {
Contact contact = new Contact("黄大虾","","");
return new ApiInfoBuilder()
.title("测试新建SpringBoot和swagger,API文档")
.description("平台管理服务api")
.contact(contact)
.version("1.0.0").build();
}
}

然后就可以在controller上用swagger注解了,参考controller:

@Api(value = "用户管理TUser",tags = "SwaggerTestController",description = "用户管理API")
@Controller
@RequestMapping("/test")
public class TestController { @Autowired
private TUserService tUserService; /**
* 传入一个id,返回一个id
* @param id
* @return
*/
@ApiOperation("随便传一个id,返回一个id")
@GetMapping("/test1/{id}")
public String test1(@PathVariable(value = "id") Integer id){
return "id =" + id;
} /**
* 传入一个TUser对象,返回一个对象
* @param user
* @return
*/
@ApiOperation("根据用户对象查询一个用户,查询依据是对象内的id")
@ResponseBody
@PostMapping(value = "/test2")
public TUser test2(@RequestBody TUser user){
TUser tUser = tUserService.queryUserById(user);
return tUser;
} /**
* 修改用户信息
* @param tUser
* @return
*/
@ApiOperation("传入一个TUser,用来修改用户信息,必须要有id值")
@ResponseBody
@PostMapping(value = "update")
public String updateUser(@RequestBody TUser tUser){
int i = tUserService.updateById(tUser);
System.out.println("i = " + i);
return i>0?"修改成功":"修改失败";
} /**
* 添加一个用户
* @param tUser
* @return
*/
@ApiOperation("添加一个用户对象,没有的参数则不添加")
@ResponseBody
@PostMapping(value = "/add")
public TUser addUser(@RequestBody TUser tUser){
TUser user = tUserService.add(tUser);
return user;
}
}

里面功能实现,需要自己完成。。。

启动启动类之后,浏览器打开http://localhost:8009/swagger-ui.html,就可以看到swagger的效果了

ok,,,然后就可以愉快的进行增删改查了

快速创建springboot项目,并进行增删改的更多相关文章

  1. 2springboot:快速创建springboot项目

    使用IDEA快速创建springboot项目流程: 创建新的项目选择 项目的命名以及包名 需要什么包就导入什么包 进行测试的单元 <dependency> <groupId>o ...

  2. Spring-boot(一)通过向导快速创建Spring-boot项目

    通过向导快速创建Spring-boot项目 创建步骤: 选择Spring Initializr 填写组织和模块名 选择对应的模块 注:这里左侧的模块比较多,玩家可以根据自己的实际需要自由选择,此处暂时 ...

  3. 【快学springboot】1.快速创建springboot项目

    若图片查看异常,请前往掘金查看:https://juejin.im/post/5d00e793f265da1b614ff10b 使用spring initialize工具快速创建springboot项 ...

  4. SpringBoot入门系列(一)如何快速创建SpringBoot项目

    这段时间也没什么事情,所以就重新学习整理了Spring Boot的相关内容.今天开始整理更新Spring Boot学习笔记,感兴趣的朋友可以关注我的博客:https://www.cnblogs.com ...

  5. 在线快速创建SpringBoot项目

    都2020年了,你还在手动创建SpringBoot项目吗?今天教你在线快速创建一个SpringBoot项目,瞬间高大上有木有! 进入正题,首先打开创建SpringBoot的官网:https://sta ...

  6. 3 快速创建SpringBoot项目

    一.Intellij IDEA 创建Spring Boot项目 1.创建工程  2.选择Spring Initializr 3.设置Maven版本管理参数  4.选择引用模块  5.命名工程名 6.选 ...

  7. 2.快速创建springboot项目 连pom文件里面的配置都不用配了

    无论是创建项目 还是module 模块 选择这个 .然后在后面的选择中选择自己要的功能 就可以把相关的依赖都加进去 省去了依赖 其后的写法跟第一篇一样 在这个项目下面有一个配置文件 ====>a ...

  8. 使用spring initialization创建SpringBoot项目

    https://blog.csdn.net/liutong123987/article/details/79385513 有很多方法可以快速创建Springboot项目,可以通过idea的spring ...

  9. SrpingBoot入门到入坟03-基于idea快速创建SpringBoot应用

    先前先创建Maven项目然后依照官方文档再然后编写主程序写业务逻辑代码才建立好SpringBoot项目,这样太过麻烦,IDE都支持快速创建,下面基于idea: 使用Spring Initializer ...

随机推荐

  1. synchronized真的很重么?

    synchronized 是java中常见的保证多线程访问共享资源时的安全的一个关键字.很多人在讲到synchronized 时都说synchronized 是一把重量级的锁,那么synchroniz ...

  2. C语言- 基础数据结构和算法 - 循环链表

    听黑马程序员教程<基础数据结构和算法 (C版本)>,照着老师所讲抄的, 视频地址https://www.bilibili.com/video/BV1vE411f7Jh?p=1 喜欢的朋友可 ...

  3. 合宙AIR105(四): SPI, MAX7219 8x8LED驱动

    目录 合宙AIR105(一): Keil MDK开发环境, DAP-Link 烧录和调试 合宙AIR105(二): 时钟设置和延迟函数 合宙AIR105(三): 定时器, 定时器中断和PWM输出 合宙 ...

  4. BUUCTF-FLAG

    FLAG 16进制打开没看到有什么东西,使用binwalk分离也没看到其他文件,猜测是否使用lsb隐写方式. StegSolve打开 可以看到是压缩包的文件头,save bin保存为zip文件解压 提 ...

  5. 关键字——this,super,static,final

    this 理解为当前对象. //测试 public static void main(String[] args){ Person person = new Person(3, "xiaoM ...

  6. Nginx开机自启

    编写service脚本: vim /usr/lib/systemd/system/nginx.service 将以下内容复制到nginx.service文件中 ps:我的nginx目录是/usr/lo ...

  7. JS中通过Input中id获取输入框中的值

    HTML中 <input type="text" id="ONE" oninput="kpi()"> JS中 function ...

  8. 链表设计与Java实现,手写LinkedList这也太清楚了吧!!!

    链表设计与实现 在谈链表之前,我们先谈谈我们平常编程会遇到的很常见的一个问题.如果在编程的时候,某个变量在后续编程中仍需使用,我们可以用一个局部变量来保存该值,除此之外一个更加常用的方法就是使用容器了 ...

  9. windows 安全

    Windows基础篇html { overflow-x: initial !important } :root { --bg-color: #ffffff; --text-color: #333333 ...

  10. 【跟着大佬学JavaScript】之lodash防抖节流合并

    前言 前面已经对防抖和节流有了介绍,这篇主要看lodash是如何将防抖和节流合并成一个函数的. 初衷是深入lodash,学习它内部的好代码并应用,同时也加深节流防抖的理解.这里会先从防抖开始一步步往后 ...