Java 家庭物聯網

家庭物聯網系統的代碼和說明,包括用戶認證、設備控制、數據監控、通知和警報、日志記錄以及WebSocket實時更新功能。

### 項目結構

```plaintext
home-iot-system
├── backend
│ ? └── src
│ ? ? ? └── main
│ ? ? ? ? ? └── java
│ ? ? ? ? ? ? ? └── com
│ ? ? ? ? ? ? ? ? ? └── example
│ ? ? ? ? ? ? ? ? ? ? ? └── homeiot
│ ? ? ? ? ? ? ? ? ? ? ? ? ? ├── config
│ ? ? ? ? ? ? ? ? ? ? ? ? ? ├── controller
│ ? ? ? ? ? ? ? ? ? ? ? ? ? ├── model
│ ? ? ? ? ? ? ? ? ? ? ? ? ? ├── repository
│ ? ? ? ? ? ? ? ? ? ? ? ? ? ├── service
│ ? ? ? ? ? ? ? ? ? ? ? ? ? ├── websocket
│ ? ? ? ? ? ? ? ? ? ? ? ? ? └── HomeIotApplication.java
├── frontend
│ ? ├── public
│ ? └── src
│ ? ? ? ├── components
│ ? ? ? ├── pages
│ ? ? ? ├── services
│ ? ? ? └── App.js
├── pom.xml
└── package.json
```

### 后端(Spring Boot)

#### `pom.xml`

```xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
? ? ? ? ?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? ? ? ? ?xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://www.apache.org/xsd/maven-4.0.0.xsd">
? ? <modelVersion>4.0.0</modelVersion>
? ? <groupId>com.example</groupId>
? ? <artifactId>home-iot-system</artifactId>
? ? <version>1.0-SNAPSHOT</version>
? ? <dependencies>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-web</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-data-jpa</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-security</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-thymeleaf</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>com.h2database</groupId>
? ? ? ? ? ? <artifactId>h2</artifactId>
? ? ? ? ? ? <scope>runtime</scope>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-websocket</artifactId>
? ? ? ? </dependency>
? ? </dependencies>
? ? <build>
? ? ? ? <plugins>
? ? ? ? ? ? <plugin>
? ? ? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? ? ? <artifactId>spring-boot-maven-plugin</artifactId>
? ? ? ? ? ? </plugin>
? ? ? ? </plugins>
? ? </build>
</project>
```

#### `HomeIotApplication.java`

```java
package com.example.homeiot;

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

@SpringBootApplication
public class HomeIotApplication {
? ? public static void main(String[] args) {
? ? ? ? SpringApplication.run(HomeIotApplication.class, args);
? ? }
}
```

#### 用戶認證和角色管理

##### `SecurityConfig.java`

```java
package com.example.homeiot.config;

import com.example.homeiot.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

? ? private final UserService userService;

? ? public SecurityConfig(UserService userService) {
? ? ? ? this.userService = userService;
? ? }

? ? @Override
? ? protected void configure(AuthenticationManagerBuilder auth) throws Exception {
? ? ? ? auth.userDetailsService(userService).passwordEncoder(passwordEncoder());
? ? }

? ? @Override
? ? protected void configure(HttpSecurity http) throws Exception {
? ? ? ? http
? ? ? ? ? ? .csrf().disable()
? ? ? ? ? ? .authorizeRequests()
? ? ? ? ? ? ? ? .antMatchers("/api/**").authenticated()
? ? ? ? ? ? ? ? .antMatchers("/admin/**").hasRole("ADMIN")
? ? ? ? ? ? ? ? .anyRequest().permitAll()
? ? ? ? ? ? ? ? .and()
? ? ? ? ? ? .formLogin()
? ? ? ? ? ? ? ? .and()
? ? ? ? ? ? .httpBasic();
? ? }

? ? @Bean
? ? public PasswordEncoder passwordEncoder() {
? ? ? ? return new BCryptPasswordEncoder();
? ? }
}
```

