手把手教你从零开始搭建SpringBoot后端项目框架

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 原料新鲜的IntelliJ IDEA、一双手、以及电脑一台。搭建框架新建项目打开IDE,点击File -> New Project。在左侧的列表中的选择Maven项目,点击Next。填写GroupId和ArtifactId什么是GroupId和ArtifactId?大家可以参考一下google出来的定义,可以参考一下。

原料

新鲜的IntelliJ IDEA、一双手、以及电脑一台。

搭建框架

新建项目

打开IDE,点击File -> New Project。在左侧的列表中的选择Maven项目,点击Next。

填写GroupId和ArtifactId

什么是GroupId和ArtifactId?大家可以参考一下google出来的定义,可以参考一下。

GroupID是项目组织唯一的标识符,实际对应JAVA的包的结构,是main目录里java的目录结构。

ArtifactID就是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称

简单理解一下,可以理解为GroupId就是你的Github账号,而ArtifactId就是你的具体某个项目,例如这个例子的源码,SpringBootDemo,detectiveHLH/springbootdemo
detectiveHLH就是GroupId,而ArtifactId就是后面的项目名称。

所以,这里应该填写如下(仅供参考)。

GroupId: com.detectivehlh.test
ArtifactId: parent
AI 代码解读

test为项目的名称。ArtifactId代表父类,所以就写parent了。点击Next。

设置Project Name和Project Location

ProjectName就写项目的名称就好。Project Location就是项目在你本地的真实路径。填好之后,点击Next。

然后可以看到IDE已经新建好了项目。

.
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   └── resources
│   └── test
│       └── java
└── test.iml
AI 代码解读

然后右下角会弹出Maven projects need to be imported,选择右边的Enable Auto-Imported.然后删除src目录。

新建模块

本次项目的框架一共有四层结构,也可以说是有四个模块。分别是api、core、data、domain.我们从底层开始,自底向上开始构建模块。

domain

存放实体类

点击File -> New -> Module,在左侧的列表中选择Maven,点击Next。在ArtifactId处填 domain,一路Next。

data模块

主要是做一些对数据库的操作

点击File -> New -> Module,在左侧的列表中选择Maven,点击Next。在ArtifactId处填 data,一路Next。在模块中其实是存在相互依赖关系的。
data模块依赖domain模块的实体。所以要在data文件的配置文件中实现对domain的依赖。

打开data目录中的pom.xml文件。在

<dependencies>
    <dependency>
        <groupId>com.detectivehlh.test</groupId>
        <artifactId>domain</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
AI 代码解读

core模块

后端主要的业务逻辑都会在core模块中。

点击File -> New -> Module,在左侧的列表中选择Maven,点击Next。在ArtifactId处填 core,一路Next。同上,此处也需要配置依赖关系。
core模块的中的service会依赖data模块中的数据。

打开core目录下的pom.xml文件。在

<dependencies>
    <dependency>
        <groupId>com.detectivehlh.test</groupId>
        <artifactId>data</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
AI 代码解读

api模块

主要是存放供前端调用的接口。

点击File -> New -> Module,在左侧的列表中选择Maven,点击Next。在ArtifactId处填 api,一路Next。此处的api模块依赖core中的service服务。

打开api目录下的pom.xml文件。在

<dependencies>
    <dependency>
        <groupId>com.detectivehlh.test</groupId>
        <artifactId>core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
AI 代码解读

让项目"走两步"

到此,框架算是搭建好了,下一步就是要让项目"走两步"来看看。此时的项目的目录如下。

.
├── api
│   ├── api.iml
│   ├── pom.xml
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           └── java
├── core
│   ├── pom.xml
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           └── java
├── data
│   ├── pom.xml
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           └── java
├── domain
│   ├── pom.xml
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           └── java
├── pom.xml
└── test.iml
AI 代码解读

定位到/api/src/main/java,在java目录下新建package,名字为你之前定义的groupid再加上模块名,举个例子。我这的名字就应该为com.detectivehlh.test.api,然后
在该包下新建名为Application的class。然后将代码替换成如下代码。

package com.detectivehlh.test.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
AI 代码解读

此时会报错,是因为springboot的各项依赖,都还没有引入项目的dependences。打开根目录下的pom.xml文件,添加如下依赖。

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
AI 代码解读

然后打开api目录下的pom.xml文件。在dependencies标签中添加如下依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
AI 代码解读

此时Application中就不会报错了。然后就可以启动项目了。打开Application这个类,在SpringBootApplication注解下有个绿色的启动键,点击即可启动项目。之后可在右上方启动。

