diff --git a/README.md b/README.md index f724453fb34ed7d55cb96f0999af3a0be2b82092..0cf80a21aff10db1b7e1ae9307cefe1873f988f2 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,12 @@ io/geekidea/springboot/** + + mapper/** diff --git a/pom.xml b/pom.xml index c40f6c2a2c279407831550621c6f9abe7e1e2672..274cb5907f5f635974cd3e510f09e152bfb12e6f 100644 --- a/pom.xml +++ b/pom.xml @@ -38,9 +38,34 @@ UTF-8 UTF-8 1.8 + 1.1.21 + 8.0.18 + 3.3.1 + + org.projectlombok + lombok + provided + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} + + + + mysql + mysql-connector-java + ${mysql.version} + org.springframework.boot spring-boot-starter-web @@ -106,6 +131,8 @@ io/geekidea/springboot/** + + mapper/** diff --git a/sql/APP_DEMO.sql b/sql/APP_DEMO.sql new file mode 100644 index 0000000000000000000000000000000000000000..fb50d6c3907c368546db8a62ff796a12b466520e --- /dev/null +++ b/sql/APP_DEMO.sql @@ -0,0 +1,24 @@ + + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for APP_DEMO +-- ---------------------------- +DROP TABLE IF EXISTS `APP_DEMO`; +CREATE TABLE `APP_DEMO` ( + `ID` varchar(100) COLLATE utf8_bin DEFAULT NULL, + `NAME` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `CREATE_TIME` datetime DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- ---------------------------- +-- Records of APP_DEMO +-- ---------------------------- +BEGIN; +INSERT INTO `APP_DEMO` VALUES ('ADSSADASDASDA', '张三', '2019-06-22 22:00:57'); +INSERT INTO `APP_DEMO` VALUES ('asdasdad', '阿斯达大', '2019-06-22 22:01:08'); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/assembly/assembly.xml b/src/main/assembly/assembly.xml index be33196de9b070358dfef2a5b1e5473e2339326a..2c390e60e585165357dea58ab18de854f02a9d73 100644 --- a/src/main/assembly/assembly.xml +++ b/src/main/assembly/assembly.xml @@ -37,7 +37,6 @@ application.yml application-${profileActive}.yml - mapper/**/*.xml static/** templates/** *.xml diff --git a/src/main/java/io/geekidea/springboot/assembly/Application.java b/src/main/java/io/geekidea/springboot/assembly/Application.java index 430adbebf7a733e7860537442ca368feda49c20c..6c7241339fbfff13145a20c46fcc4021287e4efd 100644 --- a/src/main/java/io/geekidea/springboot/assembly/Application.java +++ b/src/main/java/io/geekidea/springboot/assembly/Application.java @@ -1,5 +1,6 @@ package io.geekidea.springboot.assembly; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; @@ -11,6 +12,7 @@ import org.springframework.core.env.ConfigurableEnvironment; * @since 2018/11/20 */ @SpringBootApplication +@MapperScan("io.geekidea.springboot.*.mapper") public class Application { public static void main(String[] args) { diff --git a/src/main/java/io/geekidea/springboot/assembly/entity/AppDemo.java b/src/main/java/io/geekidea/springboot/assembly/entity/AppDemo.java new file mode 100644 index 0000000000000000000000000000000000000000..1aa95a84a572749f6ffb2988a0c411a867847e01 --- /dev/null +++ b/src/main/java/io/geekidea/springboot/assembly/entity/AppDemo.java @@ -0,0 +1,20 @@ +package io.geekidea.springboot.assembly.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @author Eastern unbeaten + * @email chenshiyun2011@163.com + * @data 2019-06-22 + */ +@Data +@TableName("APP_DEMO") +public class AppDemo { + + private String id; + private String name; + private LocalDateTime createTime; +} diff --git a/src/main/java/io/geekidea/springboot/assembly/mapper/AppDemoMapper.java b/src/main/java/io/geekidea/springboot/assembly/mapper/AppDemoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..a6293839718f9b5d76c9b036d0d7b4f09581481f --- /dev/null +++ b/src/main/java/io/geekidea/springboot/assembly/mapper/AppDemoMapper.java @@ -0,0 +1,12 @@ +package io.geekidea.springboot.assembly.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.geekidea.springboot.assembly.entity.AppDemo; + +import java.util.List; + + +public interface AppDemoMapper extends BaseMapper { + + List getxx(); +} diff --git a/src/main/java/io/geekidea/springboot/assembly/service/AppDemoService.java b/src/main/java/io/geekidea/springboot/assembly/service/AppDemoService.java new file mode 100644 index 0000000000000000000000000000000000000000..075d74290ac2f90fdb39edc1c54daf7374eaa9e7 --- /dev/null +++ b/src/main/java/io/geekidea/springboot/assembly/service/AppDemoService.java @@ -0,0 +1,13 @@ +package io.geekidea.springboot.assembly.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import io.geekidea.springboot.assembly.entity.AppDemo; + +import java.util.List; + + +public interface AppDemoService extends IService { + + List getxx(); + +} diff --git a/src/main/java/io/geekidea/springboot/assembly/service/impl/AppDemoServiceImpl.java b/src/main/java/io/geekidea/springboot/assembly/service/impl/AppDemoServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..f397f4b68f9833b4fa1ccc6183d125ff82f3025b --- /dev/null +++ b/src/main/java/io/geekidea/springboot/assembly/service/impl/AppDemoServiceImpl.java @@ -0,0 +1,25 @@ +package io.geekidea.springboot.assembly.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import io.geekidea.springboot.assembly.entity.AppDemo; +import io.geekidea.springboot.assembly.mapper.AppDemoMapper; +import io.geekidea.springboot.assembly.service.AppDemoService; +import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +public class AppDemoServiceImpl extends ServiceImpl implements AppDemoService { + + @Autowired + private AppDemoMapper appDemoMapper; + + + @Override + public List getxx() { + return appDemoMapper.getxx(); + } +} diff --git a/src/main/java/io/geekidea/springboot/assembly/web/AppUserController.java b/src/main/java/io/geekidea/springboot/assembly/web/AppUserController.java new file mode 100644 index 0000000000000000000000000000000000000000..433c9cc0699bc395a6ad4944130f330e2c4826bf --- /dev/null +++ b/src/main/java/io/geekidea/springboot/assembly/web/AppUserController.java @@ -0,0 +1,33 @@ +package io.geekidea.springboot.assembly.web; + + +import io.geekidea.springboot.assembly.service.AppDemoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping("/demo") +public class AppUserController { + + + @Autowired + private AppDemoService appDemoService; + + @GetMapping(value = "/list") + public ResponseEntity list() { + return ResponseEntity.ok(appDemoService.getxx()); + } + + + @GetMapping(value = "/list2") + public ResponseEntity list2() { + return ResponseEntity.ok(appDemoService.list()); + } + + + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3f6106548582d9ee454baf58fad29d5016023e64..9700cc73f23ce3fbedc4bc94892fd0480b287782 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,14 @@ +datasource: + mysql: + validation-query: select 1 + driver: com.mysql.cj.jdbc.Driver + #数据库名称 + database: nebula-web + ip: test + port: 3306 + username: root + password: 123456 + url: jdbc:mysql://${datasource.mysql.ip}:${datasource.mysql.port}/${datasource.mysql.database}?useSSL=false&serverTimezone=UTC&characterEncoding=utf8 server: servlet: context-path: /example @@ -9,5 +20,18 @@ spring: # 当前maven打包的profile profiles: active: @profileActive@ + datasource: + druid: + min-idle: 5 + max-active: 10 + initial-size: 1 + validation-query: ${datasource.mysql.validation-query} + driver-class-name: ${datasource.mysql.driver} + username: ${datasource.mysql.username} + password: ${datasource.mysql.password} + url: ${datasource.mysql.url} hello: Hello spring-boot-assembly +#mybatis +mybatis-plus: + mapper-locations: classpath*:mapper/**/*.xml diff --git a/src/main/resources/mapper/demo/AppDemoMapper.xml b/src/main/resources/mapper/demo/AppDemoMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..df8b4930070e520fe35bc4687645f0c7a27261d1 --- /dev/null +++ b/src/main/resources/mapper/demo/AppDemoMapper.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/hello/hello.xml b/src/main/resources/mapper/hello/hello.xml deleted file mode 100644 index 2eb42179334bcb67d4c502953eb0960b59b419d8..0000000000000000000000000000000000000000 --- a/src/main/resources/mapper/hello/hello.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/main/resources/mapper/test.xml b/src/main/resources/mapper/test.xml deleted file mode 100644 index 08e9868871edebd40e8c3dc6d4243f3094e7cb96..0000000000000000000000000000000000000000 --- a/src/main/resources/mapper/test.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file