##### `Role.java`

```java
package com.example.homeiot.model;

import javax.persistence.*;
import java.util.Set;

@Entity
public class Role {
? ? @Id
? ? @GeneratedValue(strategy = GenerationType.AUTO)
? ? private Long id;
? ? private String name;

? ? @ManyToMany(mappedBy = "roles")
? ? private Set<User> users;

? ? // getters and setters
}
```

##### `User.java`

```java
package com.example.homeiot.model;

import javax.persistence.*;
import java.util.Set;

@Entity
public class User {
? ? @Id
? ? @GeneratedValue(strategy = GenerationType.AUTO)
? ? private Long id;
? ? private String username;
? ? private String password;

? ? @ManyToMany(fetch = FetchType.EAGER)
? ? @JoinTable(
? ? ? name = "user_role",?
? ? ? joinColumns = @JoinColumn(name = "user_id"),?
? ? ? inverseJoinColumns = @JoinColumn(name = "role_id"))
? ? private Set<Role> roles;

? ? // getters and setters
}
```

##### `UserRepository.java`

```java
package com.example.homeiot.repository;

import com.example.homeiot.model.User;
import org.springframework.data.repository.CrudRepository;

public interface UserRepository extends CrudRepository<User, Long> {
? ? User findByUsername(String username);
}
```

##### `RoleRepository.java`

```java
package com.example.homeiot.repository;

import com.example.homeiot.model.Role;
import org.springframework.data.repository.CrudRepository;

public interface RoleRepository extends CrudRepository<Role, Long> {
}
```

##### `UserService.java`

```java
package com.example.homeiot.service;

import com.example.homeiot.model.User;
import com.example.homeiot.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

@Service
public class UserService implements UserDetailsService {
? ? @Autowired
? ? private UserRepository userRepository;

? ? @Autowired
? ? private PasswordEncoder passwordEncoder;

? ? public User save(User user) {
? ? ? ? user.setPassword(passwordEncoder.encode(user.getPassword()));
? ? ? ? return userRepository.save(user);
? ? }

? ? public User findByUsername(String username) {
? ? ? ? return userRepository.findByUsername(username);
? ? }

? ? @Override
? ? public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
? ? ? ? User user = userRepository.findByUsername(username);
? ? ? ? if (user == null) {
? ? ? ? ? ? throw new UsernameNotFoundException("User not found");
? ? ? ? }
? ? ? ? return org.springframework.security.core.userdetails.User
? ? ? ? ? ? ? ? .withUsername(username)
? ? ? ? ? ? ? ? .password(user.getPassword())
? ? ? ? ? ? ? ? .authorities(user.getRoles().stream()
? ? ? ? ? ? ? ? ? ? ? ? .map(role -> "ROLE_" + role.getName().toUpperCase())
? ? ? ? ? ? ? ? ? ? ? ? .toArray(String[]::new))
? ? ? ? ? ? ? ? .build();
? ? }
}
```

#### 設備數據監控和日志記錄

##### `Device.java`

```java
package com.example.homeiot.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;

@Entity
public class Device {
? ? @Id
? ? @GeneratedValue(strategy = GenerationType.AUTO)
? ? private Long id;
? ? private String name;
? ? private String status;
? ? private String data;
? ? private LocalDateTime lastUpdated;

? ? // getters and setters
}
```

##### `DeviceLog.java`

```java
package com.example.homeiot.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;

@Entity
public class DeviceLog {
? ? @Id
? ? @GeneratedValue(strategy = GenerationType.AUTO)
? ? private Long id;
? ? private Long deviceId;
? ? private String status;
? ? private String data;
? ? private LocalDateTime timestamp;

? ? // getters and setters
}
```

##### `DeviceLogRepository.java`

```java
package com.example.homeiot.repository;

import com.example.homeiot.model.DeviceLog;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface DeviceLogRepository extends CrudRepository<DeviceLog, Long> {
? ? List<DeviceLog> findByDeviceId(Long deviceId);
}
```