启动之后,打开http://localhost:8080,如果页面显示

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Sep 18 19:01:11 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available

那么一个简单的springboot应用就可以启动成功了。

实现controller层

com.detectivehlh.test.api包下,新建一个名为controller的包。然后新建名为HelloController的class。
将其全部替换为如下代码(包名根据你的项目命名自行修改)。

package com.detectivehlh.test.api.controller;

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, SpringBoot";
    }
}
AI 代码解读

重新启动项目,访问http://localhost:8080/hello,就可以看到页面显示如下信息。

Hello, SpringBoot

@RestController注解比较适用于Restful风格的API,如果接口只关心数据,不做server render,就可以使用@RestController注解。
如果接口需要返回模版页面,则需要使用@Controller注解。

@GetMapping注解,是将HTTP Get请求映射到我们自定义的hello方法上。

实现service层

新建CoreConfiguration

定位到/core/src/main/java,在java目录下新建名为com.detectivehlh.test.core的包。然后在该包新建名为CoreConfiguration的Class。
将其全部替换为如下代码(包名根据你的项目命名自行修改)。

package com.detectivehlh.test.core;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author detectiveHLH
 * @date 2018/09/13
 */
@ComponentScan
@Configuration
public class CoreConfiguration {

}
AI 代码解读

引入依赖

此时会报错,同样是因为依赖没有引入。在core的pom.xml文件中的dependencies标签中添加如下依赖。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.0.5.RELEASE</version>
</dependency>
AI 代码解读

稍等片刻,就不会有报错提示了。

新建Interface

在com.detectivehlh.test.core包下新建一个名为service的包。在service包下新建一个Class,
名字为HelloService,类型选择Interface。然后修改代码如下(包名根据你的项目命名自行修改)。

package com.detectivehlh.test.core.service;

public interface HelloService {
    String sayHello();
}
AI 代码解读

新建实现类

在service目录下新建名为impl的包。然后在impl下新建名为HelloServiceImpl的类。修改代码如下(包名根据你的项目命名自行修改)。

package com.detectivehlh.test.core.service.impl;

import com.detectivehlh.test.core.service.HelloService;
import org.springframework.stereotype.Service;

@Service
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHello() {
        return "Hello, SpringBoot";
    }
}
AI 代码解读

调用实现类

修改HelloController中的 hello 方法的代码如下(包名根据你的项目命名自行修改)。

package com.detectivehlh.test.api.controller;

import com.detectivehlh.test.core.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * RestController
 * 定义为Restful风格的API控制器
 */
@RestController
public class HelloController {
    @Autowired
    private HelloService helloService;
    
    @GetMapping("/hello")
    public String hello() {
        return helloService.sayHello();
    }
}
AI 代码解读

此时helloService会报错,这是因为我们没有将HelloService这个添加到Bean容器中来。修改Application类代码如下(包名根据你的项目命名自行修改)。

package com.detectivehlh.test.api;

import com.detectivehlh.test.core.CoreConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;

@SpringBootApplication
@Import(CoreConfiguration.class)
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
AI 代码解读

此时再访问http://localhost:8080/hello,就可以看到如下正常的输出了。

Hello, SpringBoot

打通数据库

实现了简单的service,下一步就是要连接数据库。假设现在在你本地已经有了mysql服务。有名为test的数据库,该数据库下有名为user_role的表。表结构如下。

数据库表名和表数据

column_name column_value
id 用户id
name 用户名

并且有了数据

column_name column_value
id name
1 detectiveHLH

新建实体类

定位到/domain/src/main/java,在java目录下新建名为com.detectivehlh.test.domain的包。在该包下新建entity包。
在entity下新建名为BaseEntity的抽象类。修改代码如下。

package com.detectivehlh.test.domain.entity;

public abstract class BaseEntity {

    private long createdAt;

    private String createdBy;

    private long updatedAt;

    private String updatedBy;

