-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
378 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>dynamic-datasource-samples</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>springboot3-sample</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<spring-boot-dependencies.version>3.1.0</spring-boot-dependencies.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-validation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springdoc</groupId> | ||
<artifactId>springdoc-openapi-ui</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId> | ||
<version>4.0.0-B2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
<version>3.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
33 changes: 33 additions & 0 deletions
33
springboot3-sample/src/main/java/com/baomidou/sample/boot3/SpringBoot3Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright © ${project.inceptionYear} organization baomidou | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.baomidou.sample.boot3; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@Slf4j | ||
@SpringBootApplication | ||
@MapperScan("com.baomidou.sample.boot3.mapper") | ||
public class SpringBoot3Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringBoot3Application.class, args); | ||
log.info("open http://localhost:8080/swagger-ui.html"); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
springboot3-sample/src/main/java/com/baomidou/sample/boot3/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright © ${project.inceptionYear} organization baomidou | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.baomidou.sample.boot3.controller; | ||
|
||
|
||
import com.baomidou.sample.boot3.entity.User; | ||
import com.baomidou.sample.boot3.service.UserService; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/users") | ||
public class UserController { | ||
|
||
private static final Random RANDOM = new Random(); | ||
private final UserService userService; | ||
|
||
@GetMapping("master") | ||
public List<User> masterUsers() { | ||
return userService.selectMasterUsers(); | ||
} | ||
|
||
@GetMapping("slave") | ||
public List<User> slaveUsers() { | ||
return userService.selectSlaveUsers(); | ||
} | ||
|
||
@PostMapping | ||
public User addUser() { | ||
User user = new User(); | ||
user.setName("测试用户" + RANDOM.nextInt()); | ||
user.setAge(RANDOM.nextInt(100)); | ||
userService.addUser(user); | ||
return user; | ||
} | ||
|
||
@DeleteMapping("{id}") | ||
public String deleteUser(@PathVariable Long id) { | ||
userService.deleteUserById(id); | ||
return "成功删除用户" + id; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
springboot3-sample/src/main/java/com/baomidou/sample/boot3/dto/UserDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright © ${project.inceptionYear} organization baomidou | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.baomidou.sample.boot3.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class UserDto { | ||
|
||
private Integer id; | ||
|
||
private String name; | ||
|
||
private Integer age; | ||
} |
28 changes: 28 additions & 0 deletions
28
springboot3-sample/src/main/java/com/baomidou/sample/boot3/entity/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright © ${project.inceptionYear} organization baomidou | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.baomidou.sample.boot3.entity; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class User { | ||
|
||
private Integer id; | ||
|
||
private String name; | ||
|
||
private Integer age; | ||
} |
36 changes: 36 additions & 0 deletions
36
springboot3-sample/src/main/java/com/baomidou/sample/boot3/mapper/UserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright © ${project.inceptionYear} organization baomidou | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.baomidou.sample.boot3.mapper; | ||
|
||
import com.baomidou.sample.boot3.entity.User; | ||
import org.apache.ibatis.annotations.Delete; | ||
import org.apache.ibatis.annotations.Insert; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.apache.ibatis.annotations.Select; | ||
|
||
import java.util.List; | ||
|
||
public interface UserMapper { | ||
|
||
@Select("select * from t_user") | ||
List<User> selectUsers(); | ||
|
||
@Insert("insert into t_user (name,age) values (#{name},#{age})") | ||
boolean addUser(@Param("name") String name, @Param("age") Integer age); | ||
|
||
@Delete("delete from t_user where id = #{id}") | ||
void deleteUserById(Long id); | ||
} |
32 changes: 32 additions & 0 deletions
32
springboot3-sample/src/main/java/com/baomidou/sample/boot3/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright © ${project.inceptionYear} organization baomidou | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.baomidou.sample.boot3.service; | ||
|
||
|
||
import com.baomidou.sample.boot3.entity.User; | ||
|
||
import java.util.List; | ||
|
||
public interface UserService { | ||
|
||
List<User> selectMasterUsers(); | ||
|
||
List<User> selectSlaveUsers(); | ||
|
||
void addUser(User user); | ||
|
||
void deleteUserById(Long id); | ||
} |
Oops, something went wrong.