傅行帆 6 年前
父节点
当前提交
7b51bb67a0
共有 18 个文件被更改,包括 288 次插入3 次删除
  1. 17
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/pom.xml
  2. 19
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/controller/TestController.java
  3. 11
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/dao/ScUserMapper.java
  4. 37
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/model/ScUser.java
  5. 9
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/service/ScUserServiceI.java
  6. 25
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/service/impl/ScUserServiceImpl.java
  7. 0
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/resources/application.properties
  8. 9
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/resources/application.yml
  9. 16
    0
      SmartCommunity/SmartCommunityV1/eureka-client1/src/main/resources/mapper/ScUserMapper.xml
  10. 17
    0
      SmartCommunity/SmartCommunityV1/eureka-client2/pom.xml
  11. 20
    1
      SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/controller/TestController.java
  12. 11
    0
      SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/dao/ScUserMapper.java
  13. 37
    0
      SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/model/ScUser.java
  14. 9
    0
      SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/service/ScUserServiceI.java
  15. 25
    0
      SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/service/impl/ScUserServiceImpl.java
  16. 9
    1
      SmartCommunity/SmartCommunityV1/eureka-client2/src/main/resources/application.yml
  17. 16
    0
      SmartCommunity/SmartCommunityV1/eureka-client2/src/main/resources/mapper/ScUserMapper.xml
  18. 1
    1
      SmartCommunity/SmartCommunityV1/eureka-sever/src/main/resources/application.properties

+ 17
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/pom.xml 查看文件

40
 			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
40
 			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
41
 		</dependency>
41
 		</dependency>
42
 
42
 
43
+		<dependency>
44
+			<groupId>org.mybatis.spring.boot</groupId>
45
+			<artifactId>mybatis-spring-boot-starter</artifactId>
46
+			<version>1.3.2</version>
47
+		</dependency>
48
+
49
+		<dependency>
50
+			<groupId>mysql</groupId>
51
+			<artifactId>mysql-connector-java</artifactId>
52
+			<scope>runtime</scope>
53
+		</dependency>
54
+
55
+		<dependency>
56
+			<groupId>org.springframework.boot</groupId>
57
+			<artifactId>spring-boot-starter-actuator</artifactId>
58
+		</dependency>
59
+
43
 		<dependency>
60
 		<dependency>
44
 			<groupId>org.springframework.boot</groupId>
61
 			<groupId>org.springframework.boot</groupId>
45
 			<artifactId>spring-boot-starter-test</artifactId>
62
 			<artifactId>spring-boot-starter-test</artifactId>

+ 19
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/controller/TestController.java 查看文件

1
 package com.example.demo.controller;
1
 package com.example.demo.controller;
2
 
2
 
3
+import com.example.demo.model.ScUser;
4
+import com.example.demo.service.ScUserServiceI;
3
 import com.netflix.discovery.DiscoveryClient;
5
 import com.netflix.discovery.DiscoveryClient;
4
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Value;
7
 import org.springframework.beans.factory.annotation.Value;
8
+import org.springframework.cloud.context.config.annotation.RefreshScope;
6
 import org.springframework.web.bind.annotation.RequestMapping;
9
 import org.springframework.web.bind.annotation.RequestMapping;
7
 import org.springframework.web.bind.annotation.ResponseBody;
10
 import org.springframework.web.bind.annotation.ResponseBody;
8
 import org.springframework.web.bind.annotation.RestController;
11
 import org.springframework.web.bind.annotation.RestController;
9
 
12
 
13
+import java.util.List;
14
+
10
 /**
15
 /**
11
  * @author FXF
16
  * @author FXF
12
  * @date 2018-09-11
17
  * @date 2018-09-11
13
  */
18
  */
14
 @RestController
19
 @RestController
20
+@RefreshScope
15
 public class TestController {
21
 public class TestController {
16
     
22
     
17
     @Value("${abc}")
23
     @Value("${abc}")
18
     private String abc;
24
     private String abc;
19
     
25
     
26
+    @Autowired
27
+    private ScUserServiceI scUserService;
28
+    
20
     @RequestMapping("/hello")
29
     @RequestMapping("/hello")
21
     @ResponseBody
30
     @ResponseBody
22
     public String index(){
31
     public String index(){
23
         return abc;
32
         return abc;
24
     }
33
     }
34
+    
35
+    /**
36
+     * 获取所有的用户信息
37
+     * @return
38
+     */
39
+    @RequestMapping("/user")
40
+    @ResponseBody
41
+    public List<ScUser> getUser(){
42
+        return scUserService.getUser();
43
+    }
25
 }
44
 }

+ 11
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/dao/ScUserMapper.java 查看文件

1
+package com.example.demo.dao;
2
+
3
+import com.example.demo.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
+}

+ 37
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/model/ScUser.java 查看文件

1
+package com.example.demo.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
+}

+ 9
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/service/ScUserServiceI.java 查看文件

1
+package com.example.demo.service;
2
+
3
+import com.example.demo.model.ScUser;
4
+
5
+import java.util.List;
6
+
7
+public interface ScUserServiceI {
8
+	List<ScUser> getUser();
9
+}

+ 25
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/service/impl/ScUserServiceImpl.java 查看文件

1
+package com.example.demo.service.impl;
2
+
3
+import com.example.demo.dao.ScUserMapper;
4
+import com.example.demo.model.ScUser;
5
+import com.example.demo.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
+}

+ 0
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/resources/application.properties 查看文件


+ 9
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/resources/application.yml 查看文件