##### `DeviceRepository.java`

```java
package com.example.homeiot.repository;

import com.example.homeiot.model.Device;
import org.springframework.data.repository.CrudRepository;

public interface DeviceRepository extends CrudRepository<Device, Long> {
}
```

##### `DeviceService.java`

```java
package com.example.homeiot.service;

import com.example.homeiot.model.Device;
import com.example.homeiot.model.DeviceLog;
import com.example.homeiot.repository.DeviceLogRepository;
import com.example.homeiot.repository.DeviceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeviceService {
? ? @Autowired
? ? private DeviceRepository deviceRepository;

? ? @Autowired
? ? private DeviceLogRepository deviceLogRepository;

? ? @Autowired
? ? private SimpMessagingTemplate messagingTemplate;

? ? public List<Device> getAllDevices() {
? ? ? ? return (List<Device>) deviceRepository.findAll();
? ? }

? ? public Device addDevice(Device device) {
? ? ? ? device.setLastUpdated(LocalDateTime.now());
? ? ? ? return deviceRepository.save(device);
? ? }

? ? public Device updateDeviceStatus(Long id, String status) {
? ? ? ? Device device = deviceRepository.findById(id).orElseThrow(() -> new RuntimeException("Device not found"));
? ? ? ? device.setStatus(status);
? ? ? ? device.setLastUpdated(LocalDateTime.now());
? ? ? ? deviceRepository.save(device);

? ? ? ? DeviceLog log = new DeviceLog();
? ? ? ? log.setDeviceId(id);
? ? ? ? log.setStatus(status);
? ? ? ? log.setTimestamp(LocalDateTime.now());
? ? ? ? deviceLogRepository.save(log);

? ? ? ? messagingTemplate.convertAndSend("/topic/devices", device);

? ? ? ? return device;
? ? }

? ? public List<DeviceLog> getDeviceLogs(Long deviceId) {
? ? ? ? return deviceLogRepository.findByDeviceId(deviceId);
? ? }
}
```

##### `DeviceController.java`

```java
package com.example.homeiot.controller;

import com.example.homeiot.model.Device;
import com.example.homeiot.model.DeviceLog;
import com.example.homeiot.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/devices")
public class DeviceController {
? ? @Autowired
? ? private DeviceService deviceService;

? ? @GetMapping
? ? public List<Device> getAllDevices() {
? ? ? ? return deviceService.getAllDevices();
? ? }

? ? @PostMapping
? ? public Device addDevice(@RequestBody Device device) {
? ? ? ? return deviceService.addDevice(device);
? ? }

? ? @PutMapping("/{id}/status")
? ? public Device updateDeviceStatus(@PathVariable Long id, @RequestParam String status) {
? ? ? ? return deviceService.updateDeviceStatus(id, status);
? ? }

? ? @GetMapping("/{id}/logs")
? ? public List<DeviceLog> getDeviceLogs(@PathVariable Long id) {
? ? ? ? return deviceService.getDeviceLogs(id);
? ? }

? ? @MessageMapping("/changeStatus")
? ? @SendTo("/topic/devices")
? ? public Device changeDeviceStatus(Device device) {
? ? ? ? return deviceService.updateDeviceStatus(device.getId(), device.getStatus());
? ? }
}
```

#### WebSocket 實時更新

##### `WebSocketConfig.java`

```java
package com.example.homeiot.websocket;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

? ? @Override
? ? public void configureMessageBroker(MessageBrokerRegistry config) {
? ? ? ? config.enableSimpleBroker("/topic");
? ? ? ? config.setApplicationDestinationPrefixes("/app");
? ? }

? ? @Override
? ? public void registerStompEndpoints(StompEndpointRegistry registry) {
? ? ? ? registry.addEndpoint("/ws").withSockJS();
? ? }
}
```

### 前端(React)

#### `package.json`

