vaadin/hilla
GitHub: vaadin/hilla
Hilla 是一个将 Spring Boot 与 React/TypeScript 无缝集成的全栈 Web 框架,通过自动类型生成实现前后端类型安全的服务端通信。
Stars: 984 | Forks: 79
Hilla
现代 Web 框架
专为 Java 打造

[](https://github.com/vaadin/hilla/releases)
[官网](https://vaadin.com/hilla) · [文档](https://vaadin.com/docs/latest/hilla) · [论坛](https://vaadin.com/forum/c/hilla/18)
Hilla 将 Spring Boot Java 后端与响应式 TypeScript 前端集成在一起。它通过类型安全的服务器通信、内置的 UI 组件以及集成的工具,帮助您更快地构建应用。
## 简单且类型安全的服务器通信
Hilla 通过类型安全的 endpoint 帮助您轻松访问后端。
`index.ts`
```
// Type info is automatically generated based on Java
import Person from 'Frontend/generated/com/vaadin/hilla/demo/entity/Person';
import { PersonService } from 'Frontend/generated/endpoints';
async function getPeopleWithPhoneNumber() {
const people: Person[] = await PersonService.findAll();
// Compile error: The property is 'phone', not 'phoneNumber'
return people.filter((person) => !!person.phoneNumber);
}
console.log('People with phone numbers: ', getPeopleWithPhoneNumber());
```
`PersonService.java`
```
@BrowserCallable
@AnonymousAllowed
public class PersonService {
private PersonRepository repository;
public PersonService(PersonRepository repository) {
this.repository = repository;
}
public @Nonnull List<@Nonnull Person> findAll() {
return repository.findAll();
}
}
```
`Person.java`
```
@Entity
public class Person {
@Id
@GeneratedValue
private Integer id;
@Nonnull private String firstName;
@Nonnull private String lastName;
@Email @Nonnull private String email;
@Nonnull private String phone;
// getters, setters
}
```
在 [vaadin.com/hilla](https://vaadin.com/hilla) 了解更多
## 开始使用
请按照 https://vaadin.com/docs/latest/getting-started 上的教程进行操作
### 开发
如果您想开发 Hilla,可以克隆代码仓库并使用以下命令运行测试:
```
git clone https://github.com/vaadin/hilla.git
npm install
npm run build
mvn clean spotless:apply install -DskipTests
npm test
mvn verify -Pproduction
```
您需要以下版本的 SDK 和工具:
- **Node.js**: `>= 22 LTS`,
- **npm**: `>=10`(`package-lock.json` 为版本 3)
- **JDK**: `>=17`
- **Maven**: `>=3`
### 在本地测试更改
Java 模块位于 `./packages/java`。如果您对 Java 代码进行了修改,并希望在真实应用中对其进行测试,可以在应用的 `pom.xml` 中将 Vaadin 版本设置为 `SNAPSHOT`。这需要使用 Vaadin 的预发布仓库。请确保在您的 `pom.xml` 中添加以下内容:
```
vaadin-prereleases
https://maven.vaadin.com/vaadin-prereleases
true
Vaadin Directory
https://maven.vaadin.com/vaadin-addons
false
vaadin-prereleases
https://maven.vaadin.com/vaadin-prereleases
true
```
TypeScript 模块位于 `./packages/ts`。如果您对 TypeScript 代码进行了修改,可以在修改后的 package 中运行以下命令,在本地打包您的更改:
```
npm run build && npm pack
```
它将在 package 根目录下创建一个 `.tgz` 文件。然后,在您的应用中,可以使用以下命令安装该 package:
```
npm install
```
测试完成后,请记得删除 `package.json` 中指向该 package 的行。下次运行时会自动重新添加对应的默认 package。
[](https://github.com/vaadin/hilla/actions/workflows/validation.yml)
[](https://codecov.io/gh/vaadin/hilla)标签:JS文件枚举, MITM代理, React, Spring Boot, Syscalls, TypeScript, Web开发框架, 域名枚举, 安全插件, 类型安全