idea:new没有class

idea:new没有class

重装环境后,做了个springboot测试,new controller时发现new选项中没有class。怎么办呢?

解决方案:

  1. File –project structure
    这里写图片描述

  2. project setting 中选取modules
    这里写图片描述

3.点击项目src目录
这里写图片描述
4.点击上面的source按钮,将选定目录设置为源码目录
这里写图片描述
5. 查看右侧的源码目录,OK
这里写图片描述

查看效果:
这里写图片描述

### 使用 IntelliJ IDEA 开发 Spring Boot 应用程序 #### 创建一个新的 Spring Boot 项目 为了创建一个基于 Spring 的应用程序,在启动 IntelliJ IDEA 后,选择 `File` -> `New` -> `Project...`. 接下来,选择左侧列表中的 `Spring Initializr`, 这样可以利用官方提供的服务来初始化项目配置[^1]. 对于依赖项的选择,如果目标是构建 Web 应用,则应加入 `Spring Web`; 若计划连接 MySQL 数据库,则需添加 `Spring Data JPA` 和 `MySQL Driver` 作为依赖。 #### 配置 application.properties 文件 在 resources 文件夹下找到并编辑名为 `application.properties` 或者 `application.yml` 的文件。这里设置数据库连接参数以及其他必要的属性。例如: ```properties spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useSSL=false&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=password spring.jpa.hibernate.ddl-auto=update ``` 这段代码片段展示了如何指定数据源 URL、用户名以及密码,并告知 Hibernate 自动更新模式以匹配实体类结构的变化[^2]. #### 编写简单的 RESTful API 控制器 下面是一个非常基础的例子,它定义了一个控制器用于处理 HTTP 请求: ```java package com.example.demo; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") public String hello() { return "Hello, world!"; } } ``` 此段 Java 代码实现了当访问 `/hello` 路径时返回字符串 `"Hello, world!"`.
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值