├── .gitignore ├── config └── application.yml ├── pom.xml ├── viboot-apilog ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── apilog │ │ ├── ViBootApiLogApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ ├── mapper │ │ ├── UserMapper.java │ │ └── xml │ │ │ └── UserMapper.xml │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mapper │ └── user │ └── UserMapper.xml ├── viboot-common ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ ├── aop │ │ └── ResponseAop.java │ │ ├── exception │ │ └── NullResponseException.java │ │ ├── handler │ │ ├── GlobalExceptionHandler.java │ │ └── RequestExceptionHandler.java │ │ └── util │ │ ├── CORSFilter.java │ │ ├── CommonUrl.java │ │ ├── JSONUtil.java │ │ ├── MailConstants.java │ │ ├── ReadPropertiesUtil.java │ │ ├── ReturnCode.java │ │ ├── ReturnVO.java │ │ └── Slf4JTest.java │ └── resources │ ├── banner.txt │ └── response.properties ├── viboot-email ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── mail │ │ ├── ViBootMailApplication.java │ │ ├── controller │ │ └── MailController.java │ │ ├── entity │ │ └── Mail.java │ │ └── util │ │ └── MailUtil.java │ └── resources │ ├── application.properties │ └── templates │ └── mailTemplate.html ├── viboot-es ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── es │ │ ├── ViBootESApplication.java │ │ ├── controller │ │ └── ESController.java │ │ ├── dao │ │ └── ESDao.java │ │ ├── entity │ │ └── Article.java │ │ └── service │ │ ├── ESService.java │ │ └── impl │ │ └── ESServiceImpl.java │ └── resources │ └── application.yml ├── viboot-exception-annotation ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── exception │ │ └── annotation │ │ ├── ViBootExceptionAnnotationApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── dao │ │ └── UserMapper.java │ │ ├── entity │ │ └── UserDO.java │ │ ├── exception │ │ ├── GlobalExceptionHandler.java │ │ └── RequestExceptionHandler.java │ │ └── service │ │ ├── IUserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ └── application.yml ├── viboot-mybatis-grace ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── mybatis │ │ ├── ViBootMybatisGraceApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── dao │ │ ├── BaseDao.java │ │ └── impl │ │ │ └── BaseDaoImpl.java │ │ ├── entity │ │ └── UserDO.java │ │ └── service │ │ ├── IUserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mybatis │ ├── mapper │ └── UserMapper.xml │ └── mybatis-config.xml ├── viboot-mybatis-plus ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── mybatis │ │ ├── ViBootMybatisPlusApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ ├── mapper │ │ ├── UserMapper.java │ │ └── xml │ │ │ └── UserMapper.xml │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mapper │ └── user │ └── UserMapper.xml ├── viboot-mybatis-sqlsession ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── mybatis │ │ ├── ViBootMybatisSqlSessionApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── UserDO.java │ │ ├── mapper │ │ └── UserMapper.java │ │ └── service │ │ ├── IUserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mybatis │ ├── mapper │ └── UserMapper.xml │ └── mybatis-config.xml ├── viboot-mybatis-xml ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── mybatis │ │ ├── ViBootMybatisXmlApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── UserDO.java │ │ ├── mapper │ │ └── UserMapper.java │ │ └── service │ │ ├── IUserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mybatis │ ├── mapper │ └── UserMapper.xml │ └── mybatis-config.xml ├── viboot-mybatis ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── mybatis │ │ ├── ViBootMybatisApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── UserDO.java │ │ ├── mapper │ │ └── UserMapper.java │ │ └── service │ │ ├── IUserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ └── application.yml ├── viboot-pagehelper ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── pagehelper │ │ ├── VibootPagehelperApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── UserDO.java │ │ ├── mapper │ │ └── UserMapper.java │ │ └── service │ │ ├── IUserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ └── application.yml ├── viboot-rds ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── redis │ │ ├── VibootRedisApplication.java │ │ ├── base │ │ ├── RedisDao.java │ │ └── impl │ │ │ ├── AbstractBaseRedisDao.java │ │ │ └── RedisDaoImpl.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── UserDO.java │ │ ├── mapper │ │ └── UserMapper.java │ │ └── service │ │ ├── IUserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mybatis │ ├── mapper │ └── UserMapper.xml │ └── mybatis-config.xml ├── viboot-restful ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── restful │ │ ├── VibootRestfulApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ ├── mapper │ │ ├── UserMapper.java │ │ └── xml │ │ │ └── UserMapper.xml │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mapper │ └── user │ └── UserMapper.xml ├── viboot-shiro └── pom.xml ├── viboot-swagger2 ├── .classpath ├── .factorypath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── indi │ │ └── viyoung │ │ └── viboot │ │ └── swagger2 │ │ ├── ViBootSwaggerApplication.java │ │ ├── config │ │ └── Swagger2Config.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ ├── mapper │ │ ├── UserMapper.java │ │ └── xml │ │ │ └── UserMapper.xml │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mapper │ └── user │ └── UserMapper.xml └── viboot-uploader ├── pom.xml └── src └── main ├── java └── indi │ └── viyoung │ └── viboot │ └── uploader │ ├── ViBootUploaderApplication.java │ ├── controller │ └── UploadController.java │ ├── service │ ├── IUploadService.java │ └── impl │ │ └── UploadServiceImpl.java │ └── vo │ └── Chunk.java └── resources └── application.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | logs/ 4 | **/target -------------------------------------------------------------------------------- /config/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: com.mysql.cj.jdbc.Driver 4 | url: jdbc:mysql://localhost:3306/viboot?useUnicode=true&characterEncoding=utf-8 5 | username: root 6 | password: Passw0rd 7 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | indi.viyoung.course 8 | viboot 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | 13 | viboot-mybatis 14 | viboot-mybatis-grace 15 | viboot-mybatis-plus 16 | viboot-mybatis-sqlsession 17 | viboot-mybatis-xml 18 | viboot-exception-annotation 19 | viboot-common 20 | viboot-restful 21 | viboot-apilog 22 | viboot-swagger2 23 | viboot-pagehelper 24 | viboot-rds 25 | viboot-uploader 26 | viboot-es 27 | viboot-shiro 28 | viboot-email 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-parent 34 | 2.1.1.RELEASE 35 | 36 | 37 | 38 | 39 | UTF-8 40 | UTF-8 41 | 1.8 42 | 43 | 44 | 45 | 46 | 47 | mysql 48 | mysql-connector-java 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-web 53 | 54 | 55 | org.projectlombok 56 | lombok 57 | true 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-test 62 | test 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /viboot-apilog/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-apilog/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-apilog 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-apilog/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-apilog/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-apilog/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-apilog/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-apilog/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-apilog 13 | 14 | 15 | 16 | 17 | com.baomidou 18 | mybatis-plus-boot-starter 19 | 3.0.6 20 | 21 | 22 | 23 | 24 | org.apache.velocity 25 | velocity 26 | 1.7 27 | 28 | 29 | 30 | 31 | org.freemarker 32 | freemarker 33 | 2.3.28 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-aop 38 | 39 | 40 | indi.viyoung.course 41 | viboot-common 42 | 1.0-SNAPSHOT 43 | 44 | 45 | eu.bitwalker 46 | UserAgentUtils 47 | 1.20 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/java/indi/viyoung/viboot/apilog/ViBootApiLogApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.apilog; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.ComponentScan; 7 | 8 | /** 9 | * @author vi 10 | * @since 2019/2/19 7:43 PM 11 | */ 12 | @SpringBootApplication 13 | @ComponentScan(value = "indi.viyoung.viboot.*") 14 | @MapperScan(value = "indi.viyoung.viboot.apilog.mapper") 15 | public class ViBootApiLogApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(ViBootApiLogApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/java/indi/viyoung/viboot/apilog/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.apilog.controller; 2 | 3 | 4 | import indi.viyoung.viboot.apilog.entity.User; 5 | import indi.viyoung.viboot.apilog.service.UserService; 6 | import io.swagger.annotations.Api; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import javax.annotation.Resource; 14 | import java.util.List; 15 | 16 | /** 17 | *

18 | * 前端控制器 19 | *