    public long getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(long createdAt) {
        this.createdAt = createdAt;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public long getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(long updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }
}
AI 代码解读

在entity下新建名为UserRole的类。代码如下。

package com.detectivehlh.test.domain.entity;

public class UserRole extends BaseEntity {
    private int id;
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
AI 代码解读

新建dao层

实现与数据库交互的mapper。

定位到/data/src/main/java,在java目录下新建名为com.detectivehlh.test.data的包。在该包下新建名为dao的包和名为
DataConfiguration的类。然后在dao包下新建名为UserRoleMapper的类。DataConfiguration代码如下。

package com.detectivehlh.test.data;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author duzhengkang
 * @date 2018/6/25
 */
@ComponentScan
@Configuration
@MapperScan("com.detectivehlh.test.data.dao")
public class DataConfiguration {

}
AI 代码解读

将UserRoleMapper的代码修改为如下。

package com.detectivehlh.test.data.dao;

import com.detectivehlh.test.domain.entity.UserRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserRoleMapper {
    /**
     * 查询所有的用户角色
     * @return
     */
    List<UserRole> all();
}
AI 代码解读

此时代码会报错,同样的依赖原因。打开根目录下的pom.xml文件。添加如下依赖。

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.1.10</version>
</dependency>
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.5</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>6.0.6</version>
</dependency>
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.2</version>
</dependency>
AI 代码解读

添加如上依赖,稍等片刻,就不会报错了。但是此时运行项目依旧会报错。是因为我们引入了mybatis但是却没有配置文件。以及没有将mapper注入到容器中去。

修改Application中的代码如下。

package com.detectivehlh.test.api;

import com.detectivehlh.test.core.CoreConfiguration;
import com.detectivehlh.test.data.DataConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;

@SpringBootApplication
@Import({CoreConfiguration.class, DataConfiguration.class})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
AI 代码解读

mapper就被注入到容器中去了。下一步需要添加配置文件。定位到/api/src/main/resources,新建application.yaml文件。
修改代码如下。

spring:
  application:
    name: test
# 数据库配置
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: 9687Luohongwei
    url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
# mapper文件配置
mybatis:
  mapper-locations: classpath:mapper/*.xml
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
AI 代码解读

修改完毕后,启动项目,访问http://localhost:8080/hello,就可以看到正常输出了。

实现mapper

定位到/data/src/main/resources,新建名为mapper的包。在mapper包下新建名为UserRoleMapper的xml文件。修改代码如下。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.detectivehlh.test.data.dao.UserRoleMapper">
    <!--用于与数据库字段作一一对应-->
    <resultMap id="userRoleMap" type="com.detectivehlh.test.domain.entity.UserRole">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
    </resultMap>

    <!--查询下方列出的所有列-->
    <sql id="allColumns">
        id, name
    </sql>

    <!--定义表名-->
    <sql id="tableName">
        user_role
    </sql>

    <select id="all" resultMap="userRoleMap">
        SELECT
        <include refid="allColumns"/>
        FROM
        <include refid="tableName"/>
        ORDER BY id DESC
    </select>

</mapper>
AI 代码解读

一定注意namespace是否准确。

调用mapper

修改实现类HelloServiceImpl代码如下。

package com.detectivehlh.springbootdemo.core.service.impl;

import com.detectivehlh.springbootdemo.core.service.HelloService;
import com.detectivehlh.springbootdemo.data.dao.UserRoleMapper;
import com.detectivehlh.springbootdemo.domain.entity.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HelloServiceImpl implements HelloService {
    @Autowired
    private UserRoleMapper userRoleMapper;

    @Override
    public List<UserRole> createToken(String key) {
        List<UserRole> data = userRoleMapper.all();
        return data;
    }
}
AI 代码解读

此时会报错,是因为实现类中的返回类型已经变成了List

package com.detectivehlh.test.core.service;

import com.detectivehlh.test.domain.entity.UserRole;
import java.util.List;

public interface HelloService {
    List<UserRole> sayHello();
}
AI 代码解读

让我们回到controller中,我们发现在HelloController中也有报错。这个错误同样也是因为返回类型不一致的原因,修改代码如下。

package com.detectivehlh.test.api.controller;

import com.detectivehlh.test.core.service.HelloService;
import com.detectivehlh.test.domain.entity.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * RestController
 * 定义为Restful风格的API控制器
 */
@RestController
public class HelloController {
    @Autowired
    private HelloService helloService;

