Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 30a622e

Browse files
committed
update README.md
1 parent 0126feb commit 30a622e

File tree

2 files changed

+65
-62
lines changed

2 files changed

+65
-62
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,73 @@ if (violations.nonEmpty) {
5555
}
5656
```
5757

58+
## Use it like SpringBoot
59+
60+
> It does not support annotations with group parameters and only supports scala 3!
61+
62+
Add the following code to `build.sbt`:
63+
```scala
64+
libraryDependencies ++= Seq(
65+
"org.bitlap" %% "validation-scala-core" % "latest version",
66+
// "org.bitlap" %% "validation-scala-ext" % "latest version", // for zio
67+
)
68+
autoCompilerPlugins := true
69+
addCompilerPlugin("org.bitlap" %% "validation-scala-plugin" % "latest version")
70+
```
71+
72+
### `@Validated`
73+
74+
Add `@Validated` to method:
75+
```scala
76+
import bitlap.validation.extension.Validated
77+
78+
@Validated def update(person1: Person, person2: Person)
79+
```
80+
Then, checking code will be automatically inserted during compilation and may throw an `IllegalArgumentException` if the constraint checking fails.
81+
82+
If you do not wish to throw an exception directly, you should use `@ValidBinding`.
83+
84+
### `@ValidBinding`
85+
86+
Just need to add `@ValidBinding` to method, and add a `bind: BindingResult` parameter to method:
87+
```scala
88+
import bitlap.validation.extension.ValidBinding
89+
90+
@ValidBinding def update(person1: Person, person2: Person, bind: BindingResult = BindingResult.default)
91+
```
92+
93+
The plugin captures the `bind` parameters based on the type, so the name doesn't matter.
94+
95+
### Cascade Validation
96+
97+
```scala
98+
@Validated def validatedTwoParams(@Valid person1: Person, @Valid person2: Person): String
99+
100+
@Validated def validatedOneParams(@Valid person1: Person): String
101+
102+
@ValidBinding def validatedBindParams(@Valid person1: Person, bindingError: BindingResult = BindingResult.default): String
103+
104+
@Validated def validatedNotNullParams(@Valid @NotNull person1: Person): String
105+
```
106+
107+
### Non-Cascade Validation
108+
109+
```scala
110+
@Validated def validatedNotNullParams(@NotNull person1: Person): String
111+
112+
@Validated def validatedNotEmptyParam(@NotBlank name: String): String
113+
```
114+
115+
### Limitation
116+
117+
- Only instance methods of classes are supported due to the limitations of jakarta
118+
- Overloading methods with the same number of parameters are not supported.
119+
58120
## Other information
59121

60-
1. [Use it like SpringBoot](./docs/ext.md)
61-
2. [Support annotations](./docs/support-annotations.md)
122+
1. [Supported Annotations](./docs/support-annotations.md)
123+
2. [Normal Examples](./examples/src/main/scala/bitlap/validation/examples/PersonNormalService.scala)
124+
3. [ZIO Examples](./examples/src/main/scala/bitlap/validation/examples/PersonZioService.scala)
62125

63126
## Inspired by
64127

docs/ext.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)