20 | * 21 | * @author viyoung 22 | * @since 2019-01-23 23 | */ 24 | @RestController 25 | @RequestMapping("/users") 26 | @Api 27 | public class UserController { 28 | 29 | @Resource 30 | private UserService userService; 31 | 32 | @GetMapping 33 | public Object findAll() { 34 | return userService.list(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/java/indi/viyoung/viboot/apilog/entity/User.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.apilog.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import java.io.Serializable; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | import lombok.experimental.Accessors; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author viyoung 16 | * @since 2019-01-23 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @Accessors(chain = true) 21 | public class User implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId(value = "id", type = IdType.AUTO) 26 | private Long id; 27 | 28 | private String password; 29 | 30 | private String userName; 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/java/indi/viyoung/viboot/apilog/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.apilog.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import indi.viyoung.viboot.apilog.entity.User; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/java/indi/viyoung/viboot/apilog/mapper/xml/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/java/indi/viyoung/viboot/apilog/service/UserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.apilog.service; 2 | 3 | import indi.viyoung.viboot.apilog.entity.User; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/java/indi/viyoung/viboot/apilog/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.apilog.service.impl; 2 | 3 | import indi.viyoung.viboot.apilog.entity.User; 4 | import indi.viyoung.viboot.apilog.mapper.UserMapper; 5 | import indi.viyoung.viboot.apilog.service.UserService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author viyoung 15 | * @since 2019-01-23 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements UserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-apilog/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8090 3 | 4 | mybatis-plus: 5 | configuration: 6 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 -------------------------------------------------------------------------------- /viboot-apilog/src/main/resources/mapper/user/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-common/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-common/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-common 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-common/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-common/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-common/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-common/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-common 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-aop 17 | 18 | 19 | eu.bitwalker 20 | UserAgentUtils 21 | RELEASE 22 | compile 23 | 24 | 25 | com.google.code.gson 26 | gson 27 | 28 | 29 | io.springfox 30 | springfox-swagger2 31 | 2.9.2 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-mail 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | com.github.xiaoymin 46 | swagger-bootstrap-ui 47 | 1.9.0 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/aop/ResponseAop.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.aop; 2 | 3 | import eu.bitwalker.useragentutils.UserAgent; 4 | import indi.viyoung.viboot.handler.GlobalExceptionHandler; 5 | 6 | import indi.viyoung.viboot.util.JSONUtil; 7 | import indi.viyoung.viboot.util.ReturnVO; 8 | import jdk.nashorn.internal.parser.JSONParser; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.aspectj.lang.JoinPoint; 11 | import org.aspectj.lang.ProceedingJoinPoint; 12 | import org.aspectj.lang.annotation.*; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.core.annotation.Order; 17 | import org.springframework.stereotype.Component; 18 | import org.springframework.web.context.request.RequestContextHolder; 19 | import org.springframework.web.context.request.ServletRequestAttributes; 20 | 21 | import javax.servlet.http.HttpServletRequest; 22 | import java.util.Arrays; 23 | import java.util.StringTokenizer; 24 | 25 | 26 | /** 27 | * 统一封装返回值和异常处理 28 | * 29 | * @author vi 30 | * @since 2018/12/20 6:09 AM 31 | */ 32 | @Aspect 33 | @Order(5) 34 | @Component 35 | @Slf4j 36 | public class ResponseAop { 37 | 38 | @Autowired 39 | private GlobalExceptionHandler exceptionHandler; 40 | 41 | ThreadLocal startTime = new ThreadLocal<>(); 42 | 43 | @Before("httpResponse()") 44 | public void doBefore(JoinPoint joinPoint){ 45 | startTime.set(System.currentTimeMillis()); 46 | //接收到请求,记录请求内容 47 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 48 | assert attributes != null; 49 | HttpServletRequest request = attributes.getRequest(); 50 | System.out.println(request.getServerName()); 51 | System.out.println(request.getServerPort()); 52 | //记录请求的内容 53 | UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); 54 | log.info("接口路径:{}" , request.getRequestURL().toString()); 55 | log.info("浏览器:{}", userAgent.getBrowser().toString()); 56 | log.info("浏览器版本:{}",userAgent.getBrowserVersion()); 57 | log.info("操作系统: {}", userAgent.getOperatingSystem().toString()); 58 | log.info("IP : {}" , request.getRemoteAddr()); 59 | log.info("请求类型:{}", request.getMethod()); 60 | log.info("类方法 : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()); 61 | log.info("请求参数 : {} " + Arrays.toString(joinPoint.getArgs())); 62 | } 63 | 64 | /** 65 | * 切点 66 | */ 67 | @Pointcut("execution(public * indi.viyoung.viboot.*.controller..*(..))") 68 | public void httpResponse() { 69 | } 70 | 71 | /** 72 | * 环切 73 | */ 74 | @Around("httpResponse()") 75 | public ReturnVO handlerController(ProceedingJoinPoint proceedingJoinPoint) { 76 | ReturnVO returnVO = new ReturnVO(); 77 | try { 78 | startTime.set(System.currentTimeMillis()); 79 | Object proceed = proceedingJoinPoint.proceed(); 80 | if (proceed instanceof ReturnVO) { 81 | returnVO = (ReturnVO) proceed; 82 | } else { 83 | returnVO.setData(proceed); 84 | } 85 | } catch (Throwable throwable) { 86 | // 这里直接调用刚刚我们在handler中编写的方法 87 | returnVO = exceptionHandler.handlerException(throwable); 88 | } 89 | return returnVO; 90 | } 91 | 92 | @AfterReturning(returning = "ret" , pointcut = "httpResponse()") 93 | public void doAfterReturning(Object ret){ 94 | //处理完请求后,返回内容 95 | log.info("方法返回值:{}" , ret); 96 | log.info("方法执行时间:{}毫秒", (System.currentTimeMillis() - startTime.get())); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/exception/NullResponseException.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception; 2 | 3 | /** 4 | * 自定义异常:返回结果为空 5 | * @author vi 6 | * @since 2018/12/24 6:23 PM 7 | */ 8 | public class NullResponseException extends RuntimeException { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/handler/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.handler; 2 | 3 | import indi.viyoung.viboot.util.CommonUrl; 4 | import indi.viyoung.viboot.util.ReadPropertiesUtil; 5 | import indi.viyoung.viboot.util.ReturnVO; 6 | import org.springframework.http.HttpHeaders; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.RestControllerAdvice; 11 | import org.springframework.web.context.request.WebRequest; 12 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 13 | 14 | import java.util.Properties; 15 | 16 | import static indi.viyoung.viboot.util.ReturnCode.valueOf; 17 | 18 | /** 19 | * 全局异常处理类 20 | * @author yangwei 21 | * 22 | * 用于全局返回json,如需返回ModelAndView请使用@ControllerAdvice 23 | */ 24 | @RestControllerAdvice 25 | public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { 26 | 27 | private static Properties properties = ReadPropertiesUtil.getProperties(System.getProperty("user.dir") + CommonUrl.RESPONSE_PROP_URL); 28 | 29 | 30 | @Override 31 | protected ResponseEntity handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) { 32 | return new ResponseEntity<>(handlerException(ex), HttpStatus.OK); 33 | } 34 | 35 | /** 36 | * 进入controller之后的异常捕获 37 | * @param e 捕获的异常 38 | * @return 封装的返回对象 39 | **/ 40 | @ExceptionHandler(Exception.class) 41 | public ReturnVO handlerException(Throwable e) { 42 | ReturnVO returnVO = new ReturnVO(); 43 | String errorName = e.getClass().getName(); 44 | errorName = errorName.substring(errorName.lastIndexOf(".") + 1); 45 | if (e.getClass() == RuntimeException.class) { 46 | returnVO.setMessage(properties.getProperty(valueOf("RuntimeException").msg()) +": "+ e.getMessage()); 47 | returnVO.setCode(properties.getProperty(valueOf("RuntimeException").val())); 48 | } else { 49 | returnVO.setMessage(properties.getProperty(valueOf(errorName).msg())); 50 | returnVO.setCode(properties.getProperty(valueOf(errorName).val())); 51 | } 52 | return returnVO; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/handler/RequestExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.handler; 2 | 3 | import indi.viyoung.viboot.util.ReturnCode; 4 | import indi.viyoung.viboot.util.ReturnVO; 5 | import org.springframework.boot.web.servlet.error.ErrorController; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * 请求路径有误 11 | * @author yangwei 12 | * @since 2019-01-02 18:13 13 | */ 14 | @RestController 15 | public class RequestExceptionHandler implements ErrorController { 16 | 17 | @Override 18 | public String getErrorPath() { 19 | return "/error"; 20 | } 21 | 22 | @RequestMapping("/error") 23 | public ReturnVO errorPage(){ 24 | return new ReturnVO(ReturnCode.UrlError); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/CORSFilter.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import javax.servlet.*; 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author vi 12 | * @since 2019/1/14 9:38 PM 13 | */ 14 | @Component 15 | public class CORSFilter implements Filter { 16 | 17 | @Override 18 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 19 | throws IOException, ServletException { 20 | HttpServletResponse res = (HttpServletResponse) response; 21 | res.addHeader("Access-Control-Allow-Credentials", "true"); 22 | res.addHeader("Access-Control-Allow-Origin", "*"); 23 | res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); 24 | res.addHeader("Access-Control-Allow-Headers", "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN"); 25 | if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) { 26 | response.getWriter().println("ok"); 27 | return; 28 | } 29 | chain.doFilter(request, response); 30 | } 31 | @Override 32 | public void destroy() { 33 | } 34 | @Override 35 | public void init(FilterConfig filterConfig) throws ServletException { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/CommonUrl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | /** 4 | * @author vi 5 | * @since 2019/1/2 5:43 PM 6 | */ 7 | public class CommonUrl { 8 | 9 | public static final String RESPONSE_PROP_URL = "/viboot-common/src/main/resources/response.properties"; 10 | } 11 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/JSONUtil.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import com.fasterxml.jackson.databind.DeserializationFeature; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import org.springframework.util.StringUtils; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * @author vi 14 | * @since 2019/2/20 9:30 PM 15 | */ 16 | public class JSONUtil { 17 | 18 | private static ObjectMapper mapper = new ObjectMapper(); 19 | 20 | static { 21 | mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 22 | //设置输入时忽略JSON字符串中存在而Java对象实际没有的属性 23 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 24 | } 25 | 26 | public static String object2Json(Object o) { 27 | if (o == null) { 28 | return null; 29 | } 30 | 31 | String s = null; 32 | 33 | try { 34 | s = mapper.writeValueAsString(o); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | return s; 39 | } 40 | 41 | public static List listObject2ListJson(List objects) { 42 | if (objects == null) { 43 | return null; 44 | } 45 | 46 | List lists = new ArrayList(); 47 | for (T t : objects) { 48 | lists.add(JSONUtil.object2Json(t)); 49 | } 50 | 51 | return lists; 52 | } 53 | 54 | public static List listJson2ListObject(List jsons, Class c) { 55 | if (jsons == null) { 56 | return null; 57 | } 58 | 59 | List ts = new ArrayList(); 60 | for (String j : jsons) { 61 | ts.add(JSONUtil.json2Object(j, c)); 62 | } 63 | 64 | return ts; 65 | } 66 | 67 | public static T json2Object(String json, Class c) { 68 | if (!StringUtils.hasLength(json)) { 69 | return null; 70 | } 71 | 72 | T t = null; 73 | try { 74 | t = mapper.readValue(json, c); 75 | } catch (Exception e) { 76 | e.printStackTrace(); 77 | } 78 | return t; 79 | } 80 | 81 | @SuppressWarnings("unchecked") 82 | public static T json2Object(String json, TypeReference tr) { 83 | if (StringUtils.hasLength(json) == false) { 84 | return null; 85 | } 86 | 87 | T t = null; 88 | try { 89 | t = (T) mapper.readValue(json, tr); 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | } 93 | return (T) t; 94 | } 95 | } -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/MailConstants.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | /** 4 | * 邮件常量类 5 | * @author vi 6 | * @since 2019/07/17 7 | */ 8 | public class MailConstants { 9 | 10 | public final static String SIMPLE_TYPE = "1"; 11 | public final static String TEMPLATE_TYPE = "2"; 12 | public final static String ATTACHED_TYPE = "3"; 13 | } 14 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/ReadPropertiesUtil.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | import java.io.*; 4 | import java.util.Iterator; 5 | import java.util.Properties; 6 | 7 | /** 8 | * 读取*.properties中的属性 9 | * @author vi 10 | * @since 2018/12/24 7:33 PM 11 | */ 12 | public class ReadPropertiesUtil { 13 | 14 | public static Properties getProperties(String propertiesPath){ 15 | Properties properties = new Properties(); 16 | try { 17 | InputStream inputStream = new BufferedInputStream(new FileInputStream(propertiesPath)); 18 | properties.load(inputStream); 19 | } catch (IOException e) { 20 | e.printStackTrace(); 21 | } 22 | return properties; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/ReturnCode.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | /** 4 | * @author yangwei 5 | * @since 2018/12/20 6 | */ 7 | @SuppressWarnings("ALL") 8 | public enum ReturnCode { 9 | 10 | /** 操作成功 */ 11 | SUCCESS("SUCCESS_CODE", "SUCCESS_MSG"), 12 | 13 | /** 操作失败 */ 14 | FAIL("FAIL_CODE", "FAIL_MSG"), 15 | 16 | /** 空指针异常 */ 17 | NullpointerException("NPE_CODE", "NPE_MSG"), 18 | 19 | /** 自定义异常之返回值为空 */ 20 | NullResponseException("NRE_CODE", "NRE_MSG"), 21 | 22 | /** 运行时异常 */ 23 | RuntimeException("RTE_CODE","RTE_MSG"), 24 | 25 | /** 请求方式错误异常 */ 26 | HttpRequestMethodNotSupportedException("REQUEST_METHOD_UNSUPPORTED_CODE","REQUEST_METHOD_UNSUPPORTED_MSG"), 27 | 28 | /** INTERNAL_ERROR */ 29 | BindException("BIND_EXCEPTION_CODE","BIND_EXCEPTION_MSG"), 30 | 31 | /** 页面路径不对 */ 32 | UrlError("UE_CODE","UE_MSG"); 33 | 34 | private ReturnCode(String value, String msg){ 35 | this.val = value; 36 | this.msg = msg; 37 | } 38 | 39 | public String val() { 40 | return val; 41 | } 42 | 43 | public String msg() { 44 | return msg; 45 | } 46 | 47 | private String val; 48 | private String msg; 49 | } 50 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/ReturnVO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | import java.util.Properties; 4 | 5 | /** 6 | * 统一定义返回类 7 | * 8 | * @author yangwei 9 | * @since 2018/12/20 10 | */ 11 | public class ReturnVO { 12 | 13 | private static Properties properties = ReadPropertiesUtil.getProperties(System.getProperty("user.dir") + CommonUrl.RESPONSE_PROP_URL); 14 | 15 | /** 16 | * 返回代码 17 | */ 18 | private String code; 19 | 20 | /** 21 | * 返回信息 22 | */ 23 | private String message; 24 | 25 | /** 26 | * 返回数据 27 | */ 28 | private Object data; 29 | 30 | 31 | public Object getData() { 32 | return data; 33 | } 34 | 35 | public void setData(Object data) { 36 | this.data = data; 37 | } 38 | 39 | public String getMessage() { 40 | return message; 41 | } 42 | 43 | public void setMessage(String message) { 44 | this.message = message; 45 | } 46 | 47 | public String getCode() { 48 | return code; 49 | } 50 | 51 | public void setCode(String code) { 52 | this.code = code; 53 | } 54 | 55 | /** 56 | * 默认构造,返回操作正确的返回代码和信息 57 | */ 58 | public ReturnVO() { 59 | this.setCode(properties.getProperty(ReturnCode.SUCCESS.val())); 60 | this.setMessage(properties.getProperty(ReturnCode.SUCCESS.msg())); 61 | } 62 | 63 | /** 64 | * 返回代码,这里需要在枚举中去定义 65 | * @param code 66 | */ 67 | public ReturnVO(ReturnCode code) { 68 | this.setCode(properties.getProperty(code.val())); 69 | this.setMessage(properties.getProperty(code.msg())); 70 | } 71 | 72 | /** 73 | * 返回数据,默认返回正确的code和message 74 | * @param data 75 | */ 76 | public ReturnVO(Object data) { 77 | this.setCode(properties.getProperty(ReturnCode.SUCCESS.val())); 78 | this.setMessage(properties.getProperty(ReturnCode.SUCCESS.msg())); 79 | this.setData(data); 80 | } 81 | 82 | /** 83 | * 返回错误的代码,以及自定义的错误信息 84 | * @param code 85 | * @param message 86 | */ 87 | public ReturnVO(ReturnCode code, String message) { 88 | this.setCode(properties.getProperty(code.val())); 89 | this.setMessage(message); 90 | } 91 | 92 | /** 93 | * 返回自定义的code,message,以及data 94 | * @param code 95 | * @param message 96 | * @param data 97 | */ 98 | public ReturnVO(ReturnCode code, String message, Object data) { 99 | this.setCode(code.val()); 100 | this.setMessage(message); 101 | this.setData(data); 102 | } 103 | 104 | @Override 105 | public String toString() { 106 | return "ReturnVO{" + 107 | "code='" + code + '\'' + 108 | ", message='" + message + '\'' + 109 | ", data=" + data + 110 | '}'; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /viboot-common/src/main/java/indi/viyoung/viboot/util/Slf4JTest.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.util; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | /** 6 | * @author vi 7 | * @since 2019/1/9 11:02 PM 8 | */ 9 | @Slf4j 10 | public class Slf4JTest { 11 | 12 | public static void main(String[] args) { 13 | log.info("This is a Slf4jTest"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /viboot-common/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | __ ___ ____ _ 2 | \ \ / (_) | __ ) ___ ___ | |_ 3 | \ \ / /| | | _ \ / _ \ / _ \| __| 4 | \ V / | | | |_) | (_) | (_) | |_ 5 | \_/ |_| |____/ \___/ \___/ \__| 6 | -------------------------------------------------------------------------------- /viboot-common/src/main/resources/response.properties: -------------------------------------------------------------------------------- 1 | SUCCESS_CODE=2000 2 | SUCCESS_MSG=\u64CD\u4F5C\u6210\u529F 3 | 4 | FAIL_CODE=5000 5 | FAIL_MSG=\u64CD\u4F5C\u5931\u8D25 6 | 7 | NPE_CODE=5001 8 | NPE_MSG=\u7A7A\u6307\u9488\u5F02\u5E38 9 | 10 | NRE_CODE=5002 11 | NRE_MSG=\u8FD4\u56DE\u503C\u4E3A\u7A7A 12 | 13 | RTE_CODE=5001 14 | RTE_MSG=\u8FD0\u884C\u65F6\u5F02\u5E38 15 | 16 | UE_CODE=404 17 | UE_MSG=\u672A\u77E5\u9519\u8BEF\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458 18 | 19 | REQUEST_METHOD_UNSUPPORTED_CODE=4000 20 | REQUEST_METHOD_UNSUPPORTED_MSG=\u8BF7\u6C42\u65B9\u5F0F\u5F02\u5E38 21 | 22 | BIND_EXCEPTION_CODE=4001 23 | BIND_EXCEPTION_MSG=\u8BF7\u6C42\u53C2\u6570\u7ED1\u5B9A\u5931\u8D25 24 | -------------------------------------------------------------------------------- /viboot-email/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-email 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-mail 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-thymeleaf 23 | 24 | 25 | indi.viyoung.course 26 | viboot-common 27 | 1.0-SNAPSHOT 28 | 29 | 30 | -------------------------------------------------------------------------------- /viboot-email/src/main/java/indi/viyoung/viboot/mail/ViBootMailApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mail; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ViBootMailApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ViBootMailApplication.class,args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /viboot-email/src/main/java/indi/viyoung/viboot/mail/controller/MailController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mail.controller; 2 | 3 | 4 | import indi.viyoung.viboot.mail.entity.Mail; 5 | import indi.viyoung.viboot.mail.util.MailUtil; 6 | 7 | import indi.viyoung.viboot.util.MailConstants; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.util.StringUtils; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | 13 | @RestController 14 | @RequestMapping("mail") 15 | public class MailController { 16 | 17 | @Value("${spring.mail.username}") 18 | private static String MAIL_SENDER; 19 | 20 | @PostMapping("mail-test") 21 | public void simpleMailTest(@RequestBody Mail email) { 22 | Mail mail = new Mail(); 23 | // 在这里进行邮件发送类型的控制 24 | mail.setType(MailConstants.SIMPLE_TYPE); 25 | // 这里可以直接读取配置文件中的邮件地址 26 | mail.setFrom(MAIL_SENDER); 27 | mail.setTo(email.getTo()); 28 | if (!StringUtils.isEmpty(email.getVariables())) { 29 | mail.setVariables(email.getVariables()); 30 | } 31 | // 剩余的内容可以根据自己的情况进行填写 32 | MailUtil.sendEmail(mail); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /viboot-email/src/main/java/indi/viyoung/viboot/mail/entity/Mail.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mail.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * 邮件实体类 11 | * @author vi 12 | * @since 2019/07/15 13 | */ 14 | @Data 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class Mail { 18 | 19 | /** 20 | * 邮件发送人 21 | */ 22 | private String from; 23 | /** 24 | * 邮件接收人 25 | */ 26 | private String to; 27 | /** 28 | * 邮件主题 29 | */ 30 | private String subject; 31 | /** 32 | * 邮件内容 33 | */ 34 | private String content; 35 | /** 36 | * 邮件主题 37 | */ 38 | private String type; 39 | 40 | /** 41 | * 发送邮件模板时的模板文件名 42 | */ 43 | private String templateName; 44 | 45 | /** 46 | * 模板参数 47 | */ 48 | private Map variables; 49 | 50 | /** 51 | * 附件地址 52 | */ 53 | private String attachPath; 54 | 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /viboot-email/src/main/java/indi/viyoung/viboot/mail/util/MailUtil.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mail.util; 2 | 3 | import com.mysql.cj.util.StringUtils; 4 | import indi.viyoung.viboot.mail.entity.Mail; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.core.io.FileSystemResource; 10 | import org.springframework.mail.SimpleMailMessage; 11 | import org.springframework.mail.javamail.JavaMailSender; 12 | import org.springframework.mail.javamail.MimeMessageHelper; 13 | import org.thymeleaf.TemplateEngine; 14 | import org.thymeleaf.context.Context; 15 | 16 | import javax.mail.MessagingException; 17 | import javax.mail.internet.MimeMessage; 18 | import java.io.File; 19 | 20 | public class MailUtil { 21 | 22 | private static final Logger logger = LoggerFactory.getLogger(MailUtil.class); 23 | 24 | 25 | @Autowired 26 | private static JavaMailSender javaMailSender; 27 | 28 | @Autowired 29 | private static TemplateEngine templateEngine; 30 | 31 | /** 32 | * 对外开放的统一发送邮件方法 33 | * @param mail 34 | */ 35 | public static void sendEmail(Mail mail) { 36 | String type = mail.getType(); 37 | switch (type) { 38 | case "1": 39 | sendSimpleMail(mail); 40 | case "2": 41 | sendMimeMail(mail); 42 | } 43 | } 44 | 45 | /** 46 | * 发送普通邮件 47 | * @param email 邮件对象 48 | */ 49 | private static void sendSimpleMail(Mail email) { 50 | SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); 51 | // 邮件发送人 52 | simpleMailMessage.setFrom(email.getFrom()); 53 | // 邮件接收人 54 | simpleMailMessage.setTo(email.getTo()); 55 | // 邮件主题 56 | simpleMailMessage.setSubject(email.getSubject()); 57 | // 邮件内容 58 | simpleMailMessage.setText(email.getContent()); 59 | // 发送邮件 60 | javaMailSender.send(simpleMailMessage); 61 | } 62 | 63 | /** 64 | * 发送MIME类型的邮件 65 | * @param email 邮件对象 66 | */ 67 | private static void sendMimeMail(Mail email) { 68 | // 生成邮件字符串 69 | String content = email.getContent(); 70 | if (email.getVariables() != null) { 71 | content = generate(email); 72 | } 73 | // 基于这个对象可以发送HTML,或者携带附件的二进制邮件 74 | MimeMessage message= javaMailSender.createMimeMessage(); 75 | try { 76 | // 构建发送模板邮件的对象 77 | MimeMessageHelper helper = new MimeMessageHelper(message,true); 78 | // 设置发送邮箱 79 | helper.setFrom(email.getFrom()); 80 | // 设置接收邮箱 81 | helper.setTo(email.getTo()); 82 | // 设置邮件名(主题) 83 | helper.setSubject(email.getSubject()); 84 | // 设置邮件内容 85 | helper.setText(content,true); 86 | // 这里可以发送带有附件的邮件,如果没有附件可以省略,就不在多做描述 87 | if (!StringUtils.isNullOrEmpty(email.getAttachPath())) { 88 | FileSystemResource file = new FileSystemResource(new File(email.getAttachPath())); 89 | helper.addAttachment(file.getFilename(), file); 90 | } 91 | // 发送邮件 92 | javaMailSender.send(message); 93 | } catch (MessagingException e) { 94 | 95 | } 96 | } 97 | 98 | /** 99 | * 生成模板字符串 100 | * @param email 邮件对象 101 | * @return 102 | */ 103 | private static String generate(Mail email) { 104 | Context context = new Context(); 105 | // 设置模板参数 106 | context.setVariables(email.getVariables()); 107 | // 加载模板后的内容字符串 108 | return templateEngine.process(email.getTemplateName(), context); 109 | } 110 | 111 | 112 | } 113 | -------------------------------------------------------------------------------- /viboot-email/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.mail.host=smtp.163.com 2 | spring.mail.username=18530069930@163.com 3 | spring.mail.password=yw1995 4 | spring.mail.properties.mail.smtp.auth=true 5 | spring.mail.properties.mail.smtp.starttls.enable=true 6 | spring.mail.properties.mail.smtp.starttls.required=true 7 | spring.mail.default-encoding=UTF-8 8 | 9 | spring.thymeleaf.check-template-location=true 10 | spring.thymeleaf.prefix=classpath:/templates/ 11 | spring.thymeleaf.suffix=.html 12 | spring.thymeleaf.mode=HTML5 13 | spring.thymeleaf.encoding=UTF-8 14 | -------------------------------------------------------------------------------- /viboot-email/src/main/resources/templates/mailTemplate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 |

9 | 10 | -------------------------------------------------------------------------------- /viboot-es/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-es 13 | 14 | 15 | 16 | 17 | org.springframework.data 18 | spring-data-elasticsearch 19 | 3.1.8.RELEASE 20 | 21 | 22 | -------------------------------------------------------------------------------- /viboot-es/src/main/java/indi/viyoung/viboot/es/ViBootESApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.es; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author vi 8 | * @description 9 | * @since 2019-05-16 22:59 10 | */ 11 | @SpringBootApplication 12 | public class ViBootESApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ViBootESApplication.class,args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /viboot-es/src/main/java/indi/viyoung/viboot/es/controller/ESController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.es.controller; 2 | 3 | import indi.viyoung.viboot.es.entity.Article; 4 | import indi.viyoung.viboot.es.service.ESService; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Optional; 15 | 16 | /** 17 | * @author vi 18 | * @description 19 | * @since 2019-05-19 12:26 20 | */ 21 | @RestController 22 | @RequestMapping("es") 23 | @Slf4j 24 | public class ESController { 25 | 26 | 27 | @Autowired 28 | private ESService esService; 29 | 30 | @GetMapping("addSome") 31 | public void addSome() { 32 | List
list = new ArrayList<>(); 33 | for (int i = 0; i < 10; i++) { 34 | Article article = new Article(); 35 | article.setId((long) i); 36 | article.setTitle("测试"+i); 37 | article.setContent("测试1文字啊啊"+i); 38 | list.add(article); 39 | } 40 | esService.addSome(list); 41 | } 42 | 43 | 44 | @GetMapping("get") 45 | public Iterable
getAll() { 46 | Iterable
all = esService.findAll(); 47 | all.forEach(one ->{ 48 | log.info(one.toString()); 49 | }); 50 | 51 | return all; 52 | 53 | } 54 | 55 | @GetMapping("add") 56 | public void add() { 57 | Article article = new Article(); 58 | article.setId(1L); 59 | article.setTitle("测试1"); 60 | article.setContent("测试1文字啊啊"); 61 | esService.add(article); 62 | } 63 | 64 | @GetMapping("put") 65 | public void put() { 66 | Article article = new Article(); 67 | article.setId(1L); 68 | article.setTitle("测试1"); 69 | article.setContent("测试1修改啊啊"); 70 | esService.add(article); 71 | } 72 | 73 | @GetMapping("delete") 74 | public void delete() { 75 | esService.delete(1L); 76 | } 77 | 78 | 79 | @GetMapping("getOne/{id}") 80 | public Optional
getOne(@PathVariable("id") Long id) { 81 | return esService.findOne(id); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /viboot-es/src/main/java/indi/viyoung/viboot/es/dao/ESDao.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.es.dao; 2 | 3 | import indi.viyoung.viboot.es.entity.Article; 4 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 5 | 6 | public interface ESDao extends ElasticsearchRepository { 7 | } 8 | -------------------------------------------------------------------------------- /viboot-es/src/main/java/indi/viyoung/viboot/es/entity/Article.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.es.entity; 2 | 3 | import lombok.Data; 4 | import org.springframework.data.annotation.Id; 5 | import org.springframework.data.elasticsearch.annotations.Document; 6 | import org.springframework.data.elasticsearch.annotations.Field; 7 | import org.springframework.data.elasticsearch.annotations.FieldType; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * @author vi 13 | * @description 14 | * @since 2019-05-19 17:48 15 | */ 16 | 17 | @Document(indexName = "test",type = "article") 18 | @Data 19 | public class Article implements Serializable { 20 | 21 | private Long id; 22 | 23 | @Field(type= FieldType.Text,analyzer = "ik_max_word") 24 | private String title; 25 | 26 | private String content; 27 | } 28 | -------------------------------------------------------------------------------- /viboot-es/src/main/java/indi/viyoung/viboot/es/service/ESService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.es.service; 2 | 3 | import indi.viyoung.viboot.es.entity.Article; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface ESService { 9 | 10 | Iterable
findAll(); 11 | 12 | void add(Article article); 13 | 14 | void delete(long l); 15 | 16 | void addSome(List
list); 17 | 18 | Optional
findOne(Long id); 19 | } 20 | -------------------------------------------------------------------------------- /viboot-es/src/main/java/indi/viyoung/viboot/es/service/impl/ESServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.es.service.impl; 2 | 3 | import indi.viyoung.viboot.es.dao.ESDao; 4 | import indi.viyoung.viboot.es.entity.Article; 5 | import indi.viyoung.viboot.es.service.ESService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | /** 13 | * @author vi 14 | * @description 15 | * @since 2019-05-19 12:31 16 | */ 17 | @Service 18 | public class ESServiceImpl implements ESService { 19 | 20 | 21 | @Autowired 22 | private ESDao esDao; 23 | 24 | @Override 25 | public Iterable
findAll() { 26 | return esDao.findAll(); 27 | } 28 | 29 | @Override 30 | public void add(Article article) { 31 | esDao.save(article); 32 | } 33 | 34 | @Override 35 | public void delete(long l) { 36 | esDao.deleteById(l); 37 | } 38 | 39 | @Override 40 | public void addSome(List
list) { 41 | esDao.saveAll(list); 42 | } 43 | 44 | @Override 45 | public Optional
findOne(Long id) { 46 | return esDao.findById(id); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /viboot-es/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | elasticsearch: 4 | cluster-name: my-applicatioon 5 | cluster-nodes: 127.0.0.1:9300 -------------------------------------------------------------------------------- /viboot-exception-annotation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-exception-annotation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-exception-annotation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-exception-annotation/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-exception-annotation/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-exception-annotation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-exception-annotation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-exception-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-exception-annotation 13 | 14 | 15 | 16 | org.mybatis.spring.boot 17 | mybatis-spring-boot-starter 18 | 1.3.2 19 | 20 | 21 | 22 | indi.viyoung.course 23 | viboot-common 24 | 1.0-SNAPSHOT 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-devtools 29 | true 30 | 31 | 32 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/ViBootExceptionAnnotationApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.ComponentScan; 7 | 8 | /** 9 | * 10 | * @author vi 11 | * @since 7:05 AM 2018/12/25 12 | **/ 13 | @SpringBootApplication 14 | @MapperScan(value = "indi.viyoung.viboot.exception.annotation.dao") 15 | public class ViBootExceptionAnnotationApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(ViBootExceptionAnnotationApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation.controller; 2 | 3 | import indi.viyoung.viboot.exception.NullResponseException; 4 | import indi.viyoung.viboot.exception.annotation.entity.UserDO; 5 | import indi.viyoung.viboot.exception.annotation.service.IUserService; 6 | import indi.viyoung.viboot.util.ReturnVO; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * 用户控制层 16 | * @author yangwei 17 | */ 18 | @RestController 19 | @RequestMapping(value = "/user") 20 | public class UserController { 21 | 22 | @Autowired 23 | private IUserService userService; 24 | 25 | 26 | @PostMapping(value = "/findAll") 27 | public Object findAll() { 28 | throw new RuntimeException("ddd"); 29 | } 30 | 31 | @RequestMapping(value = "/findAll1") 32 | public ReturnVO findAll1(UserDO userDO) { 33 | System.out.println(userDO); 34 | return new ReturnVO(userService.findAll()); 35 | } 36 | 37 | @RequestMapping(value = "/test") 38 | public ReturnVO test() { 39 | throw new RuntimeException("测试非自定义运行时异常"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/dao/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation.dao; 2 | 3 | import indi.viyoung.viboot.exception.annotation.entity.UserDO; 4 | import org.apache.ibatis.annotations.*; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yangwei 10 | */ 11 | public interface UserMapper { 12 | 13 | /** 14 | * 查询所有信息 15 | * @return 人员列表 16 | */ 17 | @Select("SELECT * FROM user") 18 | @Results({ 19 | @Result(property = "userName", column = "user_name"), 20 | @Result(property = "password", column = "password") 21 | }) 22 | List findAll(); 23 | 24 | @Select("SELECT * FROM user WHERE id = #{id}") 25 | @Results({ 26 | @Result(property = "userName", column = "user_name"), 27 | @Result(property = "password", column = "password") 28 | }) 29 | UserDO get(Long id); 30 | 31 | @Insert("INSERT INTO user(user_name,password) VALUES(#{userName}, #{password})") 32 | void insert(UserDO user); 33 | 34 | @Update("UPDATE user SET user_name=#{userName},password=#{password} WHERE id =#{id}") 35 | void update(UserDO user); 36 | 37 | @Delete("DELETE FROM user WHERE id =#{id}") 38 | void delete(Long id); 39 | } 40 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * UserDO 7 | * @author yangwei 8 | */ 9 | @Data 10 | public class UserDO { 11 | 12 | private Long id; 13 | 14 | private String userName; 15 | 16 | private String password; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation.exception; 2 | 3 | import indi.viyoung.viboot.util.CommonUrl; 4 | import indi.viyoung.viboot.util.ReadPropertiesUtil; 5 | import indi.viyoung.viboot.util.ReturnVO; 6 | import org.springframework.http.HttpHeaders; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.RestControllerAdvice; 11 | import org.springframework.web.context.request.WebRequest; 12 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 13 | 14 | import java.util.Properties; 15 | 16 | import static indi.viyoung.viboot.util.ReturnCode.*; 17 | 18 | /** 19 | * 全局异常处理类 20 | * @author yangwei 21 | * 22 | * 用于全局返回json,如需返回ModelAndView请使用@ControllerAdvice 23 | */ 24 | @RestControllerAdvice 25 | public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { 26 | private static Properties properties = ReadPropertiesUtil.getProperties(System.getProperty("user.dir") + CommonUrl.RESPONSE_PROP_URL); 27 | 28 | @Override 29 | protected ResponseEntity handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) { 30 | return new ResponseEntity<>(handlerException(ex), HttpStatus.OK); 31 | } 32 | 33 | /** 34 | * 进入controller之后的异常捕获 35 | * @param e 捕获的异常 36 | * @return 封装的返回对象 37 | **/ 38 | @ExceptionHandler(Exception.class) 39 | public ReturnVO handlerException(Exception e) { 40 | ReturnVO returnVO = new ReturnVO(); 41 | String errorName = e.getClass().getName(); 42 | errorName = errorName.substring(errorName.lastIndexOf(".") + 1); 43 | if (e.getClass() == RuntimeException.class) { 44 | returnVO.setMessage(properties.getProperty(valueOf("RuntimeException").msg()) +": "+ e.getMessage()); 45 | returnVO.setCode(properties.getProperty(valueOf("RuntimeException").val())); 46 | } else { 47 | returnVO.setMessage(properties.getProperty(valueOf(errorName).msg())); 48 | returnVO.setCode(properties.getProperty(valueOf(errorName).val())); 49 | } 50 | return returnVO; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/exception/RequestExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation.exception; 2 | 3 | import indi.viyoung.viboot.util.ReturnCode; 4 | import indi.viyoung.viboot.util.ReturnVO; 5 | import org.springframework.boot.web.servlet.error.ErrorController; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * 请求路径有误 11 | * @author yangwei 12 | * @since 2019-01-02 18:13 13 | */ 14 | @RestController 15 | public class RequestExceptionHandler implements ErrorController { 16 | 17 | @Override 18 | public String getErrorPath() { 19 | return "/error"; 20 | } 21 | 22 | @RequestMapping("/error") 23 | public ReturnVO errorPage(){ 24 | return new ReturnVO(ReturnCode.UrlError); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation.service; 2 | 3 | 4 | import indi.viyoung.viboot.exception.annotation.entity.UserDO; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 用户事务接口 10 | * @author yangwei 11 | */ 12 | public interface IUserService { 13 | 14 | /** 15 | * 查询所有人员 16 | * @return 17 | */ 18 | List findAll(); 19 | 20 | List findAll1(); 21 | } 22 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/java/indi/viyoung/viboot/exception/annotation/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.exception.annotation.service.impl; 2 | 3 | import indi.viyoung.viboot.exception.NullResponseException; 4 | import indi.viyoung.viboot.exception.annotation.dao.UserMapper; 5 | import indi.viyoung.viboot.exception.annotation.entity.UserDO; 6 | import indi.viyoung.viboot.exception.annotation.service.IUserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | 13 | /** 14 | * @ClassName UserServiceImpl 15 | * @Description TODO 16 | * @Author vi 17 | * @Date 2018/12/13 9:29 AM 18 | */ 19 | @Service 20 | public class UserServiceImpl implements IUserService { 21 | 22 | @Autowired 23 | private UserMapper userMapper; 24 | 25 | @Override 26 | public List findAll() { 27 | if (true) { 28 | throw new NullResponseException(); 29 | } 30 | return userMapper.findAll(); 31 | } 32 | 33 | @Override 34 | public List findAll1() { 35 | return userMapper.findAll(); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /viboot-exception-annotation/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8086 3 | 4 | spring: 5 | datasource: 6 | driver-class-name: com.mysql.cj.jdbc.Driver 7 | url: jdbc:mysql://localhost:3306/viboot?useUnicode=true&characterEncoding=utf-8 8 | username: root 9 | password: Passw0rd 10 | devtools: 11 | restart: 12 | additional-paths: src/main/java -------------------------------------------------------------------------------- /viboot-mybatis-grace/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-mybatis-grace 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-mybatis-grace 13 | 14 | 15 | 16 | org.mybatis.spring.boot 17 | mybatis-spring-boot-starter 18 | 1.3.2 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/java/indi/viyoung/viboot/mybatis/ViBootMybatisGraceApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @ClassName ViBootMybatisApplication 9 | * @Description TODO 10 | * @Author vi 11 | * @Date 2018/12/12 10:07 PM 12 | */ 13 | @SpringBootApplication 14 | public class ViBootMybatisGraceApplication { 15 | public static void main(String[] args) { 16 | SpringApplication.run(ViBootMybatisGraceApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/java/indi/viyoung/viboot/mybatis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.controller; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import indi.viyoung.viboot.mybatis.service.IUserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 用户实体类 13 | */ 14 | @RestController 15 | @RequestMapping(value = "/user") 16 | public class UserController { 17 | 18 | @Autowired 19 | private IUserService userService; 20 | 21 | @RequestMapping(value = "/findAll") 22 | public List findAll() { 23 | return userService.findAll(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/java/indi/viyoung/viboot/mybatis/dao/BaseDao.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.dao; 2 | 3 | import java.util.List; 4 | 5 | 6 | public interface BaseDao { 7 | 8 | /** 9 | * 查找对象 10 | * 11 | * @param str 12 | * @param obj 13 | * @return 14 | * @throws Exception 15 | */ 16 | Object findForList(String str, Object obj); 17 | 18 | /** 19 | * 保存对象 20 | * 21 | * @param str 22 | * @param obj 23 | * @return 24 | * @throws Exception 25 | */ 26 | int insert(String str, Object obj); 27 | 28 | /** 29 | * 批量保存对象 30 | * 31 | * @param str 32 | * @param objs 33 | * @return 34 | * @throws Exception 35 | */ 36 | int batchInsert(String str, List objs); 37 | 38 | /** 39 | * 修改对象 40 | * 41 | * @param str 42 | * @param obj 43 | * @return 44 | * @throws Exception 45 | */ 46 | int update(String str, Object obj); 47 | 48 | /** 49 | * 批量修改对象 50 | * 51 | * @param str 52 | * @param objs 53 | * @return 54 | * @throws Exception 55 | */ 56 | void batchUpdate(String str, List objs); 57 | 58 | /** 59 | * 批量修改对象(通过sql的case/when拼接) 60 | * 61 | * @param str 62 | * @param objs 63 | * @return 64 | * @throws Exception 65 | */ 66 | int batchUpdateCaseWhen(String str, List objs); 67 | 68 | /** 69 | * 删除对象 70 | * 71 | * @param str 72 | * @param obj 73 | * @return 74 | * @throws Exception 75 | */ 76 | int delete(String str, Object obj); 77 | 78 | /** 79 | * 批量删除对象 80 | * 81 | * @param str 82 | * @param obj 83 | * @return 84 | * @throws Exception 85 | */ 86 | int batchDelete(String str, List objs); 87 | 88 | /** 89 | * 查找对象 90 | * 91 | * @param str 92 | * @param obj 93 | * @return 94 | * @throws Exception 95 | */ 96 | Object findForObject(String str, Object obj); 97 | 98 | /** 99 | * 查找对象 100 | * 101 | * @param str 102 | * @return 103 | * @throws Exception 104 | */ 105 | Object findForObject(String str); 106 | 107 | 108 | /** 109 | * 查找对象封装成Map 110 | * 111 | * @param s 112 | * @param obj 113 | * @return 114 | * @throws Exception 115 | */ 116 | Object findForMap(String sql, Object obj, String key, String value); 117 | 118 | } 119 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/java/indi/viyoung/viboot/mybatis/dao/impl/BaseDaoImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.dao.impl; 2 | 3 | import java.util.List; 4 | 5 | import javax.annotation.Resource; 6 | 7 | import indi.viyoung.viboot.mybatis.dao.BaseDao; 8 | import org.apache.ibatis.session.ExecutorType; 9 | import org.apache.ibatis.session.SqlSession; 10 | import org.apache.ibatis.session.SqlSessionFactory; 11 | import org.mybatis.spring.SqlSessionTemplate; 12 | import org.springframework.stereotype.Repository; 13 | 14 | 15 | /** 16 | * @author vi 17 | * @since 2019/03/01 18 | */ 19 | @Repository("baseDao") 20 | public class BaseDaoImpl implements BaseDao { 21 | 22 | @Resource(name = "sqlSessionTemplate") 23 | private SqlSessionTemplate sqlSessionTemplate; 24 | 25 | /** 26 | * 保存对象 27 | * 28 | * @param str 29 | * @param obj 30 | * @return 31 | */ 32 | @Override 33 | public int insert(String str, Object obj) { 34 | return sqlSessionTemplate.insert(str, obj); 35 | } 36 | 37 | /** 38 | * 批量更新 39 | * 40 | * @param str 41 | * @param objs 42 | * @return 43 | */ 44 | @Override 45 | public int batchInsert(String str, List objs) { 46 | return sqlSessionTemplate.insert(str, objs); 47 | } 48 | 49 | /** 50 | * 修改对象 51 | * 52 | * @param str 53 | * @param obj 54 | * @return 55 | */ 56 | @Override 57 | public int update(String str, Object obj) { 58 | return sqlSessionTemplate.update(str, obj); 59 | } 60 | 61 | /** 62 | * 批量更新 63 | * 64 | * @param str 65 | * @param obj 66 | * @return 67 | */ 68 | @Override 69 | public void batchUpdate(String str, List objs) { 70 | SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory(); 71 | // 批量执行器 72 | SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); 73 | try { 74 | if (objs != null) { 75 | for (int i = 0, size = objs.size(); i < size; i++) { 76 | sqlSession.update(str, objs.get(i)); 77 | } 78 | sqlSession.flushStatements(); 79 | sqlSession.commit(); 80 | sqlSession.clearCache(); 81 | } 82 | } finally { 83 | sqlSession.close(); 84 | } 85 | } 86 | 87 | /** 88 | * 批量修改对象 89 | * 90 | * @param str 91 | * @param obj 92 | * @return 93 | */ 94 | @Override 95 | public int batchUpdateCaseWhen(String str, List objs) { 96 | return sqlSessionTemplate.update(str, objs); 97 | } 98 | 99 | /** 100 | * 批量更新 101 | * 102 | * @param str 103 | * @param obj 104 | * @return 105 | */ 106 | @Override 107 | public int batchDelete(String str, List objs) { 108 | return sqlSessionTemplate.delete(str, objs); 109 | } 110 | 111 | /** 112 | * 删除对象 113 | * 114 | * @param str 115 | * @param obj 116 | * @return 117 | */ 118 | @Override 119 | public int delete(String str, Object obj) { 120 | return sqlSessionTemplate.delete(str, obj); 121 | } 122 | 123 | /** 124 | * 查找对象 125 | * 126 | * @param str 127 | * @param obj 128 | * @return 129 | */ 130 | @Override 131 | public Object findForObject(String str) { 132 | return sqlSessionTemplate.selectOne(str); 133 | } 134 | 135 | /** 136 | * 查找对象 137 | * 138 | * @param str 139 | * @param obj 140 | * @return 141 | */ 142 | @Override 143 | public Object findForObject(String str, Object obj) { 144 | return sqlSessionTemplate.selectOne(str, obj); 145 | } 146 | 147 | /** 148 | * 查找对象 149 | * 150 | * @param str 151 | * @param obj 152 | * @return 153 | */ 154 | @Override 155 | public Object findForList(String str, Object obj) { 156 | return sqlSessionTemplate.selectList(str, obj); 157 | } 158 | 159 | @Override 160 | public Object findForMap(String str, Object obj, String key, String value) { 161 | return sqlSessionTemplate.selectMap(str, obj, key); 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/java/indi/viyoung/viboot/mybatis/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @ClassName UserDO 7 | * @Description TODO 8 | * @Author vi 9 | * @Date 2018/12/12 10:30 PM 10 | */ 11 | @Data 12 | public class UserDO { 13 | 14 | private Long id; 15 | 16 | private String username; 17 | 18 | private String password; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/java/indi/viyoung/viboot/mybatis/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 用户事务接口 9 | * @author yangwei 10 | */ 11 | public interface IUserService { 12 | 13 | /** 14 | * 查询所有人员 15 | * @return 16 | */ 17 | List findAll(); 18 | } 19 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/java/indi/viyoung/viboot/mybatis/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service.impl; 2 | 3 | import indi.viyoung.viboot.mybatis.dao.BaseDao; 4 | import indi.viyoung.viboot.mybatis.entity.UserDO; 5 | import indi.viyoung.viboot.mybatis.service.IUserService; 6 | import org.apache.ibatis.session.SqlSession; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @ClassName UserServiceImpl 14 | * @Description TODO 15 | * @Author vi 16 | * @Date 2018/12/13 9:29 AM 17 | */ 18 | @Service 19 | public class UserServiceImpl implements IUserService { 20 | 21 | @Autowired 22 | private BaseDao dao; 23 | 24 | 25 | @Override 26 | public List findAll() { 27 | return (List) dao.findForList("UserMapper.findAll", UserDO.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8084 3 | 4 | spring: 5 | datasource: 6 | driver-class-name: com.mysql.cj.jdbc.Driver 7 | url: jdbc:mysql://localhost:3306/viboot?useUnicode=true&characterEncoding=utf-8 8 | username: root 9 | password: Passw0rd 10 | 11 | mybatis: 12 | type-aliases-package: indi.viyoung.viboot.mybatis.entity 13 | config-location: classpath:mybatis/mybatis-config.xml 14 | mapper-locations: classpath:mybatis/mapper/*.xml -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/resources/mybatis/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | id, user_name, password 13 | 14 | 15 | 20 | 21 | 28 | 29 | 30 | INSERT INTO 31 | user 32 | (user_name,password) 33 | VALUES 34 | (#{username}, #{password}) 35 | 36 | 37 | 38 | UPDATE 39 | user 40 | SET 41 | user_name = #{username}, 42 | password = #{password}, 43 | WHERE 44 | id = #{id} 45 | 46 | 47 | 48 | DELETE FROM user WHERE id =#{id} 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /viboot-mybatis-grace/src/main/resources/mybatis/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-mybatis-plus 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-mybatis-plus 13 | 14 | 15 | 16 | 17 | 18 | com.baomidou 19 | mybatis-plus-boot-starter 20 | 3.0.6 21 | 22 | 23 | 24 | 25 | org.apache.velocity 26 | velocity 27 | 1.7 28 | 29 | 30 | 31 | 32 | org.freemarker 33 | freemarker 34 | 2.3.28 35 | 36 | 37 | 38 | indi.viyoung.course 39 | viboot-common 40 | 1.0-SNAPSHOT 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/java/indi/viyoung/viboot/mybatis/ViBootMybatisPlusApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import indi.viyoung.viboot.util.CORSFilter; 5 | import org.mybatis.spring.annotation.MapperScan; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.ComponentScan; 11 | 12 | /** 13 | * @author yangwei 14 | */ 15 | @SpringBootApplication 16 | @ComponentScan(value = "indi.viyoung.viboot.*") 17 | @MapperScan(value = "indi.viyoung.viboot.mybatis.mapper") 18 | public class ViBootMybatisPlusApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(ViBootMybatisPlusApplication.class, args); 22 | } 23 | 24 | /** 25 | * 分页插件 26 | */ 27 | @Bean 28 | public PaginationInterceptor paginationInterceptor() { 29 | return new PaginationInterceptor(); 30 | } 31 | 32 | @Bean 33 | public FilterRegistrationBean corsFilter() { 34 | FilterRegistrationBean reg = new FilterRegistrationBean(); 35 | CORSFilter filter = new CORSFilter(); 36 | reg.setFilter(filter); 37 | reg.setOrder(1); 38 | reg.addUrlPatterns("/*"); 39 | return reg; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/java/indi/viyoung/viboot/mybatis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author viyoung 14 | * @since 2019-01-23 15 | */ 16 | @Controller 17 | @RequestMapping("/user") 18 | public class UserController { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/java/indi/viyoung/viboot/mybatis/entity/User.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import java.io.Serializable; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | import lombok.experimental.Accessors; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author viyoung 16 | * @since 2019-01-23 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @Accessors(chain = true) 21 | public class User implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId(value = "id", type = IdType.AUTO) 26 | private Long id; 27 | 28 | private String password; 29 | 30 | private String userName; 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/java/indi/viyoung/viboot/mybatis/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.mapper; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.User; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/java/indi/viyoung/viboot/mybatis/mapper/xml/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/java/indi/viyoung/viboot/mybatis/service/UserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.User; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/java/indi/viyoung/viboot/mybatis/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service.impl; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.User; 4 | import indi.viyoung.viboot.mybatis.mapper.UserMapper; 5 | import indi.viyoung.viboot.mybatis.service.UserService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author viyoung 15 | * @since 2019-01-23 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements UserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8084 3 | 4 | mybatis-plus: 5 | configuration: 6 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 -------------------------------------------------------------------------------- /viboot-mybatis-plus/src/main/resources/mapper/user/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-mybatis-sqlsession 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-mybatis-sqlsession 13 | 14 | 15 | 16 | org.mybatis.spring.boot 17 | mybatis-spring-boot-starter 18 | 1.3.2 19 | 20 | 21 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/java/indi/viyoung/viboot/mybatis/ViBootMybatisSqlSessionApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @ClassName ViBootMybatisApplication 9 | * @Description TODO 10 | * @Author vi 11 | * @Date 2018/12/12 10:07 PM 12 | */ 13 | @SpringBootApplication 14 | @MapperScan("indi.viyoung.viboot.mybatis.mapper") 15 | public class ViBootMybatisSqlSessionApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(ViBootMybatisSqlSessionApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/java/indi/viyoung/viboot/mybatis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.controller; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import indi.viyoung.viboot.mybatis.service.IUserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 用户实体类 13 | */ 14 | @RestController 15 | @RequestMapping(value = "/user") 16 | public class UserController { 17 | 18 | @Autowired 19 | private IUserService userService; 20 | 21 | @RequestMapping(value = "/findAll") 22 | public List findAll() { 23 | return userService.findAll(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/java/indi/viyoung/viboot/mybatis/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @ClassName UserDO 7 | * @Description TODO 8 | * @Author vi 9 | * @Date 2018/12/12 10:30 PM 10 | */ 11 | @Data 12 | public class UserDO { 13 | 14 | private Long id; 15 | 16 | private String username; 17 | 18 | private String password; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/java/indi/viyoung/viboot/mybatis/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.mapper; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | public interface UserMapper { 8 | 9 | List findAll(); 10 | 11 | UserDO get(Long id); 12 | 13 | void insert(UserDO user); 14 | 15 | void update(UserDO user); 16 | 17 | void delete(Long id); 18 | } 19 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/java/indi/viyoung/viboot/mybatis/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 用户事务接口 9 | * @author yangwei 10 | */ 11 | public interface IUserService { 12 | 13 | /** 14 | * 查询所有人员 15 | * @return 16 | */ 17 | List findAll(); 18 | } 19 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/java/indi/viyoung/viboot/mybatis/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service.impl; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import indi.viyoung.viboot.mybatis.mapper.UserMapper; 5 | import indi.viyoung.viboot.mybatis.service.IUserService; 6 | import org.apache.ibatis.session.SqlSession; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @ClassName UserServiceImpl 14 | * @Description TODO 15 | * @Author vi 16 | * @Date 2018/12/13 9:29 AM 17 | */ 18 | @Service 19 | public class UserServiceImpl implements IUserService { 20 | 21 | 22 | @Autowired 23 | private SqlSession sqlSession; 24 | 25 | @Override 26 | public List findAll() { 27 | return sqlSession.selectList("indi.viyoung.viboot.mybatis.mapper.UserMapper.findAll"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | 4 | spring: 5 | datasource: 6 | driver-class-name: com.mysql.cj.jdbc.Driver 7 | url: jdbc:mysql://localhost:3306/viboot?useUnicode=true&characterEncoding=utf-8 8 | username: root 9 | password: Passw0rd 10 | 11 | mybatis: 12 | type-aliases-package: indi.viyoung.viboot.mybatis.entity 13 | config-location: classpath:mybatis/mybatis-config.xml 14 | mapper-locations: classpath:mybatis/mapper/*.xml -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/resources/mybatis/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | id, user_name, password 13 | 14 | 15 | 20 | 21 | 28 | 29 | 30 | INSERT INTO 31 | user 32 | (user_name,password) 33 | VALUES 34 | (#{username}, #{password}) 35 | 36 | 37 | 38 | UPDATE 39 | user 40 | SET 41 | user_name = #{username}, 42 | password = #{password}, 43 | WHERE 44 | id = #{id} 45 | 46 | 47 | 48 | DELETE FROM user WHERE id =#{id} 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /viboot-mybatis-sqlsession/src/main/resources/mybatis/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-mybatis-xml 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-mybatis-xml 13 | 14 | 15 | 16 | org.mybatis.spring.boot 17 | mybatis-spring-boot-starter 18 | 1.3.2 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/java/indi/viyoung/viboot/mybatis/ViBootMybatisXmlApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @ClassName ViBootMybatisApplication 9 | * @Description TODO 10 | * @Author vi 11 | * @Date 2018/12/12 10:07 PM 12 | */ 13 | @SpringBootApplication 14 | @MapperScan(value = "indi.viyoung.viboot.mybatis.mapper") 15 | public class ViBootMybatisXmlApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(ViBootMybatisXmlApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/java/indi/viyoung/viboot/mybatis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.controller; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import indi.viyoung.viboot.mybatis.service.IUserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 用户实体类 13 | */ 14 | @RestController 15 | @RequestMapping(value = "/user") 16 | public class UserController { 17 | 18 | @Autowired 19 | private IUserService userService; 20 | 21 | @RequestMapping(value = "/findAll") 22 | public List findAll() { 23 | return userService.findAll(); 24 | } 25 | 26 | @RequestMapping(value = "insert") 27 | public Integer insert(){ 28 | UserDO userDO = new UserDO(); 29 | userDO.setPassword("123456"); 30 | userDO.setUserName("vi-young"); 31 | return userService.insert(userDO); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/java/indi/viyoung/viboot/mybatis/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @ClassName UserDO 7 | * @Description TODO 8 | * @Author vi 9 | * @Date 2018/12/12 10:30 PM 10 | */ 11 | @Data 12 | public class UserDO { 13 | 14 | private Long id; 15 | 16 | private String userName; 17 | 18 | private String password; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/java/indi/viyoung/viboot/mybatis/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.mapper; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | public interface UserMapper { 8 | 9 | List findAll(); 10 | 11 | UserDO get(Long id); 12 | 13 | Integer insert(UserDO user); 14 | 15 | void update(UserDO user); 16 | 17 | void delete(Long id); 18 | } 19 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/java/indi/viyoung/viboot/mybatis/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 用户事务接口 9 | * @author yangwei 10 | */ 11 | public interface IUserService { 12 | 13 | /** 14 | * 查询所有人员 15 | * @return 16 | */ 17 | List findAll(); 18 | 19 | Integer insert(UserDO userDO); 20 | } 21 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/java/indi/viyoung/viboot/mybatis/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service.impl; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import indi.viyoung.viboot.mybatis.mapper.UserMapper; 5 | import indi.viyoung.viboot.mybatis.service.IUserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @ClassName UserServiceImpl 13 | * @Description TODO 14 | * @Author vi 15 | * @Date 2018/12/13 9:29 AM 16 | */ 17 | @Service 18 | public class UserServiceImpl implements IUserService { 19 | 20 | @Autowired 21 | private UserMapper userMapper; 22 | 23 | @Override 24 | public List findAll() { 25 | return userMapper.findAll(); 26 | } 27 | 28 | @Override 29 | public Integer insert(UserDO userDO) { 30 | return userMapper.insert(userDO); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 3 | 4 | 5 | mybatis: 6 | type-aliases-package: indi.viyoung.viboot.mybatis.entity 7 | config-location: classpath:mybatis/mybatis-config.xml 8 | mapper-locations: classpath:mybatis/mapper/*.xml -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/resources/mybatis/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 22 | 23 | 24 | INSERT INTO 25 | user 26 | (user_name,password) 27 | VALUES 28 | (#{username}, #{password}) 29 | 30 | 31 | 32 | UPDATE 33 | user 34 | SET 35 | user_name = #{username}, 36 | password = #{password}, 37 | WHERE 38 | id = #{id} 39 | 40 | 41 | 42 | DELETE FROM user WHERE id =#{id} 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /viboot-mybatis-xml/src/main/resources/mybatis/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /viboot-mybatis/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-mybatis/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-mybatis 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-mybatis/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-mybatis/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-mybatis/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-mybatis/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-mybatis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-mybatis 13 | 14 | 15 | org.mybatis.spring.boot 16 | mybatis-spring-boot-starter 17 | 1.3.2 18 | 19 | 20 | -------------------------------------------------------------------------------- /viboot-mybatis/src/main/java/indi/viyoung/viboot/mybatis/ViBootMybatisApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @ClassName ViBootMybatisApplication 9 | * @Description TODO 10 | * @Author vi 11 | * @Date 2018/12/12 10:07 PM 12 | */ 13 | @SpringBootApplication 14 | @MapperScan("indi.viyoung.viboot.mybatis.mapper") 15 | public class ViBootMybatisApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(ViBootMybatisApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /viboot-mybatis/src/main/java/indi/viyoung/viboot/mybatis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.controller; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import indi.viyoung.viboot.mybatis.service.IUserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 用户控制层 13 | * @author yangwei 14 | */ 15 | @RestController 16 | @RequestMapping(value = "/user") 17 | public class UserController { 18 | 19 | @Autowired 20 | private IUserService userService; 21 | 22 | @RequestMapping(value = "/findAll") 23 | public List findAll() { 24 | return userService.findAll(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /viboot-mybatis/src/main/java/indi/viyoung/viboot/mybatis/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @ClassName UserDO 7 | * @Description TODO 8 | * @Author vi 9 | * @Date 2018/12/12 10:30 PM 10 | */ 11 | @Data 12 | public class UserDO { 13 | 14 | private Long id; 15 | 16 | private String userName; 17 | 18 | private String password; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-mybatis/src/main/java/indi/viyoung/viboot/mybatis/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.mapper; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import org.apache.ibatis.annotations.*; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yangwei 10 | */ 11 | public interface UserMapper { 12 | 13 | /** 14 | * 查询所有信息 15 | * @return 人员列表 16 | */ 17 | @Select("SELECT * FROM user") 18 | @Results({ 19 | @Result(property = "userName", column = "user_name"), 20 | @Result(property = "password", column = "password") 21 | }) 22 | List findAll(); 23 | 24 | @Select("SELECT * FROM user WHERE id = #{id}") 25 | @Results({ 26 | @Result(property = "userName", column = "user_name"), 27 | @Result(property = "password", column = "password") 28 | }) 29 | UserDO get(Long id); 30 | 31 | @Insert("INSERT INTO user(user_name,password) VALUES(#{userName}, #{password})") 32 | void insert(UserDO user); 33 | 34 | @Update("UPDATE user SET user_name=#{userName},password=#{password} WHERE id =#{id}") 35 | void update(UserDO user); 36 | 37 | @Delete("DELETE FROM user WHERE id =#{id}") 38 | void delete(Long id); 39 | } 40 | -------------------------------------------------------------------------------- /viboot-mybatis/src/main/java/indi/viyoung/viboot/mybatis/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 用户事务接口 9 | * @author yangwei 10 | */ 11 | public interface IUserService { 12 | 13 | /** 14 | * 查询所有人员 15 | * @return 16 | */ 17 | List findAll(); 18 | } 19 | -------------------------------------------------------------------------------- /viboot-mybatis/src/main/java/indi/viyoung/viboot/mybatis/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.mybatis.service.impl; 2 | 3 | import indi.viyoung.viboot.mybatis.entity.UserDO; 4 | import indi.viyoung.viboot.mybatis.mapper.UserMapper; 5 | import indi.viyoung.viboot.mybatis.service.IUserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @ClassName UserServiceImpl 13 | * @Description TODO 14 | * @Author vi 15 | * @Date 2018/12/13 9:29 AM 16 | */ 17 | @Service 18 | public class UserServiceImpl implements IUserService { 19 | 20 | @Autowired 21 | private UserMapper userMapper; 22 | 23 | @Override 24 | public List findAll() { 25 | return userMapper.findAll(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /viboot-mybatis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | 4 | spring: 5 | datasource: 6 | driver-class-name: com.mysql.jdbc.Driver 7 | url: jdbc:mysql://localhost:3306/viboot?useUnicode=true&characterEncoding=utf-8 8 | username: root 9 | password: Passw0rd 10 | -------------------------------------------------------------------------------- /viboot-pagehelper/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-pagehelper/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-pagehelper 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-pagehelper/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-pagehelper/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-pagehelper/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-pagehelper/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-pagehelper/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-pagehelper 13 | 14 | 15 | 16 | 17 | org.mybatis.spring.boot 18 | mybatis-spring-boot-starter 19 | 2.0.0 20 | 21 | 22 | tk.mybatis 23 | mapper-spring-boot-starter 24 | 2.1.5 25 | 26 | 27 | com.github.pagehelper 28 | pagehelper-spring-boot-starter 29 | 1.2.10 30 | 31 | 32 | -------------------------------------------------------------------------------- /viboot-pagehelper/src/main/java/indi/viyoung/viboot/pagehelper/VibootPagehelperApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.pagehelper; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author vi 9 | * @since 2019/3/12 8:56 PM 10 | */ 11 | @SpringBootApplication 12 | @MapperScan(value = "indi.viyoung.viboot.pagehelper.mapper") 13 | public class VibootPagehelperApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(VibootPagehelperApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /viboot-pagehelper/src/main/java/indi/viyoung/viboot/pagehelper/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.pagehelper.controller; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.github.pagehelper.PageHelper; 5 | import com.github.pagehelper.PageInfo; 6 | import indi.viyoung.viboot.pagehelper.entity.UserDO; 7 | import indi.viyoung.viboot.pagehelper.service.IUserService; 8 | import org.mybatis.spring.SqlSessionTemplate; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.HttpRequest; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import javax.annotation.Resource; 16 | import javax.servlet.http.HttpServletRequest; 17 | import java.util.HashMap; 18 | 19 | /** 20 | * 用户控制层 21 | * @author yangwei 22 | */ 23 | @RestController 24 | @RequestMapping(value = "/users") 25 | public class UserController { 26 | 27 | @Autowired 28 | private IUserService userService; 29 | 30 | @Resource(name = "sqlSessionTemplate") 31 | private SqlSessionTemplate sqlSessionTemplate; 32 | 33 | @GetMapping("/page0") 34 | public PageInfo findAll() { 35 | // 只有紧跟在PageHelper.startPage方法后的第一个Mybatis的查询(Select)方法会被分页。 36 | PageHelper.startPage(1, 10); 37 | return PageInfo.of(userService.findAll()); 38 | } 39 | 40 | @GetMapping("/page1") 41 | public PageInfo findPage(HttpServletRequest request) { 42 | PageHelper.startPage(request); 43 | return PageInfo.of(userService.findAll()); 44 | } 45 | 46 | @GetMapping("/page2") 47 | public PageInfo findPage2(HttpServletRequest request) { 48 | return PageInfo.of(userService.findPage(request)); 49 | } 50 | 51 | @GetMapping("/page3") 52 | public PageInfo findPage3() { 53 | // 只有紧跟在PageHelper.startPage方法后的第一个Mybatis的查询(Select)方法会被分页。 54 | PageHelper.offsetPage(1, 10); 55 | return PageInfo.of(userService.findAll()); 56 | } 57 | 58 | @GetMapping("/page4") 59 | public PageInfo findPage4() { 60 | return PageHelper.startPage(1, 10).doSelectPageInfo(() -> userService.findAll()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /viboot-pagehelper/src/main/java/indi/viyoung/viboot/pagehelper/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.pagehelper.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @ClassName UserDO 7 | * @Description TODO 8 | * @Author vi 9 | * @Date 2018/12/12 10:30 PM 10 | */ 11 | @Data 12 | public class UserDO { 13 | 14 | private Long id; 15 | 16 | private String userName; 17 | 18 | private String password; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-pagehelper/src/main/java/indi/viyoung/viboot/pagehelper/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.pagehelper.mapper; 2 | 3 | import indi.viyoung.viboot.pagehelper.entity.UserDO; 4 | import org.apache.ibatis.annotations.*; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author yangwei 12 | */ 13 | public interface UserMapper { 14 | 15 | /** 16 | * 查询所有信息 17 | * @return 人员列表 18 | */ 19 | @Select("SELECT * FROM user") 20 | @Results({ 21 | @Result(property = "userName", column = "user_name"), 22 | @Result(property = "password", column = "password") 23 | }) 24 | List findAll(); 25 | 26 | @Select("SELECT * FROM user WHERE id = #{id}") 27 | @Results({ 28 | @Result(property = "userName", column = "user_name"), 29 | @Result(property = "password", column = "password") 30 | }) 31 | UserDO get(Long id); 32 | 33 | @Insert("INSERT INTO user(user_name,password) VALUES(#{userName}, #{password})") 34 | void insert(UserDO user); 35 | 36 | @Update("UPDATE user SET user_name=#{userName},password=#{password} WHERE id =#{id}") 37 | void update(UserDO user); 38 | 39 | @Delete("DELETE FROM user WHERE id =#{id}") 40 | void delete(Long id); 41 | 42 | @Select("SELECT * FROM user") 43 | @Results({ 44 | @Result(property = "userName", column = "user_name"), 45 | @Result(property = "password", column = "password") 46 | }) 47 | List findPage(HttpServletRequest request); 48 | } 49 | -------------------------------------------------------------------------------- /viboot-pagehelper/src/main/java/indi/viyoung/viboot/pagehelper/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.pagehelper.service; 2 | 3 | import indi.viyoung.viboot.pagehelper.entity.UserDO; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * 用户事务接口 11 | * @author yangwei 12 | */ 13 | public interface IUserService { 14 | 15 | /** 16 | * 查询所有人员 17 | * @return 18 | */ 19 | List findAll(); 20 | 21 | List findPage(HttpServletRequest request); 22 | } 23 | -------------------------------------------------------------------------------- /viboot-pagehelper/src/main/java/indi/viyoung/viboot/pagehelper/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.pagehelper.service.impl; 2 | 3 | 4 | import indi.viyoung.viboot.pagehelper.entity.UserDO; 5 | import indi.viyoung.viboot.pagehelper.mapper.UserMapper; 6 | import indi.viyoung.viboot.pagehelper.service.IUserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import java.util.List; 12 | 13 | /** 14 | * @ClassName UserServiceImpl 15 | * @Description TODO 16 | * @Author vi 17 | * @Date 2018/12/13 9:29 AM 18 | */ 19 | @Service 20 | public class UserServiceImpl implements IUserService { 21 | 22 | @Autowired 23 | private UserMapper userMapper; 24 | 25 | @Override 26 | public List findAll() { 27 | return userMapper.findAll(); 28 | } 29 | 30 | @Override 31 | public List findPage(HttpServletRequest parameterMap) { 32 | return userMapper.findPage(parameterMap); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /viboot-pagehelper/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | pagehelper: 5 | # dialect: ① 6 | helper-dialect: mysql # 分页插件会自动检测当前的数据库链接,自动选择合适的分页方式(可以不设置) 7 | auto-dialect: true # 上面数据库设置后,下面的设置为true不会改变上面的结果(默认为true) 8 | page-size-zero: false # ② 9 | reasonable: true # ③ 10 | offset-as-page-num: false # 默认值为 false,该参数对使用 RowBounds 作为分页参数时有效。(一般用不着) 11 | row-bounds-with-count: false # 默认值为 false,RowBounds是否进行count查询(一般用不着) 12 | #params: ④ 13 | #support-methods-arguments: 和params配合使用,具体可以看下面的讲解 14 | auto-runtime-dialect: false # 默认值为 false。设置为 true 时,允许在运行时根据多数据源自动识别对应方言的分页 15 | close-conn: true # ⑤ 16 | default-count: true # 用于控制默认不带 count 查询的方法中,是否执行 count 查询 17 | #dialect-alias: ⑥ 18 | 19 | spring: 20 | redis: 21 | host: localhost 22 | port: 6379 23 | password: 123456 24 | lettuce: 25 | pool: 26 | max-active: 8 27 | max-idle: 8 28 | min-idle: 0 29 | max-wait: -1ms -------------------------------------------------------------------------------- /viboot-rds/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-rds/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-rds 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-rds/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-rds/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-rds/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-rds/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-rds/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-rds 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-data-redis 19 | 20 | 21 | org.mybatis.spring.boot 22 | mybatis-spring-boot-starter 23 | 1.3.2 24 | 25 | 26 | org.apache.commons 27 | commons-pool2 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-cache 32 | 33 | 34 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/VibootRedisApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cache.annotation.EnableCaching; 7 | 8 | /** 9 | * @author vi 10 | * @since 2019/3/20 10:51 PM 11 | */ 12 | @SpringBootApplication 13 | @MapperScan(value = "indi.viyoung.viboot.redis.mapper") 14 | @EnableCaching 15 | public class VibootRedisApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(VibootRedisApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/base/RedisDao.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis.base; 2 | import java.util.List; 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | /** 7 | * RedisDao接口类 8 | */ 9 | public interface RedisDao { 10 | 11 | /** 12 | * 判断缓存中是否有对应的value 13 | * 14 | * @param key 15 | * @return boolean 16 | */ 17 | public boolean existsKey(Object key); 18 | 19 | /** 20 | * 根据key获取key列表(key值可为模糊匹配---taskInfo:taskDetail:* <---> *代表任意字符) 21 | * 22 | * @param pattern 23 | * @return Set 24 | */ 25 | public Set keys(Object pattern); 26 | 27 | /** 28 | * 根据key删除对应的value 29 | * 30 | * @param key 31 | */ 32 | public boolean delete(Object key); 33 | 34 | /** 35 | * 根据key获取个数 36 | * 37 | * @param key 38 | */ 39 | public int count(Object key); 40 | 41 | /** 42 | * 批量删除对应的value 43 | * 44 | * @param keys 45 | */ 46 | public void delete(String[] keys); 47 | 48 | /** 49 | * 批量删除key(key值可为模糊匹配---taskInfo:taskDetail:* <---> *代表任意字符) 50 | * 51 | * @param pattern 52 | */ 53 | public long deletePattern(Object pattern); 54 | 55 | /** 56 | * 批量删除对应的value 57 | * 58 | * @param keys 59 | */ 60 | public long delete(Set keys); 61 | 62 | /** 63 | * 写入缓存(操作字符串) 64 | * 65 | * @param key 66 | * @param value 67 | * @return boolean 68 | */ 69 | public boolean vSet(Object key, Object value); 70 | 71 | /** 72 | * 写入缓存设置时效时间(操作字符串) 73 | * 74 | * @param key 75 | * @param value 76 | * @return boolean 77 | */ 78 | public boolean vSet(Object key, Object value, Long expireTime); 79 | 80 | /** 81 | * 更新写入缓存设置时效时间(操作字符串) 82 | * 83 | * @param key 84 | * @return boolean 85 | */ 86 | public boolean vSetUpdate(Object key, Long expireTime); 87 | 88 | /** 89 | * 读取缓存(操作字符串) 90 | * 91 | * @param key 92 | * @return Object 93 | */ 94 | public Object vGet(Object key); 95 | 96 | /** 97 | * 哈希 添加(操作hash) 98 | * 99 | * @param key 100 | * @param hashKey 101 | * @param value 102 | */ 103 | public void hmSet(Object key, Object hashKey, Object value); 104 | 105 | /** 106 | * 哈希 添加(操作hash) 107 | * 108 | * @param key 109 | * @param map 110 | */ 111 | public void hmSetAll(Object key, Map map); 112 | 113 | /** 114 | * 哈希获取数据(操作hash) 115 | * 116 | * @param key 117 | * @return Map 118 | */ 119 | public Map hmGet(Object key); 120 | 121 | /** 122 | * 哈希获取数据(操作hash) 123 | * 124 | * @param key 125 | * @param hashKey 126 | * @return Object 127 | */ 128 | public Object hmGet(Object key, Object hashKey); 129 | 130 | /** 131 | * 哈希删除数据(操作hash) 132 | * 133 | * @param key 134 | * @param hashKey 135 | * @return Object 136 | */ 137 | public Object hmDel(Object key, Object hashKey); 138 | 139 | /** 140 | * 获取列表中个数 141 | * 142 | * @param k 143 | * @return long 144 | */ 145 | public long lSize(Object k); 146 | 147 | /** 148 | * 通过其索引从列表获取第一个元素(操作list) 149 | * 150 | * @param key 151 | * @return Object 152 | */ 153 | public Object lindexFirst(Object key); 154 | 155 | /** 156 | * 通过其索引从列表获取元素(操作list) 157 | * 158 | * @param key 159 | * @param index:索引位置,从0开始 160 | * @return Object 161 | */ 162 | public Object lindex(Object key, long index); 163 | 164 | /** 165 | * 从左向右添加列表(操作list) 166 | * 167 | * @param k 168 | * @param v 169 | */ 170 | public void lLeftPush(Object k, Object v); 171 | 172 | /** 173 | * 从左向右添加列表(操作list);如果bool=true,会删除列表中已经存在的数据,然后再进行添加(仅针对字符串列表,其它待测) 174 | * 175 | * @param k 176 | * @param v 177 | * @param bool 178 | */ 179 | public void lLeftPush(Object k, Object v, boolean bool); 180 | 181 | /** 182 | * 从左向右添加列表(操作list) 183 | * 184 | * @param k 185 | * @param lst 186 | */ 187 | public void lLeftPushAll(Object k, List lst); 188 | 189 | /** 190 | * 从右向左添加列表(操作list) 191 | * 192 | * @param k 193 | * @param v 194 | */ 195 | public void lRightPush(Object k, Object v); 196 | 197 | /** 198 | * 从右向左添加列表(操作list);如果bool=true,会删除列表中已经存在的数据,然后再进行添加(仅针对字符串列表,其它待测) 199 | * 200 | * @param k 201 | * @param v 202 | * @param bool 203 | */ 204 | public void lRightPush(Object k, Object v, boolean bool); 205 | 206 | /** 207 | * 从右向左添加列表(操作list) 208 | * 209 | * @param k 210 | * @param lst 211 | */ 212 | public void lRightPushAll(Object k, List lst); 213 | 214 | /** 215 | * 删除并获取列表中的第1个元素(操作list) 216 | * 217 | * @param k 218 | * @return Object 219 | */ 220 | public Object lLeftPop(Object k); 221 | 222 | /** 223 | * 删除并获取列表中的最后1个元素(操作list) 224 | * 225 | * @param k 226 | * @return Object 227 | */ 228 | public Object lRightPop(Object k); 229 | 230 | /** 231 | * 移除k中的count个,返回删除的个数;如果没有这个元素则返回0(操作list) 232 | * 233 | * @param k 234 | * @param count 235 | * @return long 236 | */ 237 | public long lRemove(Object k, long count); 238 | 239 | /** 240 | * 移除k中值为v的count个,返回删除的个数;如果没有这个元素则返回0(操作list) 241 | * 242 | * @param k 243 | * @param count 244 | * @param v 245 | * @return long 246 | */ 247 | public long lRemove(Object k, long count, Object v); 248 | 249 | /** 250 | * 移除k中值为v的所有数据,返回删除的个数;如果没有这个元素则返回0(操作list) 251 | * 252 | * @param k 253 | * @param v 254 | * @param v 255 | * @return long 256 | */ 257 | public long lRemove(Object k, Object v); 258 | 259 | /** 260 | * 根据key获取获取List列表(操作list) 261 | * 262 | * @param key 263 | * @return Object 264 | */ 265 | public Object lRange(Object key); 266 | 267 | /** 268 | * 根据key获取列表中第start至end的数据(操作list) 269 | * 270 | * @param k 271 | * @param start 272 | * @param end 273 | * @return List 274 | */ 275 | public List lRange(Object k, long start, long end); 276 | 277 | /** 278 | * 集合添加 279 | * 280 | * @param key 281 | * @param value 282 | */ 283 | public void sAdd(Object key, Object value); 284 | 285 | /** 286 | * 集合获取 287 | * 288 | * @param key 289 | * @return Set 290 | */ 291 | public Set sMembers(Object key); 292 | 293 | /** 294 | * 有序集合添加 295 | * 296 | * @param key 297 | * @param value 298 | * @param scoure 299 | */ 300 | public void zAdd(Object key, Object value, double scoure); 301 | 302 | /** 303 | * 有序集合获取 304 | * 305 | * @param key 306 | * @param scoure 307 | * @param scoure1 308 | * @return Set 309 | */ 310 | public Set rangeByScore(Object key, double scoure, double scoure1); 311 | 312 | /** 313 | * 将hashKey中储存的数字加上指定的增量值(操作hash) 314 | * 315 | * @param key 316 | * @param value 317 | * @return boolean 318 | */ 319 | public void hmSetIncrement(Object key, Object hashKey, Long value); 320 | 321 | } 322 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/base/impl/AbstractBaseRedisDao.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis.base.impl; 2 | 3 | import org.springframework.data.redis.core.RedisTemplate; 4 | import org.springframework.data.redis.serializer.RedisSerializer; 5 | 6 | import javax.annotation.Resource; 7 | 8 | /** 9 | * @author yangwei 10 | * @since 2019/03/20 11 | * redis抽象类 12 | */ 13 | public abstract class AbstractBaseRedisDao { 14 | 15 | @Resource(name = "redisTemplate") 16 | protected RedisTemplate redisTemplate; 17 | 18 | /** 19 | * 设置redisTemplate 20 | * 21 | * @param redisTemplate 22 | */ 23 | public void setRedisTemplate(RedisTemplate redisTemplate) { 24 | this.redisTemplate = redisTemplate; 25 | } 26 | 27 | /** 28 | * 获取 RedisSerializer 29 | */ 30 | protected RedisSerializer getRedisSerializer() { 31 | return redisTemplate.getStringSerializer(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis.controller; 2 | 3 | import indi.viyoung.viboot.redis.entity.UserDO; 4 | import indi.viyoung.viboot.redis.service.IUserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.DeleteMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.websocket.server.PathParam; 12 | import java.util.List; 13 | 14 | /** 15 | * 用户实体类 16 | */ 17 | @RestController 18 | @RequestMapping(value = "/user") 19 | public class UserController { 20 | 21 | @Autowired 22 | private IUserService userService; 23 | 24 | @RequestMapping(value = "/findAll") 25 | public List findAll() { 26 | return userService.findAll(); 27 | } 28 | 29 | @RequestMapping(value = "insert") 30 | public Integer insert(){ 31 | UserDO userDO = new UserDO(); 32 | userDO.setPassword("123456"); 33 | userDO.setUsername("vi-young"); 34 | return userService.insert(userDO); 35 | } 36 | 37 | @RequestMapping(value = "/{id}") 38 | public UserDO findOne(@PathVariable Long id) { 39 | return userService.findOne(id); 40 | } 41 | 42 | @RequestMapping(value="/update") 43 | public void update() { 44 | UserDO userDO = new UserDO(); 45 | userDO.setId(10000002L); 46 | userDO.setUsername("redis"); 47 | userDO.setPassword("123456"); 48 | userService.update(userDO); 49 | } 50 | 51 | @RequestMapping(value = "/delete/{id}") 52 | public void delete(@PathVariable Long id) { 53 | userService.delete(id); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @ClassName UserDO 9 | * @Description TODO 10 | * @Author vi 11 | * @Date 2018/12/12 10:30 PM 12 | */ 13 | @Data 14 | public class UserDO implements Serializable { 15 | 16 | private static final long serialVersionUID = -2910356307341008947L; 17 | 18 | private Long id; 19 | 20 | private String username; 21 | 22 | private String password; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis.mapper; 2 | 3 | import indi.viyoung.viboot.redis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | public interface UserMapper { 8 | 9 | List findAll(); 10 | 11 | UserDO get(Long id); 12 | 13 | Integer insert(UserDO user); 14 | 15 | int update(UserDO user); 16 | 17 | int delete(Long id); 18 | } 19 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis.service; 2 | 3 | import indi.viyoung.viboot.redis.entity.UserDO; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 用户事务接口 9 | * @author yangwei 10 | */ 11 | public interface IUserService { 12 | 13 | /** 14 | * 查询所有人员 15 | * @return 16 | */ 17 | List findAll(); 18 | 19 | Integer insert(UserDO userDO); 20 | 21 | UserDO findOne(Long id); 22 | 23 | int delete(Long id); 24 | 25 | UserDO update(UserDO userDO); 26 | } 27 | -------------------------------------------------------------------------------- /viboot-rds/src/main/java/indi/viyoung/viboot/redis/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.redis.service.impl; 2 | 3 | import indi.viyoung.viboot.redis.base.RedisDao; 4 | import indi.viyoung.viboot.redis.entity.UserDO; 5 | import indi.viyoung.viboot.redis.mapper.UserMapper; 6 | import indi.viyoung.viboot.redis.service.IUserService; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.cache.annotation.CacheEvict; 10 | import org.springframework.cache.annotation.CachePut; 11 | import org.springframework.cache.annotation.Cacheable; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * @ClassName UserServiceImpl 18 | * @Description TODO 19 | * @Author vi 20 | * @Date 2018/12/13 9:29 AM 21 | */ 22 | @Service 23 | @Slf4j 24 | public class UserServiceImpl implements IUserService { 25 | 26 | @Autowired 27 | private UserMapper userMapper; 28 | 29 | @Override 30 | 31 | public List findAll() { 32 | 33 | return userMapper.findAll(); 34 | } 35 | 36 | @Override 37 | public Integer insert(UserDO userDO) { 38 | return userMapper.insert(userDO); 39 | } 40 | 41 | @Override 42 | @Cacheable(value = "users", key = "#id") 43 | public UserDO findOne(Long id) { 44 | log.info("From MYSQL"); 45 | return userMapper.get(id); 46 | } 47 | 48 | @Override 49 | @CachePut(value = "users", key = "#userDO.id") 50 | public UserDO update(UserDO userDO) { 51 | if (userMapper.update(userDO) > 0) { 52 | return userMapper.get(userDO.getId()); 53 | } 54 | return null; 55 | } 56 | 57 | @Override 58 | @CacheEvict(value = "users", key = "#id") 59 | public int delete(Long id) { 60 | return userMapper.delete(id); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /viboot-rds/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 3 | 4 | mybatis: 5 | type-aliases-package: indi.viyoung.viboot.indi.entity 6 | config-location: classpath:mybatis/mybatis-config.xml 7 | mapper-locations: classpath:mybatis/mapper/*.xml 8 | 9 | spring: 10 | redis: 11 | host: 127.0.0.1 # IP 12 | port: 6379 # 端口号 13 | password: 123456 # 密码 14 | lettuce: 15 | pool: 16 | max-active: 8 # 连接池最大连接数 17 | max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) 18 | min-idle: 0 # 连接池中的最小空闲连接 19 | max-idle: 8 # 连接池中的最大空闲连接 -------------------------------------------------------------------------------- /viboot-rds/src/main/resources/mybatis/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 22 | 23 | 24 | INSERT INTO 25 | user 26 | (user_name,password) 27 | VALUES 28 | (#{username}, #{password}) 29 | 30 | 31 | 32 | UPDATE 33 | user 34 | SET 35 | user_name = #{username}, 36 | password = #{password} 37 | WHERE 38 | id = #{id} 39 | 40 | 41 | 42 | DELETE FROM user WHERE id =#{id} 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /viboot-rds/src/main/resources/mybatis/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /viboot-restful/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-restful/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-restful 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-restful/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-restful/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-restful/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-restful/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-restful/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-restful 13 | 14 | 15 | 16 | com.baomidou 17 | mybatis-plus-boot-starter 18 | 3.0.6 19 | 20 | 21 | 22 | org.apache.velocity 23 | velocity 24 | 1.7 25 | 26 | 27 | 28 | 29 | org.freemarker 30 | freemarker 31 | 2.3.28 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /viboot-restful/src/main/java/indi/viyoung/viboot/restful/VibootRestfulApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.restful; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author vi 9 | * @since 2019/1/23 9:20 PM 10 | */ 11 | @SpringBootApplication 12 | @MapperScan(value = "indi.viyoung.viboot.restful.mapper") 13 | public class VibootRestfulApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(VibootRestfulApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /viboot-restful/src/main/java/indi/viyoung/viboot/restful/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.restful.controller; 2 | 3 | import indi.viyoung.viboot.restful.entity.User; 4 | import indi.viyoung.viboot.restful.service.UserService; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * 前端控制器 14 | *

15 | * 16 | * @author viyoung 17 | * @since 2019-01-23 18 | */ 19 | @RestController 20 | @RequestMapping("/users") 21 | @Slf4j 22 | @CrossOrigin 23 | public class UserController { 24 | 25 | @Autowired 26 | private UserService userService; 27 | 28 | @GetMapping 29 | public List get() { 30 | log.info("GET方法执行。。。"); 31 | return userService.list(); 32 | } 33 | 34 | @GetMapping(value = "/{id}") 35 | public User get(@PathVariable String id) { 36 | log.info("GET..{}...方法执行。。。",id); 37 | return userService.getById(id); 38 | } 39 | 40 | @PostMapping 41 | public void post() { 42 | log.info("POST方法执行。。。"); 43 | } 44 | 45 | @PutMapping 46 | public void put() { 47 | log.info("PUT方法执行。。。"); 48 | } 49 | 50 | @DeleteMapping 51 | public void delete() { 52 | log.info("DELETE方法执行。。。"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /viboot-restful/src/main/java/indi/viyoung/viboot/restful/entity/User.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.restful.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import java.io.Serializable; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | import lombok.experimental.Accessors; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author viyoung 16 | * @since 2019-01-23 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @Accessors(chain = true) 21 | public class User implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId(value = "id", type = IdType.AUTO) 26 | private Long id; 27 | 28 | private String password; 29 | 30 | private String userName; 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /viboot-restful/src/main/java/indi/viyoung/viboot/restful/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.restful.mapper; 2 | 3 | import indi.viyoung.viboot.restful.entity.User; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-restful/src/main/java/indi/viyoung/viboot/restful/mapper/xml/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-restful/src/main/java/indi/viyoung/viboot/restful/service/UserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.restful.service; 2 | 3 | import indi.viyoung.viboot.restful.entity.User; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-restful/src/main/java/indi/viyoung/viboot/restful/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.restful.service.impl; 2 | 3 | import indi.viyoung.viboot.restful.entity.User; 4 | import indi.viyoung.viboot.restful.mapper.UserMapper; 5 | import indi.viyoung.viboot.restful.service.UserService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author viyoung 15 | * @since 2019-01-23 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements UserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-restful/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8088 3 | -------------------------------------------------------------------------------- /viboot-restful/src/main/resources/mapper/user/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-shiro/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-shiro 13 | 14 | 15 | -------------------------------------------------------------------------------- /viboot-swagger2/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /viboot-swagger2/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | viboot-swagger2 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /viboot-swagger2/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /viboot-swagger2/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=true 3 | org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations 4 | org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations 5 | -------------------------------------------------------------------------------- /viboot-swagger2/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.processAnnotations=enabled 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /viboot-swagger2/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /viboot-swagger2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-swagger2 13 | 14 | 15 | 16 | com.baomidou 17 | mybatis-plus-boot-starter 18 | 3.0.6 19 | 20 | 21 | 22 | org.apache.velocity 23 | velocity 24 | 1.7 25 | 26 | 27 | 28 | 29 | org.freemarker 30 | freemarker 31 | 2.3.28 32 | 33 | 34 | 35 | 36 | io.springfox 37 | springfox-swagger2 38 | 2.9.2 39 | 40 | 41 | 42 | io.springfox 43 | springfox-swagger-ui 44 | 2.9.2 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/ViBootSwaggerApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.swagger2; 2 | 3 | //import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.ComponentScan; 8 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 9 | 10 | /** 11 | * @author vi 12 | * @since 2019/3/6 6:35 PM 13 | */ 14 | @SpringBootApplication 15 | @ComponentScan(value = "indi.viyoung.viboot.*") 16 | @MapperScan(value = "indi.viyoung.viboot.swagger2.mapper") 17 | @EnableSwagger2 18 | //@EnableSwaggerBootstrapUI 19 | public class ViBootSwaggerApplication { 20 | public static void main(String[] args) { 21 | SpringApplication.run(ViBootSwaggerApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/config/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.swagger2.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.service.Contact; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | 13 | /** 14 | * @author vi 15 | * @since 2019/3/6 8:31 PM 16 | */ 17 | @Configuration 18 | public class Swagger2Config { 19 | 20 | @Bean 21 | public Docket createRestApi() { 22 | return new Docket(DocumentationType.SWAGGER_2) 23 | .apiInfo(apiInfo()) 24 | .select() 25 | .apis(RequestHandlerSelectors.basePackage("indi.viyoung.viboot.swagger2")) 26 | .paths(PathSelectors.any()) 27 | .build(); 28 | } 29 | 30 | private ApiInfo apiInfo() { 31 | return new ApiInfoBuilder() 32 | .title("viboot-swagger2") 33 | .description("Restful-API-Doc") 34 | .termsOfServiceUrl("https://www.cnblogs.com/viyoung") 35 | .contact(new Contact("Vi的技术博客", "https://www.cnblogs.com/viyoung", "18530069930@163.com")) 36 | .version("1.0") 37 | .build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.swagger2.controller; 2 | 3 | import indi.viyoung.viboot.swagger2.entity.User; 4 | import indi.viyoung.viboot.swagger2.service.UserService; 5 | import io.swagger.annotations.*; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | *

14 | * 前端控制器 15 | *

16 | * 17 | * @author viyoung 18 | * @since 2019-01-23 19 | */ 20 | @RestController 21 | @RequestMapping("/users") 22 | @Slf4j 23 | @CrossOrigin 24 | @Api(tags = "用户类控制器") 25 | public class UserController { 26 | 27 | @Autowired 28 | private UserService userService; 29 | 30 | @GetMapping 31 | @ApiOperation(value = "获取用户列表",notes = "获取用户列表") 32 | @ApiResponse(response = User.class,code = 200,message = "查询成功") 33 | public List get() { 34 | log.info("GET方法执行。。。"); 35 | return userService.list(); 36 | } 37 | 38 | @GetMapping(value = "/{id}") 39 | @ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息") 40 | public User get(@PathVariable Long id) { 41 | log.info("GET..{}...方法执行。。。",id); 42 | return userService.getById(id); 43 | } 44 | 45 | @PostMapping 46 | @ApiOperation(value="创建用户", notes="根据User对象创建用户") 47 | @ApiImplicitParam(name = "user", value = "user类", required = true, dataType = "User") 48 | public void post(@RequestBody User user) { 49 | userService.save(user); 50 | log.info("POST方法执行。。。"); 51 | } 52 | 53 | @PutMapping 54 | @ApiOperation(value="更新用户信息",notes = "根据User对象更新用户信息") 55 | @ApiImplicitParams({ 56 | @ApiImplicitParam(name = "user", value = "用户实体user", required = true, dataType = "User") 57 | }) 58 | public void put(User user) { 59 | userService.updateById(user); 60 | log.info("PUT方法执行。。。"); 61 | } 62 | 63 | @DeleteMapping(value = "/{id}") 64 | @ApiOperation(value="删除用户", notes="根据url的id来指定删除用户") 65 | @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long", paramType = "path") 66 | public void delete(@PathVariable Long id) { 67 | userService.removeById(id); 68 | log.info("DELETE方法执行。。。"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/entity/User.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.swagger2.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiModel; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | import lombok.experimental.Accessors; 11 | 12 | import java.io.Serializable; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author viyoung 20 | * @since 2019-01-23 21 | */ 22 | @Data 23 | @EqualsAndHashCode(callSuper = false) 24 | @Accessors(chain = true) 25 | @ApiModel(value="user对象",description="用户对象user") 26 | public class User implements Serializable { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | @TableId(value = "id", type = IdType.AUTO) 31 | @ApiModelProperty(value = "用户ID",example = "1000001") 32 | private Long id; 33 | 34 | @ApiModelProperty(value="用户名",required = true,dataType = "String") 35 | private String userName; 36 | 37 | @ApiModelProperty(value = "密码") 38 | private String password; 39 | } 40 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.swagger2.mapper; 2 | 3 | import indi.viyoung.viboot.swagger2.entity.User; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/mapper/xml/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/service/UserService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.swagger2.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import indi.viyoung.viboot.swagger2.entity.User; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author viyoung 12 | * @since 2019-01-23 13 | */ 14 | public interface UserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/java/indi/viyoung/viboot/swagger2/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.swagger2.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import indi.viyoung.viboot.swagger2.entity.User; 5 | import indi.viyoung.viboot.swagger2.mapper.UserMapper; 6 | import indi.viyoung.viboot.swagger2.service.UserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author viyoung 15 | * @since 2019-01-23 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements UserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /viboot-swagger2/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8089 3 | 4 | logging: 5 | level: 6 | io.swagger.models.parameters.AbstractSerializableParameter: error 7 | 8 | mybatis-plus: 9 | configuration: 10 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 -------------------------------------------------------------------------------- /viboot-swagger2/src/main/resources/mapper/user/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /viboot-uploader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | viboot 7 | indi.viyoung.course 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | viboot-uploader 13 | 14 | 15 | 16 | indi.viyoung.course 17 | viboot-rds 18 | 1.0-SNAPSHOT 19 | 20 | 21 | -------------------------------------------------------------------------------- /viboot-uploader/src/main/java/indi/viyoung/viboot/uploader/ViBootUploaderApplication.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.uploader; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | /** 8 | * @author vi 9 | * @since 2019/4/16 9:39 PM 10 | */ 11 | @SpringBootApplication 12 | @ComponentScan("indi.viyoung") 13 | public class ViBootUploaderApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ViBootUploaderApplication.class,args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /viboot-uploader/src/main/java/indi/viyoung/viboot/uploader/controller/UploadController.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.uploader.controller; 2 | 3 | import indi.viyoung.viboot.uploader.service.IUploadService; 4 | import indi.viyoung.viboot.uploader.vo.Chunk; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.apache.tomcat.util.http.fileupload.FileUtils; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | import org.springframework.web.multipart.MultipartFile; 10 | 11 | import java.io.File; 12 | import java.io.FileInputStream; 13 | import java.io.IOException; 14 | import java.nio.file.Files; 15 | import java.nio.file.Path; 16 | import java.nio.file.Paths; 17 | import java.util.HashMap; 18 | import java.util.HashSet; 19 | import java.util.Map; 20 | 21 | /** 22 | * @author vi 23 | * @since 2019/4/16 9:42 PM 24 | */ 25 | @RequestMapping("/upload") 26 | @RestController 27 | @Slf4j 28 | @CrossOrigin 29 | public class UploadController { 30 | 31 | private final static String CHUNK_FOLDER = "/Users/yangwei/resource/data/chunk"; 32 | private final static String SINGLE_FOLDER = "/Users/yangwei/resource/data/single"; 33 | 34 | @Autowired 35 | private IUploadService uploadService; 36 | 37 | 38 | @PostMapping("single") 39 | public void singleUpload(Chunk chunk) { 40 | MultipartFile file = chunk.getFile(); 41 | String filename = chunk.getFilename(); 42 | try { 43 | byte[] bytes = file.getBytes(); 44 | if (!Files.isWritable(Paths.get(SINGLE_FOLDER))) { 45 | Files.createDirectories(Paths.get(SINGLE_FOLDER)); 46 | } 47 | Path path = Paths.get(SINGLE_FOLDER,filename); 48 | Files.write(path, bytes); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | 54 | @GetMapping("chunk") 55 | public Map checkChunks(Chunk chunk) { 56 | return uploadService.checkChunkExits(chunk); 57 | } 58 | 59 | @PostMapping("chunk") 60 | public Map saveChunk(Chunk chunk) { 61 | MultipartFile file = chunk.getFile(); 62 | Integer chunkNumber = chunk.getChunkNumber(); 63 | String identifier = chunk.getIdentifier(); 64 | byte[] bytes; 65 | try { 66 | bytes = file.getBytes(); 67 | Path path = Paths.get(generatePath(CHUNK_FOLDER, chunk)); 68 | Files.write(path, bytes); 69 | } catch (IOException e) { 70 | e.printStackTrace(); 71 | } 72 | Integer chunks = uploadService.saveChunk(chunkNumber, identifier); 73 | Map result = new HashMap<>(); 74 | if (chunks.equals(chunk.getTotalChunks())) { 75 | result.put("message","上传成功!"); 76 | result.put("code", 205); 77 | } 78 | return result; 79 | } 80 | 81 | @PostMapping("merge") 82 | public void mergeChunks(Chunk chunk) { 83 | String fileName = chunk.getFilename(); 84 | uploadService.mergeFile(fileName,CHUNK_FOLDER + File.separator + chunk.getIdentifier()); 85 | } 86 | 87 | private static String generatePath(String uploadFolder, Chunk chunk) { 88 | 89 | StringBuilder sb = new StringBuilder(); 90 | sb.append(uploadFolder).append(File.separator).append(chunk.getIdentifier()); 91 | //判断uploadFolder/identifier 路径是否存在,不存在则创建 92 | if (!Files.isWritable(Paths.get(sb.toString()))) { 93 | try { 94 | Files.createDirectories(Paths.get(sb.toString())); 95 | } catch (IOException e) { 96 | log.error(e.getMessage(), e); 97 | } 98 | } 99 | return sb.append(File.separator) 100 | .append(chunk.getFilename()) 101 | .append("-") 102 | .append(chunk.getChunkNumber()).toString(); 103 | 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /viboot-uploader/src/main/java/indi/viyoung/viboot/uploader/service/IUploadService.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.uploader.service; 2 | 3 | import indi.viyoung.viboot.uploader.vo.Chunk; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * @author vi 9 | * @since 2019/5/9 8:36 PM 10 | */ 11 | public interface IUploadService { 12 | 13 | Map checkChunkExits(Chunk chunk); 14 | 15 | Integer saveChunk(Integer chunkNumber, String identifier); 16 | 17 | void mergeFile(String fileName, String chunkFolder); 18 | } 19 | -------------------------------------------------------------------------------- /viboot-uploader/src/main/java/indi/viyoung/viboot/uploader/service/impl/UploadServiceImpl.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.uploader.service.impl; 2 | 3 | import indi.viyoung.viboot.redis.base.RedisDao; 4 | import indi.viyoung.viboot.uploader.service.IUploadService; 5 | import indi.viyoung.viboot.uploader.vo.Chunk; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.scheduling.annotation.Async; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.nio.file.Files; 14 | import java.nio.file.Paths; 15 | import java.nio.file.StandardOpenOption; 16 | import java.util.*; 17 | 18 | /** 19 | * @author vi 20 | * @since 2019/5/9 8:37 PM 21 | */ 22 | @Service 23 | @Slf4j 24 | @Async 25 | public class UploadServiceImpl implements IUploadService { 26 | 27 | @Autowired 28 | private RedisDao redisDao; 29 | 30 | private static final String mergeFolder = "/Users/yangwei/resource/data/merge"; 31 | 32 | @Override 33 | public Map checkChunkExits(Chunk chunk) { 34 | Map res = new HashMap<>(); 35 | String identifier = chunk.getIdentifier(); 36 | if (redisDao.existsKey(identifier)) { 37 | Set chunkNumber = (Set) redisDao.hmGet(identifier, "chunkNumberList"); 38 | res.put("chunkNumbers",chunkNumber); 39 | } 40 | return res; 41 | } 42 | 43 | @Override 44 | public Integer saveChunk(Integer chunkNumber, String identifier) { 45 | Set oldChunkNumber = (Set) redisDao.hmGet(identifier, "chunkNumberList"); 46 | if (Objects.isNull(oldChunkNumber)) { 47 | Set newChunkNumber = new HashSet<>(); 48 | newChunkNumber.add(chunkNumber); 49 | redisDao.hmSet(identifier, "chunkNumberList", newChunkNumber); 50 | return newChunkNumber.size(); 51 | } else { 52 | oldChunkNumber.add(chunkNumber); 53 | redisDao.hmSet(identifier, "chunkNumberList", oldChunkNumber); 54 | return oldChunkNumber.size(); 55 | } 56 | 57 | } 58 | 59 | @Override 60 | public void mergeFile(String fileName, String chunkFolder) { 61 | try { 62 | if (!Files.isWritable(Paths.get(mergeFolder))) { 63 | Files.createDirectories(Paths.get(mergeFolder)); 64 | } 65 | String target = mergeFolder + File.separator + fileName; 66 | Files.createFile(Paths.get(target)); 67 | Files.list(Paths.get(chunkFolder)) 68 | .filter(path -> path.getFileName().toString().contains("-")) 69 | .sorted((o1, o2) -> { 70 | String p1 = o1.getFileName().toString(); 71 | String p2 = o2.getFileName().toString(); 72 | int i1 = p1.lastIndexOf("-"); 73 | int i2 = p2.lastIndexOf("-"); 74 | return Integer.valueOf(p2.substring(i2)).compareTo(Integer.valueOf(p1.substring(i1))); 75 | }) 76 | .forEach(path -> { 77 | try { 78 | //以追加的形式写入文件 79 | Files.write(Paths.get(target), Files.readAllBytes(path), StandardOpenOption.APPEND); 80 | //合并后删除该块 81 | Files.delete(path); 82 | } catch (IOException e) { 83 | e.printStackTrace(); 84 | } 85 | }); 86 | } catch (IOException e) { 87 | e.printStackTrace(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /viboot-uploader/src/main/java/indi/viyoung/viboot/uploader/vo/Chunk.java: -------------------------------------------------------------------------------- 1 | package indi.viyoung.viboot.uploader.vo; 2 | 3 | import lombok.Data; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.io.Serializable; 7 | import java.util.Objects; 8 | 9 | /** 10 | * @author vi 11 | * @since 2019/4/1 8:36 PM 12 | */ 13 | @Data 14 | public class Chunk implements Serializable { 15 | 16 | private static final long serialVersionUID = 7073871700302406420L; 17 | 18 | private Long id; 19 | /** 20 | * 当前文件块,从1开始 21 | */ 22 | private Integer chunkNumber; 23 | /** 24 | * 分块大小 25 | */ 26 | private Long chunkSize; 27 | /** 28 | * 当前分块大小 29 | */ 30 | private Long currentChunkSize; 31 | /** 32 | * 总大小 33 | */ 34 | private Long totalSize; 35 | /** 36 | * 文件标识 37 | */ 38 | private String identifier; 39 | /** 40 | * 文件名 41 | */ 42 | private String filename; 43 | /** 44 | * 相对路径 45 | */ 46 | private String relativePath; 47 | /** 48 | * 总块数 49 | */ 50 | private Integer totalChunks; 51 | /** 52 | * 文件类型 53 | */ 54 | private String type; 55 | 56 | /** 57 | * 要上传的文件 58 | */ 59 | private MultipartFile file; 60 | } 61 | -------------------------------------------------------------------------------- /viboot-uploader/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 18080 3 | servlet: 4 | context-path: /api 5 | 6 | #Save the problem of "The field file exceeds its maximum permitted size of 1048576 bytes." 7 | spring: 8 | servlet: 9 | multipart: 10 | max-file-size: 10MB 11 | max-request-size: 100MB 12 | redis: 13 | host: 127.0.0.1 # IP 14 | port: 6379 # 端口号 15 | password: 123456 # 密码 16 | lettuce: 17 | pool: 18 | max-active: 8 # 连接池最大连接数 19 | max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) 20 | min-idle: 0 # 连接池中的最小空闲连接 21 | max-idle: 8 # 连接池中的最大空闲连接 --------------------------------------------------------------------------------