    @GetMapping("/hello")
    public List<UserRole> hello() {
        return helloService.sayHello();
    }
}
AI 代码解读

然后启动项目,访问http://localhost:8080/hello。就可以看到,接口返回了user_role表中的所有数据。

[
    {
        "createdAt": 0,
        "createdBy": null,
        "updatedAt": 0,
        "updatedBy": null,
        "id": 1,
        "name": "Tom"
    }
]
AI 代码解读

此时虽然能够正常访问,但是会在控制台报如下警告。

Tue Sep 18 20:40:22 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

在com.detectivehlh.test.api包下新建config包,在config包中新建DbConfig文件。代码如下。

package com.detectivehlh.test.api.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
/**
 * DbConfig
 *
 * @author detectiveHLH
 * @date 2018-07-27 10:35
 **/
@Configuration
@ConfigurationProperties
@EnableTransactionManagement
public class DbConfig {
    @Bean
    @ConfigurationProperties("spring.datasource")
    public DataSource dataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        return dataSource;
    }
    @Bean
    public JdbcTemplate jdbcTemplate(){
        return new JdbcTemplate(dataSource());
    }
    @Bean
    public PlatformTransactionManager transactionManager(){
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource());
        return dataSourceTransactionManager;
    }
}
AI 代码解读

重启启动项目,访问接口时就不会有警告了。

最后的代码目录结构如下。

.
├── api
│   ├── api.iml
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── detectivehlh
│   │   │   │           └── test
│   │   │   │               └── api
│   │   │   │                   ├── Application.java
│   │   │   │                   ├── config
│   │   │   │                   │   └── DbConfig.java
│   │   │   │                   └── controller
│   │   │   │                       └── HelloController.java
│   │   │   └── resources
│   │   │       └── application.yml
│   │   └── test
│   │       └── java
│   └── target
│       ├── classes
│       │   ├── application.yml
│       │   └── com
│       │       └── detectivehlh
│       │           └── test
│       │               └── api
│       │                   ├── Application.class
│       │                   ├── config
│       │                   │   └── DbConfig.class
│       │                   └── controller
│       │                       └── HelloController.class
│       └── generated-sources
│           └── annotations
├── core
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── detectivehlh
│   │   │   │           └── test
│   │   │   │               └── core
│   │   │   │                   ├── CoreConfiguration.java
│   │   │   │                   └── service
│   │   │   │                       ├── HelloService.java
│   │   │   │                       └── impl
│   │   │   │                           └── HelloServiceImpl.java
│   │   │   └── resources
│   │   └── test
│   │       └── java
│   └── target
│       ├── classes
│       │   └── com
│       │       └── detectivehlh
│       │           └── test
│       │               └── core
│       │                   ├── CoreConfiguration.class
│       │                   └── service
│       │                       ├── HelloService.class
│       │                       └── impl
│       │                           └── HelloServiceImpl.class
│       └── generated-sources
│           └── annotations
├── data
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── detectivehlh
│   │   │   │           └── test
│   │   │   │               └── data
│   │   │   │                   ├── DataConfiguration.java
│   │   │   │                   └── dao
│   │   │   │                       └── UserRoleMapper.java
│   │   │   └── resources
│   │   │       └── mapper
│   │   │           └── UserRoleMapper.xml
│   │   └── test
│   │       └── java
│   └── target
│       ├── classes
│       │   ├── com
│       │   │   └── detectivehlh
│       │   │       └── test
│       │   │           └── data
│       │   │               ├── DataConfiguration.class
│       │   │               └── dao
│       │   │                   └── UserRoleMapper.class
│       │   └── mapper
│       │       └── UserRoleMapper.xml
│       └── generated-sources
│           └── annotations
├── domain
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── detectivehlh
│   │   │   │           └── test
│   │   │   │               └── domain
│   │   │   │                   └── entity
│   │   │   │                       ├── BaseEntity.java
│   │   │   │                       └── UserRole.java
│   │   │   └── resources
│   │   └── test
│   │       └── java
│   └── target
│       ├── classes
│       │   └── com
│       │       └── detectivehlh
│       │           └── test
│       │               └── domain
│       │                   └── entity
│       │                       ├── BaseEntity.class
│       │                       └── UserRole.class
│       └── generated-sources
│           └── annotations
├── pom.xml
└── test.iml
AI 代码解读

写在后面

写的比较详细,如果有不对的地方,大佬尽管怼。本项目的源码在 这里

个人博客在 这里