```json
{
? "name": "home-iot-frontend",
? "version": "1.0.0",
? "dependencies": {
? ? "axios": "^0.21.1",
? ? "react": "^17.0.2",
? ? "react-dom": "^17.0.2",
? ? "react-router-dom": "^5.2.0",
? ? "react-scripts": "4.0.3",
? ? "sockjs-client": "^1.5.0",
? ? "@stomp/stompjs": "^6.1.0"
? },
? "scripts": {
? ? "start": "react-scripts start",
? ? "build": "react-scripts build",
? ? "test": "react-scripts test",
? ? "eject": "react-scripts eject"
? }
}
```

#### `App.js`

```jsx
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import SockJS from 'sockjs-client';
import { Stomp } from '@stomp/stompjs';

function App() {
? const [devices, setDevices] = useState([]);
? const [deviceName, setDeviceName] = useState('');
? const [client, setClient] = useState(null);

? useEffect(() => {
? ? fetchDevices();
? ? connectWebSocket();
? }, []);

? const fetchDevices = () => {
? ? axios.get('/api/devices')
? ? ? .then(response => setDevices(response.data))
? ? ? .catch(error => console.error('Error fetching devices:', error));
? };

? const addDevice = () => {
? ? axios.post('/api/devices', { name: deviceName, status: 'off' })
? ? ? .then(response => {
? ? ? ? setDevices([...devices, response.data]);
? ? ? ? setDeviceName('');
? ? ? })
? ? ? .catch(error => console.error('Error adding device:', error));
? };

? const updateDeviceStatus = (deviceId, status) => {
? ? axios.put(`/api/devices/${deviceId}/status`, null, { params: { status } })
? ? ? .then(response => {
? ? ? ? const updatedDevices = devices.map(device => device.id === deviceId ? response.data : device);
? ? ? ? setDevices(updatedDevices);
? ? ? })
? ? ? .catch(error => console.error('Error updating device status:', error));
? };

? const connectWebSocket = () => {
? ? const socket = new SockJS('/ws');
? ? const stompClient = Stomp.over(socket);
? ? stompClient.connect({}, frame => {
? ? ? console.log('Connected: ' + frame);
? ? ? stompClient.subscribe('/topic/devices', message => {
? ? ? ? const updatedDevice = JSON.parse(message.body);
? ? ? ? setDevices(prevDevices =>
? ? ? ? ? prevDevices.map(device => device.id === updatedDevice.id ? updatedDevice : device)
? ? ? ? );
? ? ? });
? ? });
? ? setClient(stompClient);
? };

? return (
? ? <div>
? ? ? <h1>Home IoT System</h1>
? ? ? <input
? ? ? ? type="text"
? ? ? ? value={deviceName}
? ? ? ? onChange={e => setDeviceName(e.target.value)}
? ? ? ? placeholder="Enter device name"
? ? ? />
? ? ? <button onClick={addDevice}>Add Device</button>
? ? ? <ul>
? ? ? ? {devices.map(device => (
? ? ? ? ? <li key={device.id}>
? ? ? ? ? ? {device.name} - {device.status}
? ? ? ? ? ? <button onClick={() => updateDeviceStatus(device.id, device.status === 'off' ? 'on' : 'off')}>
? ? ? ? ? ? ? Toggle Status
? ? ? ? ? ? </button>
? ? ? ? ? </li>
? ? ? ? ))}
? ? ? </ul>
? ? </div>
? );
}

export default App;
```

系統具備了用戶認證、角色管理、設備數據監控、日志記錄、通知和警報、以及WebSocket實時更新功能。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/40523.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/40523.shtml
英文地址,請注明出處:http://en.pswp.cn/web/40523.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

圖書館數據倉庫

目錄 1.數據倉庫的數據來源為業務數據庫&#xff08;mysql&#xff09; 初始化腳本 init_book_result.sql 2.通過sqoop將mysql中的業務數據導入到大數據平臺&#xff08;hive&#xff09; 導入mysql數據到hive中 3.通過hive進行數據計算和數據分析 形成數據報表 4.再通過sq…

