spring 完结

This commit is contained in:
法然
2022-10-14 23:39:59 +08:00
parent b91ab7307e
commit 24bc4f24fe
265 changed files with 7316 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.example.shangguigu09;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Shangguigu09Application {
public static void main(String[] args) {
SpringApplication.run(Shangguigu09Application.class, args);
}
}

View File

@@ -0,0 +1,43 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.example.shangguigu09.controller;
import com.example.shangguigu09.entity.User;
import com.example.shangguigu09.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
* @author yinkanglong
* @version : UserController, v 0.1 2022-10-13 19:14 yinkanglong Exp $
*/
@RestController
public class UserController {
@Autowired
private UserService userService;
//id
@GetMapping("/user/{id}")
public Mono<User> getUserById(@PathVariable int id){
return userService.getUserById(id);
}
//all
@GetMapping("/user")
public Flux<User> getAllUser(){
return userService.getAllUser();
}
//tianjian
@GetMapping("/saveuser")
public Mono<Void> saveUser(@RequestBody User user){
Mono<User> userMono = Mono.just(user);
return userService.savaUserInfo(userMono);
}
}

View File

@@ -0,0 +1,78 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.example.shangguigu09.entity;
/**
* @author yinkanglong
* @version : User, v 0.1 2022-10-13 19:01 yinkanglong Exp $
*/
public class User {
private String name;
private String gender;
private Integer age;
public User() {
}
public User(String name, String gender, Integer age) {
this.name = name;
this.gender = gender;
this.age = age;
}
/**
* Getter method for property <tt>name</tt>.
*
* @return property value of name
*/
public String getName() {
return name;
}
/**
* Setter method for property <tt>counterType</tt>.
*
* @param name value to be assigned to property name
*/
public void setName(String name) {
this.name = name;
}
/**
* Getter method for property <tt>gender</tt>.
*
* @return property value of gender
*/
public String getGender() {
return gender;
}
/**
* Setter method for property <tt>counterType</tt>.
*
* @param gender value to be assigned to property gender
*/
public void setGender(String gender) {
this.gender = gender;
}
/**
* Getter method for property <tt>age</tt>.
*
* @return property value of age
*/
public Integer getAge() {
return age;
}
/**
* Setter method for property <tt>counterType</tt>.
*
* @param age value to be assigned to property age
*/
public void setAge(Integer age) {
this.age = age;
}
}

View File

@@ -0,0 +1,24 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.example.shangguigu09.service;
import com.example.shangguigu09.entity.User;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
* @author yinkanglong
* @version : UserService, v 0.1 2022-10-13 19:02 yinkanglong Exp $
*/
public interface UserService {
//id查询用户
Mono<User> getUserById(int id);
//查询所有的用户
Flux<User> getAllUser();
//添加用户
Mono<Void> savaUserInfo(Mono<User> user);
}

View File

@@ -0,0 +1,49 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2022 All Rights Reserved.
*/
package com.example.shangguigu09.service.impl;
import com.example.shangguigu09.entity.User;
import com.example.shangguigu09.service.UserService;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.HashMap;
import java.util.Map;
/**
* @author yinkanglong
* @version : UserServiceImpl, v 0.1 2022-10-13 19:02 yinkanglong Exp $
*/
@Service
public class UserServiceImpl implements UserService {
private final Map<Integer,User> users = new HashMap<>();
public UserServiceImpl() {
this.users.put(1,new User("lucy","nan",10));
this.users.put(2,new User("mary","nv",38));
this.users.put(3,new User("jack","nv",32));
}
@Override
public Mono<User> getUserById(int id) {
return Mono.justOrEmpty(this.users.get(id));
}
@Override
public Flux<User> getAllUser() {
return Flux.fromIterable(this.users.values());
}
@Override
public Mono<Void> savaUserInfo(Mono<User> userMono) {
return userMono.doOnNext(person->{
int id = users.size() + 1;
users.put(id,person);
}).thenEmpty(Mono.empty());
}
}

View File

@@ -0,0 +1,2 @@
server.port=8085

View File

@@ -0,0 +1,13 @@
package com.example.shangguigu09;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class Shangguigu09ApplicationTests {
@Test
void contextLoads() {
}
}