Github在 这里,欢迎star或follow。

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
30
分享
相关文章
制造业ERP源码,工厂ERP管理系统,前端框架:Vue,后端框架:SpringBoot
这是一套基于SpringBoot+Vue技术栈开发的ERP企业管理系统,采用Java语言与vscode工具。系统涵盖采购/销售、出入库、生产、品质管理等功能,整合客户与供应商数据,支持在线协同和业务全流程管控。同时提供主数据管理、权限控制、工作流审批、报表自定义及打印、在线报表开发和自定义表单功能,助力企业实现高效自动化管理,并通过UniAPP实现移动端支持,满足多场景应用需求。
239 1
Spring Boot 便利店销售系统项目分包设计解析
本文深入解析了基于Spring Boot的便利店销售系统分包设计,通过清晰的分层架构(表现层、业务逻辑层、数据访问层等)和模块化设计,提升了代码的可维护性、复用性和扩展性。具体分包结构包括`controller`、`service`、`repository`、`entity`、`dto`、`config`和`util`等模块,职责分明,便于团队协作与功能迭代。该设计为复杂企业级应用开发提供了实践参考。
141 0
智慧班牌源码,采用Java + Spring Boot后端框架,搭配Vue2前端技术,支持SaaS云部署
智慧班牌系统是一款基于信息化与物联网技术的校园管理工具,集成电子屏显示、人脸识别及数据交互功能,实现班级信息展示、智能考勤与家校互通。系统采用Java + Spring Boot后端框架,搭配Vue2前端技术,支持SaaS云部署与私有化定制。核心功能涵盖信息发布、考勤管理、教务处理及数据分析,助力校园文化建设与教学优化。其综合性和可扩展性有效打破数据孤岛,提升交互体验并降低管理成本,适用于日常教学、考试管理和应急场景,为智慧校园建设提供全面解决方案。
304 70
在Linux平台上进行JDK、Tomcat、MySQL的安装并部署后端项目
现在,你可以通过访问http://Your_IP:Tomcat_Port/Your_Project访问你的项目了。如果一切顺利,你将看到那绚烂的胜利之光照耀在你的项目之上!
207 41
在SpringBoot项目中使用Netty实现远程调用
本文介绍了使用Netty解决网络连接性能问题的方法,重点讲解了Netty的NIO特性及其在SpringBoot中的应用。Netty作为高效的NIO框架,支持非阻塞IO,能通过单线程管理多个客户端连接,简化TCP/UDP套接字服务器开发。文章详细展示了Netty在SpringBoot中实现远程调用的过程,包括服务端与客户端代码实现、依赖配置及测试验证。通过示例代码,如`NettyServer`、`NettyClientUtil`等,清晰说明了Netty的工作原理和实际应用,解决了半包等问题,并提供了完整的测试结果。
141 3
SpringBoot中@Scheduled和Quartz的区别是什么?分布式定时任务框架选型实战
本文对比分析了SpringBoot中的`@Scheduled`与Quartz定时任务框架。`@Scheduled`轻量易用,适合单机简单场景,但存在多实例重复执行、无持久化等缺陷;Quartz功能强大,支持分布式调度、任务持久化、动态调整和失败重试,适用于复杂企业级需求。文章通过特性对比、代码示例及常见问题解答,帮助开发者理解两者差异,合理选择方案。记住口诀:单机简单用注解,多节点上Quartz;若是任务要可靠,持久化配置不能少。
235 4
深入理解 Spring Boot 项目中的分页与排序功能
本文深入讲解了在Spring Boot项目中实现分页与排序功能的完整流程。通过实际案例,从Service层接口设计到Mapper层SQL动态生成,再到Controller层参数传递及前端页面交互,逐一剖析每个环节的核心逻辑与实现细节。重点包括分页计算、排序参数校验、动态SQL处理以及前后端联动,确保数据展示高效且安全。适合希望掌握分页排序实现原理的开发者参考学习。
151 4
两种Spring Boot 项目启动自动执行方法的实现方式
在Spring Boot项目启动后执行特定代码的实际应用场景中,可通过实现`ApplicationRunner`或`CommandLineRunner`接口完成初始化操作,如系统常量或配置加载。两者均支持通过`@Order`注解控制执行顺序,值越小优先级越高。区别在于参数接收方式:`CommandLineRunner`使用字符串数组,而`ApplicationRunner`采用`ApplicationArguments`对象。注意,`@Order`仅影响Bean执行顺序,不影响加载顺序。
143 2
Spring Boot 项目中触发 Circular View Path 错误的原理与解决方案
在Spring Boot开发中,**Circular View Path**错误常因视图解析与Controller路径重名引发。当视图名称(如`login`)与请求路径相同,Spring MVC无法区分,导致无限循环调用。解决方法包括:1) 明确指定视图路径,避免重名;2) 将视图文件移至子目录;3) 确保Spring Security配置与Controller路径一致。通过合理设定视图和路径,可有效避免该问题,确保系统稳定运行。
207 0
spring框架之AOP模块(面向切面),附带通知类型---超详细介绍
spring框架之AOP模块(面向切面),附带通知类型---超详细介绍
203 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等