-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SpringBoot2.x 整合Mybatis(多数据源),Redis,RabbitMQ,Thymeleaf等实现简单案例
- Loading branch information
Showing
21 changed files
with
701 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Getting Started | ||
|
||
### Reference Documentation | ||
For further reference, please consider the following sections: | ||
|
||
* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) | ||
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.5.5/maven-plugin/reference/html/) | ||
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.5.5/maven-plugin/reference/html/#build-image) | ||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# SpringBootDemo | ||
SpringBoot2.x demo for study | ||
|
||
#### SpringBoot2.x 整合Mybatis,Redis,RabbitMQ,Thymeleaf等实现简单案例 | ||
|
||
|
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 |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
3.Mysql | ||
并修改相关配置成你自己的 | ||
|
||
插件: | ||
IDEA插件: | ||
1.Lombok |
84 changes: 84 additions & 0 deletions
84
src/main/java/com/example/demo/controller/SalariesController.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,84 @@ | ||
package com.example.demo.controller; | ||
|
||
import com.example.demo.entity.test2.Salaries; | ||
import com.example.demo.service.SalariesService; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.annotation.Resource; | ||
|
||
/** | ||
* (Salaries)表控制层 | ||
* | ||
* @author makejava | ||
* @since 2021-12-20 09:55:29 | ||
*/ | ||
@RestController | ||
@RequestMapping("/salaries") | ||
public class SalariesController { | ||
/** | ||
* 服务对象 | ||
*/ | ||
@Resource | ||
private SalariesService salariesService; | ||
|
||
/** | ||
* 分页查询 | ||
* | ||
* @param salaries 筛选条件 | ||
* @param pageRequest 分页对象 | ||
* @return 查询结果 | ||
*/ | ||
@GetMapping | ||
public ResponseEntity<Page<Salaries>> queryByPage(Salaries salaries, PageRequest pageRequest) { | ||
return ResponseEntity.ok(this.salariesService.queryByPage(salaries, pageRequest)); | ||
} | ||
|
||
/** | ||
* 通过主键查询单条数据 | ||
* | ||
* @param id 主键 | ||
* @return 单条数据 | ||
*/ | ||
@GetMapping("/queryById") | ||
public ResponseEntity<Salaries> queryById(int id) { | ||
return ResponseEntity.ok(this.salariesService.queryById(id)); | ||
} | ||
|
||
/** | ||
* 新增数据 | ||
* | ||
* @param salaries 实体 | ||
* @return 新增结果 | ||
*/ | ||
@PostMapping | ||
public ResponseEntity<Salaries> add(Salaries salaries) { | ||
return ResponseEntity.ok(this.salariesService.insert(salaries)); | ||
} | ||
|
||
/** | ||
* 编辑数据 | ||
* | ||
* @param salaries 实体 | ||
* @return 编辑结果 | ||
*/ | ||
@PutMapping | ||
public ResponseEntity<Salaries> edit(Salaries salaries) { | ||
return ResponseEntity.ok(this.salariesService.update(salaries)); | ||
} | ||
|
||
/** | ||
* 删除数据 | ||
* | ||
* @param id 主键 | ||
* @return 删除是否成功 | ||
*/ | ||
@DeleteMapping | ||
public ResponseEntity<Boolean> deleteById(int id) { | ||
return ResponseEntity.ok(this.salariesService.deleteById(id)); | ||
} | ||
|
||
} | ||
|
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
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,84 @@ | ||
package com.example.demo.dao.test2; | ||
|
||
import com.example.demo.entity.test2.Salaries; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* (Salaries)表数据库访问层 | ||
* | ||
* @author makejava | ||
* @since 2021-12-20 09:55:29 | ||
*/ | ||
public interface SalariesDao { | ||
|
||
/** | ||
* 通过ID查询单条数据 | ||
* | ||
* @param id 主键 | ||
* @return 实例对象 | ||
*/ | ||
Salaries queryById(int id); | ||
|
||
/** | ||
* 查询指定行数据 | ||
* | ||
* @param salaries 查询条件 | ||
* @param pageable 分页对象 | ||
* @return 对象列表 | ||
*/ | ||
List<Salaries> queryAllByLimit(Salaries salaries, @Param("pageable") Pageable pageable); | ||
|
||
/** | ||
* 统计总行数 | ||
* | ||
* @param salaries 查询条件 | ||
* @return 总行数 | ||
*/ | ||
long count(Salaries salaries); | ||
|
||
/** | ||
* 新增数据 | ||
* | ||
* @param salaries 实例对象 | ||
* @return 影响行数 | ||
*/ | ||
int insert(Salaries salaries); | ||
|
||
/** | ||
* 批量新增数据(MyBatis原生foreach方法) | ||
* | ||
* @param entities List<Salaries> 实例对象列表 | ||
* @return 影响行数 | ||
*/ | ||
int insertBatch(@Param("entities") List<Salaries> entities); | ||
|
||
/** | ||
* 批量新增或按主键更新数据(MyBatis原生foreach方法) | ||
* | ||
* @param entities List<Salaries> 实例对象列表 | ||
* @return 影响行数 | ||
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 | ||
*/ | ||
int insertOrUpdateBatch(@Param("entities") List<Salaries> entities); | ||
|
||
/** | ||
* 修改数据 | ||
* | ||
* @param salaries 实例对象 | ||
* @return 影响行数 | ||
*/ | ||
int update(Salaries salaries); | ||
|
||
/** | ||
* 通过主键删除数据 | ||
* | ||
* @param id 主键 | ||
* @return 影响行数 | ||
*/ | ||
int deleteById(int id); | ||
|
||
} | ||
|
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,31 @@ | ||
package com.example.demo.entity.test2; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.Date; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* (Salaries)实体类 | ||
* | ||
* @author makejava | ||
* @since 2021-12-20 09:55:29 | ||
*/ | ||
@Getter | ||
@Setter | ||
public class Salaries implements Serializable { | ||
private static final long serialVersionUID = -95213502783840294L; | ||
|
||
private Integer id; | ||
|
||
private Integer empNo; | ||
|
||
private Integer salary; | ||
|
||
private Date fromDate; | ||
|
||
private Date toDate; | ||
|
||
} | ||
|
Oops, something went wrong.