瀏覽代碼

集成mybaties-plus

傅行帆 6 年之前
父節點
當前提交
c6ac715988
共有 20 個檔案被更改,包括 248 行新增182 行删除
  1. 11
    3
      CODE/smart-community/property-api/pom.xml
  2. 1
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/PropertyApplication.java
  3. 2
    2
      CODE/smart-community/property-api/src/main/java/com/community/huiju/Swagger2.java
  4. 8
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/common/base/BaseController.java
  5. 22
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/config/MybatisPlusConfig.java
  6. 0
    60
      CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/TestController.java
  7. 52
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/UserController.java
  8. 0
    11
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/ScUserMapper.java
  9. 16
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserMapper.java
  10. 0
    14
      CODE/smart-community/property-api/src/main/java/com/community/huiju/microController/MicroTestController.java
  11. 0
    37
      CODE/smart-community/property-api/src/main/java/com/community/huiju/model/ScUser.java
  12. 88
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/model/User.java
  13. 17
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserService.java
  14. 0
    9
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/ScUserServiceI.java
  15. 0
    25
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/ScUserServiceImpl.java
  16. 21
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserServiceImpl.java
  17. 4
    4
      CODE/smart-community/property-api/src/main/resources/application.yml
  18. 1
    1
      CODE/smart-community/property-api/src/main/resources/bootstrap.yml
  19. 0
    16
      CODE/smart-community/property-api/src/main/resources/mapper/ScUserMapper.xml
  20. 5
    0
      CODE/smart-community/property-api/src/main/resources/mapper/UserMapper.xml

+ 11
- 3
CODE/smart-community/property-api/pom.xml 查看文件

@@ -62,9 +62,9 @@
62 62
 		</dependency>
63 63
 
64 64
 		<dependency>
65
-			<groupId>org.mybatis.spring.boot</groupId>
66
-			<artifactId>mybatis-spring-boot-starter</artifactId>
67
-			<version>1.3.2</version>
65
+			<groupId>com.baomidou</groupId>
66
+			<artifactId>mybatis-plus-boot-starter</artifactId>
67
+			<version>3.0.6</version>
68 68
 		</dependency>
69 69
 
70 70
 		<dependency>
@@ -73,6 +73,14 @@
73 73
 			<scope>runtime</scope>
74 74
 		</dependency>
75 75
 
76
+		<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
77
+		<dependency>
78
+			<groupId>org.projectlombok</groupId>
79
+			<artifactId>lombok</artifactId>
80
+			<version>1.18.2</version>
81
+			<scope>provided</scope>
82
+		</dependency>
83
+
76 84
 		<dependency>
77 85
 			<groupId>org.springframework.boot</groupId>
78 86
 			<artifactId>spring-boot-starter-test</artifactId>

+ 1
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/PropertyApplication.java 查看文件

@@ -1,5 +1,6 @@
1 1
 package com.community.huiju;
2 2
 
3
+import org.mybatis.spring.annotation.MapperScan;
3 4
 import org.springframework.boot.SpringApplication;
4 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 6
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

+ 2
- 2
CODE/smart-community/property-api/src/main/java/com/community/huiju/Swagger2.java 查看文件

