Browse Source

修改entity repository

zhangxiaoyu 3 years ago
parent
commit
6935ccd358

+ 2 - 6
src/main/java/com/example/springbootdemo/SpringbootdemoApplication.java

@@ -1,17 +1,13 @@
1
 package com.example.springbootdemo;
1
 package com.example.springbootdemo;
2
 
2
 
3
-import com.example.demo.config.MyConfig;
4
-import com.example.demo.controller.User;
5
-import com.example.springbootdemo.controller.TrainJavaController;
6
-import com.example.springbootdemo.zxyTeST.EnumTest;
7
-import com.example.springbootdemo.zxyTeST.SubClass;
8
 import org.springframework.boot.SpringApplication;
3
 import org.springframework.boot.SpringApplication;
9
 import org.springframework.boot.autoconfigure.SpringBootApplication;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
10
 import org.springframework.context.ConfigurableApplicationContext;
5
 import org.springframework.context.ConfigurableApplicationContext;
11
 import org.springframework.context.annotation.ComponentScan;
6
 import org.springframework.context.annotation.ComponentScan;
12
 
7
 
13
-@SpringBootApplication
8
+@SpringBootApplication(scanBasePackages = {"com.example"})
14
 @ComponentScan({"com.example.demo","com.example.springbootdemo"})
9
 @ComponentScan({"com.example.demo","com.example.springbootdemo"})
10
+
15
 public class SpringbootdemoApplication {
11
 public class SpringbootdemoApplication {
16
     public static void main(String[] args) {
12
     public static void main(String[] args) {
17
         ConfigurableApplicationContext run  = SpringApplication.run(SpringbootdemoApplication.class, args);
13
         ConfigurableApplicationContext run  = SpringApplication.run(SpringbootdemoApplication.class, args);

+ 3 - 3
src/main/java/com/example/springbootdemo/controller/HelloController.java

@@ -15,9 +15,9 @@ public class HelloController {
15
     ColorRepository colorRepository;
15
     ColorRepository colorRepository;
16
     @RequestMapping("/hello")
16
     @RequestMapping("/hello")
17
     public void hello() {
17
     public void hello() {
18
-        List<Color> colors = colorRepository.findAll();
19
-        for (Color color:colors) {
20
-            System.out.println(color);
18
+        List<Color> listColors = colorRepository.findByColorId(2314);
19
+        for (Color color:listColors) {
20
+            System.out.println("color_name="+color.getColorName()+"    color_id="+color.getColorId());
21
         }
21
         }
22
     }
22
     }
23
 
23
 

+ 2 - 2
src/main/java/com/example/springbootdemo/zxyTeST/sql/dao/ColorRepository.java

@@ -6,6 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
6
 import java.util.List;
6
 import java.util.List;
7
 
7
 
8
 public interface ColorRepository extends JpaRepository<Color,Long> {
8
 public interface ColorRepository extends JpaRepository<Color,Long> {
9
-    List<Color> findColorsByColor_id(String color_id);
10
-    Color findColorsByColor_idAndColor_name(String color_id,String color_name);
9
+    List<Color> findByColorId(Integer color_id);
10
+    Color findByColorIdAndColorName(String color_id,String color_name);
11
 }
11
 }

+ 27 - 19
src/main/java/com/example/springbootdemo/zxyTeST/sql/entity/Color.java

@@ -6,38 +6,46 @@ import java.io.Serializable;
6
 @Entity
6
 @Entity
7
 @Table(name = "wb_tbl_color")
7
 @Table(name = "wb_tbl_color")
8
 public class Color implements Serializable {
8
 public class Color implements Serializable {
9
+    public void setColorId(Integer colorId) {
10
+        this.colorId = colorId;
11
+    }
12
+
9
     @Id
13
     @Id
10
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
11
-    private long color_id;
12
-    public long getColor_id() {
13
-        return color_id;
14
+    @GeneratedValue
15
+    @Column(name="color_id")
16
+    private Integer colorId;
17
+    public Integer getColorId() {
18
+        return colorId;
14
     }
19
     }
15
     @Column(name="color_name")
20
     @Column(name="color_name")
16
-    private String color_name;
17
-    public String getColor_name() {
18
-        return color_name;
21
+    private String colorName;
22
+    @Column(name = "color_status")
23
+    private String colorStatus;
24
+    @Column(name = "color_type")
25
+    private String colorType;
26
+    public String getColorName() {
27
+        return colorName;
19
     }
28
     }
20
 
29
 
21
-    public String getColor_status() {
22
-        return color_status;
30
+    public void setColorName(String colorName) {
31
+        this.colorName = colorName;
23
     }
32
     }
24
 
33
 
25
-    public void setColor_status(String color_status) {
26
-        this.color_status = color_status;
34
+    public String getColorStatus() {
35
+        return colorStatus;
27
     }
36
     }
28
-    @Column(name = "color_status")
29
-    private String color_status;
30
 
37
 
31
-    public String getColor_type() {
32
-        return color_type;
38
+    public void setColorStatus(String colorStatus) {
39
+        this.colorStatus = colorStatus;
33
     }
40
     }
34
 
41
 
35
-    public void setColor_type(String color_type) {
36
-        this.color_type = color_type;
42
+    public String getColorType() {
43
+        return colorType;
37
     }
44
     }
38
 
45
 
39
-    @Column(name = "color_type")
40
-    private String color_type;
46
+    public void setColorType(String colorType) {
47
+        this.colorType = colorType;
48
+    }
41
 
49
 
42
 
50
 
43
 
51
 

+ 1 - 1
src/main/resources/application.properties

@@ -1,6 +1,6 @@
1
 server.port=8081
1
 server.port=8081
2
 spring.datasource.url=jdbc:mysql://192.168.2.130:3306/ceshi?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
2
 spring.datasource.url=jdbc:mysql://192.168.2.130:3306/ceshi?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
3
-spring.datasource.name=root
3
+spring.datasource.username=root
4
 spring.datasource.password=123456
4
 spring.datasource.password=123456
5
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
5
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
6
 spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
6
 spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect