【javaweb学习】javaweb项目使用的组件和工具


title: javaweb项目使用的组件和工具
date: 2024-04-07 10:25:49
description:
cover: https://elik-1307874295.cos.ap-guangzhou.myqcloud.com/images/md_picture/bigdata/R-C.png?imageSlim
aside: true
categories:

  • web前端,后端
    tags:
  • 前端,后端

使用的组件和工具

  1. Spring Boot:

    • spring-boot-starter: 基础的Spring Boot启动器,包含了自动配置支持。
    • spring-boot-starter-web: 用于构建基于Spring MVC的Web应用。
    • spring-boot-starter-aop: 提供了面向切面编程的支持。
    • spring-boot-starter-jdbc: 提供了JDBC支持,用于数据库操作。
    • spring-boot-starter-test: 包含了测试相关的依赖,如JUnit和Spring Test等。
    • spring-boot-configuration-processor: 用于生成元数据,提高配置的编译时检查。
    • spring-boot-starter-data-redis: 提供了对Redis的集成支持。
    • spring-boot-starter-cache: 提供了缓存抽象的支持。
    • spring-boot-starter-websocket: 提供了WebSocket支持。
  2. MyBatis:

    • mybatis: MyBatis是一个半自动的ORM(对象关系映射)框架。
    • mybatis-spring-boot-starter: 用于简化MyBatis与Spring Boot的集成。
  3. 数据库:

    • mysql-connector-java: MySQL数据库的JDBC驱动。
  4. 连接池:

    • druid-spring-boot-starter: Druid连接池的Spring Boot集成。
  5. Lombok:

    • lombok: 通过注解简化Java类的编写,如@Getter, @Setter等。
  6. PageHelper:

    • pagehelper-spring-boot-starter: 一个MyBatis分页插件。
  7. 工具类库:

    • hutool-all: Hutool是一个Java工具类库,提供了一系列的工具方法。
    • poi, poi-ooxml: Apache POI库用于处理Microsoft Office格式的文件,如Excel。
  8. Swagger:

    • swagger-annotations: 用于生成API文档的注解。
  9. 阿里巴巴FastJSON:

    • fastjson: 用于JSON序列化与反序列化的库。
  10. 其他:

    • aspectjrt, aspectjweaver: 提供了对AspectJ的集成,用于实现切面编程。
    • knife4j-spring-boot-starter: 可能是一个用于生成在线API文档的工具。
    • jaxb-api: Java API for XML Binding,用于处理XML数据。
  11. 构建和部署工具:

    • spring-boot-maven-plugin: 用于简化Spring Boot应用的打包和部署。
  12. 代码生成和模板引擎:

    • tk.mybatis.mapper: 提供了通用的Mapper接口,简化了MyBatis的SQL映射。

图例

编号Component/Tool描述
1spring-boot-starter基础的Spring Boot启动器,包含自动配置支持。
2spring-boot-starter-web用于构建基于Spring MVC的Web应用。
3spring-boot-starter-aop提供了面向切面编程的支持。
4spring-boot-starter-jdbc提供了JDBC支持,用于数据库操作。
5spring-boot-starter-test包含了测试相关的依赖,如JUnit和Spring Test等。
6spring-boot-configuration-processor用于生成元数据,提高配置的编译时检查。
7spring-boot-starter-data-redis提供了对Redis的集成支持。
8spring-boot-starter-cache提供了缓存抽象的支持。
9spring-boot-starter-websocket提供了WebSocket支持。
10mybatisMyBatis是一个半自动的ORM(对象关系映射)框架。
11mybatis-spring-boot-starter用于简化MyBatis与Spring Boot的集成。
12mysql-connector-javaMySQL数据库的JDBC驱动。
13druid-spring-boot-starterDruid连接池的Spring Boot集成。
14lombok通过注解简化Java类的编写,如@Getter, @Setter等。
15pagehelper-spring-boot-starter一个MyBatis分页插件。
16hutool-allHutool是一个Java工具类库,提供了一系列的工具方法。
17poi, poi-ooxmlApache POI库用于处理Microsoft Office格式的文件,如Excel。
18swagger-annotations用于生成API文档的注解。
19fastjson用于JSON序列化与反序列化的库。
20aspectjrt, aspectjweaver提供了对AspectJ的集成,用于实现切面编程。
21knife4j-spring-boot-starter可能是一个用于生成在线API文档的工具。
22jaxb-apiJava API for XML Binding,用于处理XML数据。
23spring-boot-maven-plugin用于简化Spring Boot应用的打包和部署。
24tk.mybatis.mapper提供了通用的Mapper接口,简化了MyBatis的SQL映射。

示例

1. spring-boot-starter:
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
2. spring-boot-starter-web:
@RestController
public class MyController {
    @GetMapping("/greeting")
    public String greeting() {
        return "Hello, World!";
    }
}
3. spring-boot-starter-aop:
@Aspect
@Component
public class LoggingAspect {
    @Autowired
    private Logger logger;

    @Pointcut("execution(* com.example..anyController.*(..))")
    public void anyController() {}

    @AfterReturning(pointcut = "anyController(), returning(retVal)")
    public void logReturn(JoinPoint joinPoint, Object retVal) {
        logger.info("Returning from method: " + joinPoint.getSignature() + " value: " + retVal);
    }
}
4. spring-boot-starter-jdbc:
@Autowired
private JdbcTemplate jdbcTemplate;

public List<User> getAllUsers() {
    return jdbcTemplate.query("SELECT * FROM users", new BeanPropertyRowMapper<>(User.class));
}
5. spring-boot-starter-test:
@SpringBootTest
public class MyServiceTest {

    @Autowired
    private MyService myService;