@@ -21,14 +21,14 @@ public class Swagger2 {
21 21
     @Bean
22 22
     public Docket docket(){
23 23
         return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
24
-                .apis(RequestHandlerSelectors.basePackage("com.example.huiju.controller"))
24
+                .apis(RequestHandlerSelectors.basePackage("com.community.huiju.controller"))
25 25
                 .paths(PathSelectors.any()).build();
26 26
     }
27 27
     //构建api文档的详细信息函数
28 28
     private ApiInfo apiInfo(){
29 29
         return new ApiInfoBuilder()
30 30
                 //页面标题
31
-                .title("eureka-client2 的 RESTful API")
31
+                .title("物业端 的 RESTful API")
32 32
                 //创建人
33 33
                 .contact(new Contact("fuxingfan","","fuxingfan@dingtalk.com"))
34 34
                 //版本号

+ 8
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/common/base/BaseController.java 查看文件

@@ -0,0 +1,8 @@
1
+package com.community.huiju.common.base;
2
+
3
+/**
4
+ * @author FXF
5
+ * @date 2018-12-18
6
+ */
7
+public class BaseController {
8
+}

+ 22
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/config/MybatisPlusConfig.java 查看文件

@@ -0,0 +1,22 @@
1
+package com.community.huiju.config;
2
+
3
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4
+import org.mybatis.spring.annotation.MapperScan;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.context.annotation.Configuration;
7
+
8
+/**
9
+ * @author FXF
10
+ * @date 2018-12-18
11
+ */
12
+@Configuration
13
+@MapperScan("com.community.huiju.dao")
14
+public class MybatisPlusConfig {
15
+	/**
16
+	 * 分页插件
17
+	 */
18
+	@Bean
19
+	public PaginationInterceptor paginationInterceptor() {
20
+		return new PaginationInterceptor();
21
+	}
22
+}

+ 0
- 60
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/TestController.java 查看文件

@@ -1,60 +0,0 @@
1
-package com.community.huiju.controller;
2
-
3
-import com.community.huiju.model.ScUser;
4
-import com.community.huiju.service.ScUserServiceI;
5
-import com.community.huiju.microController.MicroTestController;
6
-import io.swagger.annotations.Api;
7
-import io.swagger.annotations.ApiOperation;
8
-import org.springframework.beans.factory.annotation.Autowired;
9
-import org.springframework.beans.factory.annotation.Value;
10
-import org.springframework.cloud.context.config.annotation.RefreshScope;
11
-import org.springframework.web.bind.annotation.RequestMapping;
12
-import org.springframework.web.bind.annotation.RequestMethod;
13
-import org.springframework.web.bind.annotation.ResponseBody;
14
-import org.springframework.web.bind.annotation.RestController;
15
-
16
-import java.util.List;
17
-
18
-/**
19
- * @author FXF
20
- * @date 2018-09-11
21
- */
22
-@RestController
23
-@RefreshScope
24
-@RequestMapping("/client2")
25
-@Api("eureka-client2的测试controller的API")
26
-public class TestController {
27
-    
28
-    @Value("${abc}")
29
-    private String abc;
30
-    
31
-    @Autowired
32
-    private ScUserServiceI scUserService;
33
-    
34
-    @Autowired
35
-    private MicroTestController microTestController;
36
-    
37
-    @ApiOperation(value = "测试无参", notes = "无参")
38
-    @RequestMapping(value = "/hello",method = RequestMethod.GET)
39
-    @ResponseBody
40
-    public String index(){
41
-        return abc;
42
-    }
43
-    
44
-    /**
45
-     * 获取所有的用户信息
46
-     * @return
47
-     */
48
-    @ApiOperation(value = "测试restful接口", notes = "测试接口2")
49
-    @RequestMapping(value = "/user",method = RequestMethod.GET)
50
-    @ResponseBody
51
-    public List<ScUser> getUser(){
52
-        return scUserService.getUser();
53
-    }
54
-    
55
-    @RequestMapping(value = "/feignUser",method = RequestMethod.GET)
56
-    @ResponseBody
57
-    public List<ScUser> getMicroUser(){
58
-        return microTestController.getUser();
59
-    }
60
-}

+ 52
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/UserController.java 查看文件

@@ -0,0 +1,52 @@
1
+package com.community.huiju.controller;
2
+
3
+
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
+import com.community.commom.constant.Constant;
6
+import com.community.commom.mode.ResponseBean;
7
+import com.community.commom.session.UserElement;
8
+import com.community.huiju.common.base.BaseController;
9
+import com.community.huiju.model.User;
10
+import com.community.huiju.service.IUserService;
11
+import io.swagger.annotations.Api;
12
+import io.swagger.annotations.ApiImplicitParam;
13
+import io.swagger.annotations.ApiImplicitParams;
14
+import io.swagger.annotations.ApiOperation;
15
+import org.springframework.beans.factory.annotation.Autowired;
16
+import org.springframework.cloud.context.config.annotation.RefreshScope;
17
+import org.springframework.web.bind.annotation.RequestMapping;
18
+import org.springframework.web.bind.annotation.RequestMethod;
19
+import org.springframework.web.bind.annotation.RestController;
20
+
21
+import javax.servlet.http.HttpSession;
22
+
23
+/**
24
+ * <p>
25
+ * 物业web端用户表 前端控制器
26
+ * </p>
27
+ *
28
+ * @author jobob
29
+ * @since 2018-12-18
30
+ */
31
+@RestController
32
+@RefreshScope
33
+@RequestMapping("/")
34
+@Api(value = "物业端用户API", description = "物业端用户API")
35
+public class UserController extends BaseController {
36
+	
37
+	@Autowired
38
+	private IUserService userService;
39
+	
40
+	@ApiOperation(value = "获取用户列表",nickname = "获取用户信息")
41
+	@ApiImplicitParams({
42
+			//@ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
43
+	})
44
+	@RequestMapping(value = "/users",method = RequestMethod.GET)
45
+	public ResponseBean getInfo(HttpSession session) {
46
+		ResponseBean response = new ResponseBean();
47
+		//response.addSuccess(userService.list());
48
+		Page a = new Page(1,10);
49
+		response.addSuccess(userService.page(a));
50
+		return response;
51
+	}
52
+}

+ 0
- 11
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/ScUserMapper.java 查看文件

@@ -1,11 +0,0 @@
1
-package com.community.huiju.dao;
2
-
3
-import com.community.huiju.model.ScUser;
4
-import org.apache.ibatis.annotations.Mapper;
5
-
6
-import java.util.List;
7
-
8
-@Mapper
9
-public interface ScUserMapper {
10
-	List<ScUser> find();
11
-}

+ 16
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserMapper.java 查看文件

@@ -0,0 +1,16 @@
1
+package com.community.huiju.dao;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.community.huiju.model.User;
5
+
6
+/**
7
+ * <p>
8
+ * 物业web端用户表 Mapper 接口
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2018-12-18
13
+ */
14
+public interface UserMapper extends BaseMapper<User> {
15
+
16
+}

+ 0
- 14
CODE/smart-community/property-api/src/main/java/com/community/huiju/microController/MicroTestController.java 查看文件

@@ -1,14 +0,0 @@
1
-package com.community.huiju.microController;
2
-
3
-import com.community.huiju.model.ScUser;
4
-import org.springframework.cloud.openfeign.FeignClient;
5
-import org.springframework.web.bind.annotation.RequestMapping;
6
-
7
-import java.util.List;
8
-
9
-@FeignClient("eureka-client1")
10
-public interface MicroTestController {
11
-	
12
-	@RequestMapping("/user")
13
-	List<ScUser> getUser();
14
-}

+ 0
- 37
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/ScUser.java 查看文件

@@ -1,37 +0,0 @@
1
-package com.community.huiju.model;
2
-
3
-/**
4
- * @author FXF
5
- * @date 2018-09-19
6
- */
7
-public class ScUser {
8
-	private Integer id;
9
-	
10
-	private String userName;
11
-	
12
-	private String userPassword;
13
-	
14
-	public Integer getId() {
15
-		return id;
16
-	}
17
-	
18
-	public void setId(Integer id) {
19
-		this.id = id;
20
-	}
21
-	
22
-	public String getUserName() {
23
-		return userName;
24
-	}
25
-	
26
-	public void setUserName(String userName) {
27
-		this.userName = userName;
28
-	}
29
-	
30
-	public String getUserPassword() {
31
-		return userPassword;
32
-	}
33
-	
34
-	public void setUserPassword(String userPassword) {
35
-		this.userPassword = userPassword;
36
-	}
37
-}

+ 88
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/User.java 查看文件

@@ -0,0 +1,88 @@
1
+package com.community.huiju.model;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableName;
4
+import lombok.Data;
5
+import lombok.EqualsAndHashCode;
6
+import lombok.experimental.Accessors;
7
+
8
+import java.io.Serializable;
9
+import java.time.LocalDateTime;
10
+
11
+/**
12
+ * <p>
13
+ * 物业web端用户表
14
+ * </p>
15
+ *
16
+ * @author jobob
17
+ * @since 2018-12-18
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+@TableName("tp_user")
23
+public class User implements Serializable {
24
+
25
+    private static final long serialVersionUID = 1L;
26
+
27
+    /**
28
+     * 小区id
29
+     */
30
+    private Integer communityId;
31
+
32
+    /**
33
+     * 用户姓名
34
+     */
35
+    private String userName;
36
+
37
+    /**
38
+     * 登录账号就是手机号确保唯一
39
+     */
40
+    private String loginName;
41
+
42
+    /**
43
+     * 登录密码
44
+     */
45
+    private String loginPassword;
46
+
47
+    /**
48
+     * 1 有效 0 无效(逻辑删除)
49
+     */
50
+    private String status;
51
+
52
+    /**
53
+     * 备注
54
+     */
55
+    private String remark;
56
+
57
+    /**
58
+     * 邮箱
59
+     */
60
+    private String email;
61
+
62
+    /**
63
+     * 头像
64
+     */
65
+    private String headPortrait;
66
+
67
+    /**
68
+     * 创建人
69
+     */
70
+    private Integer createUser;
71
+
72
+    /**
73
+     * 创建时间
74
+     */
75
+    private LocalDateTime createDate;
76
+
77
+    /**
78
+     * 更新人
79
+     */
80
+    private Integer updateUser;
81
+
82
+    /**
83
+     * 更新时间
84
+     */
85
+    private LocalDateTime updateDate;
86
+
87
+
88
+}

+ 17
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserService.java 查看文件

@@ -0,0 +1,17 @@
1
+package com.community.huiju.service;
2
+
3
+
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.community.huiju.model.User;
6
+
7
+/**
8
+ * <p>
9
+ * 物业web端用户表 服务类
10
+ * </p>
11
+ *
12
+ * @author jobob
13
+ * @since 2018-12-18
14
+ */
15
+public interface IUserService extends IService<User> {
16
+
17
+}

+ 0
- 9
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/ScUserServiceI.java 查看文件

@@ -1,9 +0,0 @@
1
-package com.community.huiju.service;
2
-
3
-import com.community.huiju.model.ScUser;
4
-
5
-import java.util.List;
6
-
7
-public interface ScUserServiceI {
8
-	List<ScUser> getUser();
9
-}

+ 0
- 25
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/ScUserServiceImpl.java 查看文件

@@ -1,25 +0,0 @@
1
-package com.community.huiju.service.impl;
2
-
3
-import com.community.huiju.dao.ScUserMapper;
4
-import com.community.huiju.model.ScUser;
5
-import com.community.huiju.service.ScUserServiceI;
6
-import org.springframework.beans.factory.annotation.Autowired;
7
-import org.springframework.stereotype.Service;
8
-
9
-import java.util.List;
10
-
11
-/**
12
- * @author FXF
13
- * @date 2018-09-19
14
- */
15
-@Service("scUserService")
16
-public class ScUserServiceImpl implements ScUserServiceI {
17
-	
18
-	@Autowired
19
-	private ScUserMapper scUserMapper;
20
-	
21
-	@Override
22
-	public List<ScUser> getUser() {
23
-		return scUserMapper.find();
24
-	}
25
-}

+ 21
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserServiceImpl.java 查看文件

@@ -0,0 +1,21 @@
1
+package com.community.huiju.service.impl;
2
+
3
+
4
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.community.huiju.dao.UserMapper;
6
+import com.community.huiju.model.User;
7
+import com.community.huiju.service.IUserService;
8
+import org.springframework.stereotype.Service;
9
+
10
+/**
11
+ * <p>
12
+ * 物业web端用户表 服务实现类
13
+ * </p>
14
+ *
15
+ * @author jobob
16
+ * @since 2018-12-18
17
+ */
18
+@Service("userService")
19
+public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
20
+
21
+}