【matlab】智能優化算法——求解目標函數

智能優化算法在求解目標函數方面發揮著重要作用&#xff0c;它通過迭代、篩選等方法來尋找目標函數的最優值&#xff08;極值&#xff09;。以下是關于智能優化算法求解目標函數的詳細介紹&#xff1a; 一、智能優化算法概述 智能優化算法是一種搜索算法&#xff0c;旨在通過…

設置單實例Apache HTTP服務器

配置倉庫 [rootlocalhost ~]# cd /etc/yum.repos.d/ [rootlocalhost yum.repos.d]# vi rpm.repo倉庫代碼&#xff1a; [BaseOS] nameBaseOS baseurl/mnt/BaseOS enabled1 gpgcheck0[AppStream] nameAppStream baseurl/mnt/AppStream enabled1 gpgcheck0掛載 [rootlocalhost …

2.4G無線收發芯片 XL2401D,SOP16封裝,集成單片機,高性價比

XL2401D 芯片是工作在2.400~2.483GHz世界通用ISM頻段&#xff0c;片內集成了九齊 NY8A054E單片機的SOC無線收發芯片。芯片集成射頻收發機、頻率收生器、晶體振蕩器、調制解調器等功能模塊&#xff0c;并且支持一對多組網和帶ACK的通信模式。發射輸出功率、工作頻道以及通信數據…

網絡基礎:IS-IS協議

IS-IS&#xff08;Intermediate System to Intermediate System&#xff09;是一種鏈路狀態路由協議&#xff0c;最初由 ISO&#xff08;International Organization for Standardization&#xff09;為 CLNS&#xff08;Connectionless Network Service&#xff09;網絡設計。…

油猴腳本高級應用:攔截與修改網頁Fetch請求實戰指南

油猴腳本高級應用&#xff1a;攔截與修改網頁Fetch請求實戰指南 簡介&#xff1a; 本文介紹了幾個使用油猴&#xff08;Tampermonkey&#xff09;腳本攔截和修改網頁 fetch 請求的案例。這些腳本可以在瀏覽器擴展油猴中運行&#xff0c;用于開發者調試網絡請求或自定義頁面行…

Vue 前端修改頁面標題無需重新打包即可生效

在public文件夾下創建config.js文件 index.html頁面修改 其他頁面的標題都可以用window.title來引用就可以了&#xff01;

【雷豐陽-谷粒商城 】【分布式高級篇-微服務架構篇】【19】認證服務03—分布式下Session共享問題

持續學習&持續更新中… 守破離 【雷豐陽-谷粒商城 】【分布式高級篇-微服務架構篇】【19】分布式下Session共享問題 session原理分布式下session共享問題Session共享問題解決—session復制Session共享問題解決—客戶端存儲Session共享問題解決—hash一致性Session共享問題…

ASUS/華碩飛行堡壘8 FX506L FX706L系列 原廠win10系統 工廠文件 帶F12 ASUS Recovery恢復

華碩工廠文件恢復系統 &#xff0c;安裝結束后帶隱藏分區&#xff0c;一鍵恢復&#xff0c;以及機器所有驅動軟件。 系統版本&#xff1a;Windows10 原廠系統下載網址&#xff1a;http://www.bioxt.cn 需準備一個20G以上u盤進行恢復 請注意&#xff1a;僅支持以上型號專用…

域名、網頁、HTTP概述

目錄 域名 概念 域名空間結構 域名注冊 網頁 概念 網站 主頁 域名 HTTP URL URN URI HTML 超鏈接 發布 HTML HTML的結構 靜態網頁 特點 動態網頁 特點 Web HTTP HTTP方法 GET方法 POST方法 HTTP狀態碼 生產環境下常見的HTTP狀態碼 域名 概念 IP地…

基于.NET開源游戲框架MonoGame實現的開源項目合集