    @Test
    public void testFindAll() {
        List<?> list = myService.findAll();
        assertNotNull(list);
    }
}
6. spring-boot-configuration-processor:
@ConfigurationProperties(prefix = "app")
public class AppConfigProperties {
    private String name;
    private int port;
    // Getters and setters...
}
7. spring-boot-starter-data-redis:
@Autowired
private RedisTemplate<String, String> redisTemplate;

public void set(String key, String value) {
    redisTemplate.opsForValue().set(key, value);
}

public String get(String key) {
    return redisTemplate.opsForValue().get(key);
}
8. spring-boot-starter-cache:
@Cacheable("users")
public User getUser(Long id) {
    // ... perform database query to get user
    return user;
}
9. spring-boot-starter-websocket:
@Controller
public class WebSocketController {

    @MessageMapping("/message")
    public void processMessageFromClient(Message message, Session session) throws Exception {
        // ... handle message
    }
}
10. mybatis:
```java
@Mapper
public interface UserMapper {
    @Select("SELECT * FROM users WHERE id = #{id}")
    User selectUserById(int id);
}
```
11. mybatis-spring-boot-starter:
```java
@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {

    @Autowired
    private MyBatisTemplate myBatisTemplate;

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}
```
12. mysql-connector-java:
```properties
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=user
spring.datasource.password=pass
```
13. druid-spring-boot-starter:
```yaml
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mydb
    username: user
    password: pass
    druid:
      initial-size: 5
      max-active: 20
```
14. lombok:
```java
@Data
public class User {
    private Long id;
    private String name;
    private String email;
}
```
15. pagehelper-spring-boot-starter:
```java
PageHelper.startPage(1, 10);
List<User> users = userMapper.selectAllUsers();
```
16. hutool-all:
```java
String result = HttpUtil.createGet("http://example.com/api/data").execute().body();
```
17. poi, poi-ooxml:
```java
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Data Sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Hello, POI!");
FileOutputStream fileOut = new FileOutputStream("example.xlsx");
workbook.write(fileOut);
fileOut.close();
workbook.close();
```
18. swagger-annotations:
```java
@ApiOperation(value = "List all pets", notes = "Returns a list of pets")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Successful operation", response = Pet.class, responseContainer = "List"),
    @ApiResponse(code = 400, message = "Invalid status value")
})
@GetMapping(value = "/pets")
public ResponseEntity<List<Pet>> listPets(@RequestParam(value = "status") String status) {
    // ... return pets
}
```
19. fastjson:
```java
String json = JSON.toJSONString(obj);
Obj obj = JSON.parseObject(json, Obj.class);
```
20. aspectjrt, aspectjweaver:
```java
@Aspect
public class PerformanceAspect {
    @Around("execution(* com.example.service.*.*(..)) && @annotation(performance)")
    public Object monitorPerformance(ProceedingJoinPoint pjp, Performance performance) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        performance.setDuration(end - start);
        return result;
    }
}
```
21. knife4j-spring-boot-starter:
```java
@EnableKnife4j
@Configuration
public class Knife4jConfig {
    // ... configure Knife4j
}
```
22. jaxb-api:
```java
JAXBContext context = JAXBContext.newInstance(MyClass.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
MyClass myClass = (MyClass) unmarshaller.unmarshal(new File("data.xml"));
```
23. spring-boot-maven-plugin:
```xml
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
```
24. tk.mybatis.mapper:
```java
@Mapper
public interface UserMapper {
    User selectUserById(int id);
    List<User> selectAllUsers();
    void insertUser(User user);
    void updateUser(User user);
    void deleteUser(int id);
}
```
1	spring-boot-starter: 基础的Spring Boot启动器,包含了自动配置支持。
2	spring-boot-starter-web: 用于构建基于Spring MVC的Web应用。
3	spring-boot-starter-aop: 提供了面向切面编程的支持。
4	spring-boot-starter-jdbc: 提供了JDBC支持,用于数据库操作。
5	spring-boot-starter-test: 包含了测试相关的依赖,如JUnit和Spring Test等。
6	spring-boot-configuration-processor: 用于生成元数据,提高配置的编译时检查。
7	spring-boot-starter-data-redis: 提供了对Redis的集成支持。
8	spring-boot-starter-cache: 提供了缓存抽象的支持。
9	spring-boot-starter-websocket: 提供了WebSocket支持。
10	mybatis: MyBatis是一个半自动的ORM(对象关系映射)框架。
11	mybatis-spring-boot-starter: 用于简化MyBatis与Spring Boot的集成。
12	mysql-connector-java: MySQL数据库的JDBC驱动。
13	druid-spring-boot-starter: Druid连接池的Spring Boot集成。
14	lombok: 通过注解简化Java类的编写,如@Getter, @Setter等。
15	pagehelper-spring-boot-starter: 一个MyBatis分页插件。
16	hutool-all: Hutool是一个Java工具类库,提供了一系列的工具方法。
17	poi, poi-ooxml: Apache POI库用于处理Microsoft Office格式的文件,如Excel。
18	swagger-annotations: 用于生成API文档的注解。
19	fastjson: 用于JSON序列化与反序列化的库。
20	aspectjrt, aspectjweaver: 提供了对AspectJ的集成,用于实现切面编程。
21	knife4j-spring-boot-starter: 可能是一个用于生成在线API文档的工具。
22	jaxb-api: Java API for XML Binding,用于处理XML数据。
23	spring-boot-maven-plugin: 用于简化Spring Boot应用的打包和部署。
24	tk.mybatis.mapper: 提供了通用的Mapper接口,简化了MyBatis的SQL映射。

  • 27
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Elik-hb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值