spring-boot-api-project-seed
:seedling::rocket:一个基于Spring Boot & MyBatis的种子项目,用于快速构建中小型API、RESTful API项目~
Top Related Projects
🚀一个用来深入学习并实战 Spring Boot 的项目。
about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。
spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。
《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!
基于SpringCloud2.1的微服务开发脚手架,整合了spring-security-oauth2、nacos、feign、sentinel、springcloud-gateway等。服务治理方面引入elasticsearch、skywalking、springboot-admin、zipkin等,让项目开发快速进入业务开发,而不需过多时间花费在架构搭建上。持续更新中
一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024
Quick Overview
Spring Boot API Project Seed is a starter template for building RESTful APIs using Spring Boot. It provides a basic project structure, common configurations, and utility classes to help developers quickly set up and start developing Spring Boot-based API projects.
Pros
- Pre-configured project structure with best practices for Spring Boot API development
- Includes common utilities and configurations, reducing boilerplate code
- Supports code generation for basic CRUD operations
- Integrates popular libraries like MyBatis and PageHelper for database operations and pagination
Cons
- Limited documentation, especially for non-Chinese speakers
- May include unnecessary dependencies for some projects
- Lacks extensive customization options out of the box
- Not actively maintained, with the last update being over a year ago
Code Examples
- Using the BaseService for CRUD operations:
@Service
public class UserService extends AbstractService<User> {
@Autowired
private UserMapper userMapper;
public User findByUsername(String username) {
return userMapper.findByUsername(username);
}
}
- Implementing a REST controller:
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserService userService;
@PostMapping
public Result add(@RequestBody User user) {
userService.save(user);
return ResultGenerator.genSuccessResult();
}
@GetMapping("/{id}")
public Result detail(@PathVariable Integer id) {
User user = userService.findById(id);
return ResultGenerator.genSuccessResult(user);
}
}
- Configuring application properties:
spring.profiles.active=dev
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=123456
mybatis.mapper-locations=classpath:mapper/*.xml
Getting Started
-
Clone the repository:
git clone https://github.com/lihengming/spring-boot-api-project-seed.git
-
Configure your database connection in
src/main/resources/application-dev.properties
. -
Run the project:
./mvnw spring-boot:run
-
Generate code for your entity:
./mvnw generate-sources
-
Start developing your API endpoints in the generated controller classes.
Competitor Comparisons
🚀一个用来深入学习并实战 Spring Boot 的项目。
Pros of spring-boot-demo
- More comprehensive, covering a wider range of Spring Boot features and integrations
- Better organized with separate modules for different functionalities
- More actively maintained with frequent updates and contributions
Cons of spring-boot-demo
- Potentially overwhelming for beginners due to its extensive scope
- May include unnecessary components for simple projects
- Requires more setup time to understand and utilize all features
Code Comparison
spring-boot-api-project-seed:
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
spring-boot-demo:
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
.allowCredentials(true)
.maxAge(3600)
.allowedHeaders("*");
}
}
The spring-boot-demo implementation provides more detailed CORS configuration, allowing for greater control over cross-origin requests. This exemplifies the project's more comprehensive approach to Spring Boot features and configurations.
about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。
Pros of spring-boot-examples
- Covers a wide range of Spring Boot topics and use cases
- Includes examples for various Spring Boot integrations (e.g., Redis, MongoDB, RabbitMQ)
- Regularly updated with new examples and improvements
Cons of spring-boot-examples
- Less focused on providing a complete project structure
- May require more effort to adapt examples into a production-ready application
- Lacks some advanced features like API versioning and Swagger integration
Code Comparison
spring-boot-api-project-seed:
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.company.project.web"))
.paths(PathSelectors.any())
.build();
}
}
spring-boot-examples:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
The spring-boot-api-project-seed example shows Swagger configuration, which is not present in spring-boot-examples. However, spring-boot-examples focuses on demonstrating various Spring Boot features and integrations across multiple smaller projects.
spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。
Pros of springboot-learning-example
- More comprehensive coverage of Spring Boot features and use cases
- Includes examples for various Spring Boot integrations (e.g., Redis, MongoDB, MyBatis)
- Better suited for learning and exploring different aspects of Spring Boot
Cons of springboot-learning-example
- Less focused on providing a ready-to-use project structure
- May require more effort to extract specific components for use in a production project
- Lacks some of the production-ready features found in spring-boot-api-project-seed
Code Comparison
spring-boot-api-project-seed:
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
springboot-learning-example:
@Configuration
public class CorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
};
}
}
Both repositories demonstrate CORS configuration, but spring-boot-api-project-seed uses a more concise approach by extending WebMvcConfigurerAdapter, while springboot-learning-example uses a separate configuration class with a Bean method.
《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!
Pros of SpringBoot-Learning
- More comprehensive coverage of Spring Boot topics, including tutorials and examples
- Regularly updated with new content and examples
- Larger community engagement and contributions
Cons of SpringBoot-Learning
- Less focused on providing a ready-to-use project structure
- May require more time to navigate and find specific information
- Not specifically tailored for API development
Code Comparison
spring-boot-api-project-seed:
@Configuration
public class MybatisConfigurer {
@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
factory.setDataSource(dataSource);
factory.setTypeAliasesPackage(MODEL_PACKAGE);
return factory.getObject();
}
}
SpringBoot-Learning:
@SpringBootApplication
public class Chapter1Application {
public static void main(String[] args) {
SpringApplication.run(Chapter1Application.class, args);
}
}
The code comparison shows that spring-boot-api-project-seed focuses on configuration and setup for a specific use case (Mybatis integration), while SpringBoot-Learning provides more general examples of Spring Boot applications.
基于SpringCloud2.1的微服务开发脚手架,整合了spring-security-oauth2、nacos、feign、sentinel、springcloud-gateway等。服务治理方面引 入elasticsearch、skywalking、springboot-admin、zipkin等,让项目开发快速进入业务开发,而不需过多时间花费在架构搭建上。持续更新中
Pros of SpringCloud
- Comprehensive microservices architecture with service discovery, gateway, and configuration management
- Implements advanced features like distributed tracing and centralized logging
- Includes security implementations with OAuth2 and JWT
Cons of SpringCloud
- More complex setup and steeper learning curve for beginners
- Potentially overkill for smaller projects or monolithic applications
- Requires more resources to run due to multiple services
Code Comparison
SpringCloud (OAuth2 configuration):
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/**").authenticated()
.antMatchers("/").permitAll();
}
}
spring-boot-api-project-seed (Basic security configuration):
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/**").authenticated()
.anyRequest().permitAll();
}
}
The SpringCloud example showcases a more advanced OAuth2 resource server configuration, while spring-boot-api-project-seed uses a simpler security setup suitable for basic authentication needs.
一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024
Pros of SpringBoot-Labs
- More comprehensive coverage of Spring Boot topics and integrations
- Regularly updated with new examples and features
- Includes detailed documentation and explanations for each module
Cons of SpringBoot-Labs
- Larger and more complex project structure, potentially overwhelming for beginners
- Less focused on providing a ready-to-use project template
- May require more time to understand and implement specific features
Code Comparison
SpringBoot-Labs example (Spring Security configuration):
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().formLogin();
}
}
spring-boot-api-project-seed example (MyBatis configuration):
@Configuration
@MapperScan("com.company.project.dao")
public class MybatisConfigurer {
@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
factory.setDataSource(dataSource);
return factory.getObject();
}
}
Both repositories provide valuable resources for Spring Boot developers, but they serve different purposes. SpringBoot-Labs offers a wide range of examples and integrations, making it an excellent learning resource. spring-boot-api-project-seed, on the other hand, provides a more streamlined template for quickly starting API projects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ç®ä»
Spring Boot API Project Seed æ¯ä¸ä¸ªåºäºSpring Boot & MyBatisçç§å项ç®ï¼ç¨äºå¿«éæ建ä¸å°åAPIãRESTful API项ç®ï¼è¯¥ç§å项ç®å·²ç»æè¿å¤ä¸ªçå®é¡¹ç®çå®è·µï¼ç¨³å®ãç®åãå¿«éï¼ä½¿æ们æè±é£äºéå¤å³å¨ï¼ä¸æ³¨äºä¸å¡ä»£ç çç¼åï¼åå°å çãä¸é¢æ¯ä¸ä¸ªç®åç使ç¨æ¼ç¤ºï¼çå¦ä½åºäºæ¬é¡¹ç®å¨ççå åç§éå å®ç°ä¸å¥ç®åçAPIï¼å¹¶è¿è¡æä¾æå¡ã
ç¹å¾&æä¾
- æä½³å®è·µç项ç®ç»æãé ç½®æ件ãç²¾ç®çPOMï¼æ¥ç项ç®ç»æå¾ï¼
- ç»ä¸ååºç»æå°è£ åçæå·¥å ·
- ç»ä¸å¼å¸¸å¤ç
- ç®åçæ¥å£ç¾å认è¯
- 常ç¨åºç¡æ¹æ³æ½è±¡å°è£
- 使ç¨Druid Spring Boot Starter éæDruidæ°æ®åºè¿æ¥æ± ä¸çæ§
- 使ç¨FastJsonHttpMessageConverterï¼æé«JSONåºååé度
- éæMyBatisãéç¨Mapperæ件ãPageHelperå页æ件ï¼å®ç°å表ä¸å¡é¶SQL
- æä¾ä»£ç çæå¨æ ¹æ®è¡¨åçæ对åºçModelãMapperãMapperXMLãServiceãServiceImplãControllerçåºç¡ä»£ç ï¼å
¶ä¸Controller模æ¿é»è®¤æä¾POSTåRESTful两å¥ï¼æ ¹æ®éæ±å¨
CodeGenerator.genController(tableName)
æ¹æ³ä¸èªå·±éæ©ï¼é»è®¤ä½¿ç¨POST模æ¿ã代ç 模æ¿å¯æ ¹æ®å®é 项ç®çéæ±æ¥æ©å±ï¼ç±äºæ¯ä¸ªå ¬å¸ä¸å¡é½ä¸å¤ªä¸æ ·ï¼æ以åªæä¾äºä¸äºæ¯è¾åºç¡ãéç¨ç模æ¿ï¼**主è¦æ¯æä¾ä¸ä¸ªæè·¯**æ¥åå°éå¤ä»£ç çç¼åï¼æå¨å®é 项ç®ç使ç¨ä¸ï¼å ¶å®æ ¹æ®å ¬å¸ä¸å¡çæ½è±¡ç¼åäºå¤§éç模æ¿ãå¦å¤ï¼ä½¿ç¨æ¨¡æ¿ä¹æå©äºä¿æå¢é代ç é£æ ¼çç»ä¸ - å¦æ彩èï¼å¾ ä½ æ¢ç´¢ Â
å¿«éå¼å§
- å é项ç®
- 对
test
å å ç代ç çæå¨CodeGenerator
è¿è¡é ç½®ï¼ä¸»è¦æ¯JDBCï¼å 为è¦æ ¹æ®è¡¨åæ¥çæ代ç - å¦æåªæ¯æ³æ ¹æ®ä¸é¢çæ¼ç¤ºæ¥äº²èªè¯è¯çè¯å¯ä»¥ä½¿ç¨
test resources
ç®å½ä¸çdemo-user.sql
ï¼å¦å忽ç¥è¯¥æ¥ - è¾å
¥è¡¨åï¼è¿è¡
CodeGenerator.main()
æ¹æ³ï¼çæåºç¡ä»£ç ï¼å¯è½éè¦å·æ°é¡¹ç®ç®å½æä¼åºæ¥ï¼ - æ ¹æ®ä¸å¡å¨åºç¡ä»£ç ä¸è¿è¡æ©å±
- 对å¼åç¯å¢é
ç½®æ件
application-dev.properties
è¿è¡é ç½®ï¼å¯å¨é¡¹ç®ï¼Have Funï¼ Â
å¼å建议
- 表åï¼å»ºè®®ä½¿ç¨å°åï¼å¤ä¸ªåè¯ä½¿ç¨ä¸å线æ¼æ¥
- Modelå
æååé建议ä¸è¡¨å段æ°é对åºï¼å¦éæ©å±æååéï¼æ¯å¦è¿è¡¨æ¥è¯¢ï¼å»ºè®®å建DTOï¼å¦åéå¨æ©å±çæååéä¸å
@Transient
注解ï¼è¯¦æ è§éç¨Mapperæ件æ档说æ - 建议ä¸å¡å¤±è´¥ç´æ¥ä½¿ç¨
ServiceException("message")
æåºï¼ç±ç»ä¸å¼å¸¸å¤çå¨æ¥å°è£ ä¸å¡å¤±è´¥çååºç»æï¼æ¯å¦throw new ServiceException("该ææºå·å·²è¢«æ³¨å")
ï¼ä¼ç´æ¥è¢«å°è£ 为{"code":400,"message":"该ææºå·å·²è¢«æ³¨å"}
è¿åï¼æ éèªå·±å¤çï¼å°½æ æåº - éè¦å·¥å
·ç±»çè¯å»ºè®®å
ä»
apache-commons-*
åguava
ä¸æ¾ï¼å®å¨æ²¡æåé è½®åæå¼å ¥ç±»åºï¼å°½éç²¾ç®é¡¹ç® - å¼åè§è建议éµå¾ªé¿éå·´å·´Javaå¼åæåï¼ææ°çä¸è½½)
- 建议å¨å ¬å¸å é¨ä½¿ç¨ShowDocãSpringFox-Swagger2 ãRAPçå¼æºé¡¹ç®æ¥ç¼åã管çAPIææ¡£ Â
ææ¯éå&ææ¡£
- Spring Bootï¼æ¥çSpring Bootå¦ä¹ &使ç¨æåï¼
- MyBatisï¼æ¥çå®æ¹ä¸æææ¡£ï¼
- MyBatisbéç¨Mapperæ件ï¼æ¥çå®æ¹ä¸æææ¡£ï¼
- MyBatis PageHelperå页æ件ï¼æ¥çå®æ¹ä¸æææ¡£ï¼
- Druid Spring Boot Starterï¼æ¥çå®æ¹ä¸æææ¡£ï¼
- Fastjsonï¼æ¥çå®æ¹ä¸æææ¡£ï¼
- å ¶ä»ç¥
License
æ ï¼çº¯ç²¹å¼æºå享ï¼æ谢大家 Star & Fork çæ¯æã
Top Related Projects
🚀一个用来深入学习并实战 Spring Boot 的项目。
about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。
spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。
《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!
基于SpringCloud2.1的微服务开发脚手架,整合了spring-security-oauth2、nacos、feign、sentinel、springcloud-gateway等。服务治理方面引入elasticsearch、skywalking、springboot-admin、zipkin等,让项目开发快速进入业务开发,而不需过多时间花费在架构搭建上。持续更新中
一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot