Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
huayanYu committed Jun 27, 2023
1 parent b445b73 commit 462e6ed
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 10 deletions.
27 changes: 17 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.11</version>
<relativePath/>
</parent>

<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-samples</artifactId>
<version>1.0.0</version>
Expand All @@ -21,12 +14,13 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>

<ds.version>4.0.0</ds.version>
<ds.version>4.0.0-B2</ds.version>
<mybatis-spring-boot-starter.version>3.0.0</mybatis-spring-boot-starter.version>
<druid.version>1.2.17</druid.version>
<druid.version>1.2.18</druid.version>
<p6spy.version>3.9.1</p6spy.version>
<h2.version>2.1.214</h2.version>
<springdoc.version>2.0.4</springdoc.version>
<spring-boot-dependencies.version>2.7.12</spring-boot-dependencies.version>
</properties>

<modules>
Expand All @@ -37,6 +31,7 @@
<module>no-ds-samples</module>
<module>third-part-samples</module>
<module>features-samples</module>
<module>springboot3-sample</module>
</modules>

<dependencyManagement>
Expand All @@ -46,6 +41,18 @@
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>${ds.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
<version>${ds.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
Expand Down Expand Up @@ -100,7 +107,7 @@
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>4.0.rc2</version>
<version>4.2</version>
<configuration>
<header>${user.dir}/license.txt</header>
<includes>
Expand Down
60 changes: 60 additions & 0 deletions springboot3-sample/pom.xml
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>
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");
}
}
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;
}
}
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;
}
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;
}
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);
}
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);
}
Loading

0 comments on commit 462e6ed

Please sign in to comment.