+ 4
- 4
CODE/smart-community/property-api/src/main/resources/application.yml 查看文件

@@ -3,7 +3,7 @@ management:
3 3
     web:
4 4
       exposure:
5 5
         include: refresh,health,info
6
-## Mybatis
7
-mybatis:
8
-  typeAliasesPackage: com.example.huiju.model
9
-  mapperLocations: classpath:mapper/*.xml
6
+##mybatis-plus
7
+mybatis-plus:
8
+  configuration:
9
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用

+ 1
- 1
CODE/smart-community/property-api/src/main/resources/bootstrap.yml 查看文件

@@ -1,5 +1,5 @@
1 1
 server:
2
-  port: 8082
2
+  port: 8084
3 3
 spring:
4 4
   application:
5 5
     name: eureka-client2

+ 0
- 16
CODE/smart-community/property-api/src/main/resources/mapper/ScUserMapper.xml 查看文件

@@ -1,16 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
-<mapper namespace="ScUserMapper">
4
-
5
-    <parameterMap id="paramMap" type="ScUser"></parameterMap>
6
-
7
-    <resultMap id="resultMap" type="ScUser">
8
-        <id property="id" column="id"/>
9
-        <result property="userName" column="user_name"/>
10
-        <result property="userPassword" column="user_password"/>
11
-    </resultMap>
12
-
13
-    <select id="find" resultMap="resultMap">
14
-        select * from sc_user
15
-    </select>
16
-</mapper>

+ 5
- 0
CODE/smart-community/property-api/src/main/resources/mapper/UserMapper.xml 查看文件

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.community.huiju.dao.UserMapper">
4
+
5
+</mapper>