跪拜 Guibai
← All articles
Frontend · Backend · Java

Front-end to Java full-stack in 2 days: AI-assisted Demo delivery with all the pitfalls

By Rain的Java大神之路 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The two-day AI-assisted demo approach offers a repeatable path for front-end developers facing backend deadlines, and the 24-item pitfall checklist compresses months of field experience into actionable saves. The OpenAPI-to-TypeScript contract generation and JWT/Security gotchas directly apply to any team mixing Spring Boot with a modern front-end.

Summary

Front-end developers facing a deadline don't need to learn Java first. A colleague's twice-completed transition shows the winning move is mapping existing front-end mental models onto the Spring ecosystem—Express routes become @RestController, npm install becomes Maven pom.xml, composables become Services—and letting AI translate the boilerplate while the developer guards contracts, layering, transactions, and validation.

The article lays out a concrete 30-minute minimal loop: Spring Initializr + H2 + JPA for the backend, Vue3 + Vite for the frontend, curl smoke tests before page-based debugging, and a three-point acceptance criterion that includes one-command startup on a fresh clone. For data access, JPA suits demos while MyBatis-Plus is the domestic-business mainstream, with a critical warning about the Boot 3 starter.

Beyond the demo, it covers production-readiness steps (MySQL, HikariCP, Flyway, Nginx, observability), JWT/Spring Security pitfalls like the OPTIONS preflight block and jjwt 0.12 API changes, and a 24-row pitfall table that includes JAVA_HOME misconfiguration, transaction self-invocation invalidation, MyBatis-Plus pagination plugin not registered, and the 401 format mismatch with Security's default exception handling.

Takeaways
— Map front-end concepts to Java equivalents: Express routes to @RestController, npm install to Maven pom.xml, composables to Service classes, axios interceptors to HandlerInterceptor or Filter.
— Use Spring Boot 3.2.x + Java 17 LTS, H2 in-memory database, springdoc-openapi, Vue3 + Vite + TS, and openapi-typescript for type contract generation.
— Boot 3 uses jakarta.* packages, not javax.*; old tutorials will fail to compile.
— 30-minute minimal loop: 0-5 min Initializr, 5-15 min three-layer code, 15-25 min page, 25-30 min integration. Full MVP with login and CRUD takes 1.5-2 days.
— Acceptance criteria for the demo: full create-read-update loop, token auto-carried and validated, one-command startup on a fresh clone without global environment.
— JPA inherits JpaRepository for zero-SQL CRUD; MyBatis-Plus requires manual pagination plugin registration and the spring-boot3 starter.
— Use a unified response body R<T> with traceId for log correlation, plus a @RestControllerAdvice global exception handler that aggregates validation errors and hides stack traces.
— Never return Entity directly; DTO/VO separation prevents password/salt exposure and field coupling.
— @Transactional only works on Service public methods; self-calls within the same class bypass the proxy and silently fail.
— OpenAPI to TypeScript: `npx openapi-typescript http://localhost:8080/v3/api-docs -o src/api/schema.d.ts` makes backend field renames break front-end compilation.
— Spring Security must permit OPTIONS preflight (`requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()`), else login endpoints 401/403.
— jjwt 0.12 API uses `verifyWith(key).build().parseSignedClaims(token)`, and the signing algorithm must be explicit to avoid key-length-driven algorithm jumps.
— Security's default 401/403 responses don't go through @RestControllerAdvice; write a custom authenticationEntryPoint to return JSON in R<T> format.
— AI prompt template should specify Java 17, Spring Boot 3.2, jakarta.*, record DTOs, three-layer structure, R<T> response, LambdaQueryWrapper, and only Service-layer transactions.
— Manual review four-point check: SQL precompiled, transaction present, parameter validation present, authorization ownership checked.
— Production hardening: H2 to MySQL with HikariCP, Flyway for DDL, Nginx same-origin deployment, actuator monitoring, JUnit + Mockito tests, Docker.
— Troubleshooting order: backend logs → real SQL → front-end, not F12 first.
— Vite proxy config has no hot reload; restart dev server after editing vite.config.ts.
Conclusions

The article's core premise—that front-end developers already carry the mental model required for backend work—challenges the common assumption that Java is a from-scratch learning curve; the real obstacle is ecosystem conventions, not language fundamentals.

The explicit warning about `open-in-view: false` reveals a deeper pattern: AI-generated Spring Boot code often inherits default settings that are fine for demos but dangerous in production, so acceptance must go beyond compilation and smoke tests.

The distinction between JPA and MyBatis-Plus signals a cultural split: JPA serves rapid prototyping with zero SQL, while MyBatis-Plus aligns with domestic business projects where SQL control is valued; the choice is less about technology and more about team expectations.

The 24-pitfall table crystallizes that most transition pain comes from ecosystem-specific defaults (package names, plugin registration, security preflight) rather than actual logic; eager learning from these lists outweighs generic Java tutorials.

AI-assisted development here is positioned as a labor division, not replacement—the developer still owns contracts, security, and architecture, and the article's caution about deploying AI-generated encryption code without review is a concrete warning against blind trust.

Concepts & terms
openapi-typescript
A tool that converts an OpenAPI schema (like the one from springdoc-openapi) into TypeScript type definitions, so front-end API types are auto-generated from the backend contract and drift is caught at compile time.
MyBatis-Plus
A popular Chinese ORM enhancement for MyBatis that provides CRUD methods (BaseMapper) and a LambdaQueryWrapper for type-safe, dynamically assembled queries, with annotations for optimistic lock and logical delete.
traceId
A unique identifier added to each request's logs, typically put into a response body field so front-end error messages can carry it and developers can retrieve the exact backend log entry for that request.
OncePerRequestFilter
A Spring filter that guarantees a single execution per request dispatch, preventing duplicate processing during forward and include operations; the recommended base class for custom JWT authentication filters.
LambdaQueryWrapper
MyBatis-Plus's fluent query builder that uses lambda method references instead of column name strings, so field names are validated at compile time and conditions like `like` can be toggled with a boolean parameter.
From the discussion
Featured comments
暴走的菜鸟 1 likes

I hand-coded a simple admin system from 0 to 1, also using Java Spring Boot. (covering face)

Rain的Java大神之路

As long as it runs, haha.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