前言 今天分享一些基于.NET開源游戲框架MonoGame實現的開源項目合集。 MonoGame項目介紹 MonoGame是一個簡單而強大的.NET框架&#xff0c;使用C#編程語言可以創建桌面PC、視頻游戲機和移動設備游戲。它已成功用于創建《怒之鐵拳4》、《食肉者》、《超凡蜘蛛俠》、《星露谷物…

【跟我學K8S】45天入門到熟練詳細學習計劃

目錄 一、什么是K8S 核心功能 架構組件 使用場景 二、入門到熟練的學習計劃 第一周&#xff1a;K8s基礎和概念 第二周&#xff1a;核心對象和網絡 第三周&#xff1a;進階使用和管理 第四周&#xff1a;CI/CD集成和監控 第五周&#xff1a;實戰模擬和案例分析 第六周…

XPointer 實例

XPointer 實例 1. 引言 XPointer 是一種用于定位 XML 文檔中特定部分的語言。它是 XLink 的補充,允許用戶在 XML 文檔中創建鏈接,指向文檔中的特定元素、屬性或文本。XPointer 的強大之處在于其精確的定位能力,使得開發者能夠創建更加豐富和動態的 XML 應用。 2. XPointe…

【Spring Boot】spring boot主啟動類_內置服務

1、主啟動類 1.1 定義與功能 Spring Boot的主啟動類是一個特殊的Java類&#xff0c;用于啟動Spring Boot應用程序。該類通常使用SpringBootApplication注解進行標注&#xff0c;這個注解是一個復合注解&#xff0c;包含SpringBootConfiguration、EnableAutoConfiguration和Co…

LRU Cache 雙向鏈表以及STL list實現----面試常考

雙向鏈表版本&#xff1a; #include <bits/stdc.h> using namespace std; struct Node{int key, value;Node* prev;Node* next;Node():key(0), value(0), prev(nullptr), next(nullptr){}Node(int k, int v):key(k), value(v), prev(nullptr), next(nullptr){} }; class…

【IT領域新生必看】Java中的對象創建魔法:小白也能掌握的五種方法

文章目錄 引言為什么需要創建對象&#xff1f;創建對象的五種常見方式1. 使用 new 關鍵字示例&#xff1a; 2. 使用反射示例&#xff1a; 3. 使用克隆示例&#xff1a; 4. 使用序列化和反序列化示例&#xff1a; 5. 使用工廠方法示例&#xff1a; 選擇合適的對象創建方式總結 引…

Spring容器Bean之XML配置方式

一、首先看applicationContext.xml里的配置項bean 我們采用xml配置文件的方式對bean進行聲明和管理&#xff0c;每一個bean標簽都代表著需要被創建的對象并通過property標簽可以為該類注入其他依賴對象&#xff0c;通過這種方式Spring容器就可以成功知道我們需要創建那些bean實…

IPython代碼塊粘貼秘籍:效率與技巧的完美結合

標題&#xff1a;IPython代碼塊粘貼秘籍&#xff1a;效率與技巧的完美結合 在數據科學和Python編程的日常實踐中&#xff0c;經常需要在IPython環境中快速有效地粘貼代碼塊。這個過程雖小&#xff0c;卻對提升工作效率至關重要。本文將詳細介紹如何在IPython中粘貼代碼塊&…

comsol隨機材料參數賦值

comsol隨機材料參數賦值 在comsol中定義外部matlab函數 在comsol中定義外部matlab函數 首選項&#xff0c;安全性&#xff0c;允許 材料中&#xff0c;將楊氏模量更改為變量函數 計算 應力有波動&#xff0c;可見賦值成功 也可以看到賦值的材料參數&#xff1a;

植物大戰僵尸雜交版V2.1+修改器+融合版

植物大戰僵尸雜交版v2.1 新增新植物&#xff0c;全新模式與玩法&#xff01; 內含窗口放大工具與修改器 主播同款游戲&#xff0c;下載使用即可&#xff01; 鏈接: https://pan.baidu.com/s/1znjbqgBSdqTJWZLBOhe5hA?pwdj6ra 提取碼: j6ra