1
+management:
2
+  endpoints:
3
+    web:
4
+      exposure:
5
+        include: refresh,health,info
6
+## Mybatis
7
+mybatis:
8
+  typeAliasesPackage: com.example.demo.model
9
+  mapperLocations: classpath:mapper/*.xml

+ 16
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/resources/mapper/ScUserMapper.xml 查看文件

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.example.demo.dao.ScUserMapper">
4
+
5
+    <parameterMap id="paramMap" type="com.example.demo.model.ScUser"></parameterMap>
6
+
7
+    <resultMap id="resultMap" type="com.example.demo.model.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>

+ 17
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/pom.xml 查看文件

39
 			<artifactId>spring-cloud-starter-config</artifactId>
39
 			<artifactId>spring-cloud-starter-config</artifactId>
40
 		</dependency>
40
 		</dependency>
41
 
41
 
42
+		<dependency>
43
+			<groupId>org.springframework.boot</groupId>
44
+			<artifactId>spring-boot-starter-actuator</artifactId>
45
+		</dependency>
46
+
47
+		<dependency>
48
+			<groupId>org.mybatis.spring.boot</groupId>
49
+			<artifactId>mybatis-spring-boot-starter</artifactId>
50
+			<version>1.3.2</version>
51
+		</dependency>
52
+
53
+		<dependency>
54
+			<groupId>mysql</groupId>
55
+			<artifactId>mysql-connector-java</artifactId>
56
+			<scope>runtime</scope>
57
+		</dependency>
58
+
42
 		<dependency>
59
 		<dependency>
43
 			<groupId>org.springframework.boot</groupId>
60
 			<groupId>org.springframework.boot</groupId>
44
 			<artifactId>spring-boot-starter-test</artifactId>
61
 			<artifactId>spring-boot-starter-test</artifactId>

+ 20
- 1
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/controller/TestController.java 查看文件

1
 package com.example.demo.controller;
1
 package com.example.demo.controller;
2
 
2
 
3
-import com.netflix.discovery.DiscoveryClient;
3
+import com.example.demo.model.ScUser;
4
+import com.example.demo.service.ScUserServiceI;
4
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Value;
6
 import org.springframework.beans.factory.annotation.Value;
7
+import org.springframework.cloud.context.config.annotation.RefreshScope;
6
 import org.springframework.web.bind.annotation.RequestMapping;
8
 import org.springframework.web.bind.annotation.RequestMapping;
7
 import org.springframework.web.bind.annotation.ResponseBody;
9
 import org.springframework.web.bind.annotation.ResponseBody;
8
 import org.springframework.web.bind.annotation.RestController;
10
 import org.springframework.web.bind.annotation.RestController;
9
 
11
 
12
+import java.util.List;
13
+
10
 /**
14
 /**
11
  * @author FXF
15
  * @author FXF
12
  * @date 2018-09-11
16
  * @date 2018-09-11
13
  */
17
  */
14
 @RestController
18
 @RestController
19
+@RefreshScope
15
 public class TestController {
20
 public class TestController {
21
+    
16
     @Value("${abc}")
22
     @Value("${abc}")
17
     private String abc;
23
     private String abc;
18
     
24
     
25
+    @Autowired
26
+    private ScUserServiceI scUserService;
27
+    
19
     @RequestMapping("/hello")
28
     @RequestMapping("/hello")
20
     @ResponseBody
29
     @ResponseBody
21
     public String index(){
30
     public String index(){
22
         return abc;
31
         return abc;
23
     }
32
     }
33
+    
34
+    /**
35
+     * 获取所有的用户信息
36
+     * @return
37
+     */
38
+    @RequestMapping("/user")
39
+    @ResponseBody
40
+    public List<ScUser> getUser(){
41
+        return scUserService.getUser();
42
+    }
24
 }
43
 }

+ 11
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/dao/ScUserMapper.java 查看文件

1
+package com.example.demo.dao;
2
+
3
+import com.example.demo.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
+}

+ 37
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/model/ScUser.java 查看文件

1
+package com.example.demo.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
+}

+ 9
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/service/ScUserServiceI.java 查看文件

1
+package com.example.demo.service;
2
+
3
+import com.example.demo.model.ScUser;
4
+
5
+import java.util.List;
6
+
7
+public interface ScUserServiceI {
8
+	List<ScUser> getUser();
9
+}

+ 25
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/service/impl/ScUserServiceImpl.java 查看文件

1
+package com.example.demo.service.impl;
2
+
3
+import com.example.demo.dao.ScUserMapper;
4
+import com.example.demo.model.ScUser;
5
+import com.example.demo.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
+}

+ 9
- 1
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/resources/application.yml 查看文件

1
-
1
+management:
2
+  endpoints:
3
+    web:
4
+      exposure:
5
+        include: refresh,health,info
6
+## Mybatis
7
+mybatis:
8
+  typeAliasesPackage: com.example.demo.model
9
+  mapperLocations: classpath:mapper/*.xml

+ 16
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/resources/mapper/ScUserMapper.xml 查看文件

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.example.demo.dao.ScUserMapper">
4
+
5
+    <parameterMap id="paramMap" type="com.example.demo.model.ScUser"></parameterMap>
6
+
7
+    <resultMap id="resultMap" type="com.example.demo.model.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>

+ 1
- 1
SmartCommunity/SmartCommunityV1/eureka-sever/src/main/resources/application.properties 查看文件

3
 eureka.client.register-with-eureka=false
3
 eureka.client.register-with-eureka=false
4
 eureka.client.fetch-registry=false
4
 eureka.client.fetch-registry=false
5
 #×ÔÎÒ±£»¤»úÖÆ
5
 #×ÔÎÒ±£»¤»úÖÆ
6
-#eureka.server.enable-self-preservation=false
6
+eureka.server.enable-self-preservation=false
7
 eureka.client.service-url.defaultZone=http://localhost:8080/eureka/
7
 eureka.client.service-url.defaultZone=http://localhost:8080/eureka/