瀏覽代碼

started homes service

mpierse 5 年之前
父節點
當前提交
74743087e9

+ 40
- 0
src/main/java/io/zipcoder/persistenceapp/home/Home.java 查看文件

1
+package io.zipcoder.persistenceapp.home;
2
+
3
+public class Home {
4
+
5
+    private Long id;
6
+    private String address;
7
+    private String homenumber;
8
+
9
+    public Home(){}
10
+
11
+    public Home(Long id, String address, String homenumber) {
12
+        this.id = id;
13
+        this.address = address;
14
+        this.homenumber = homenumber;
15
+    }
16
+
17
+    public Long getId() {
18
+        return id;
19
+    }
20
+
21
+    public void setId(Long id) {
22
+        this.id = id;
23
+    }
24
+
25
+    public String getAddress() {
26
+        return address;
27
+    }
28
+
29
+    public void setAddress(String address) {
30
+        this.address = address;
31
+    }
32
+
33
+    public String getHomenumber() {
34
+        return homenumber;
35
+    }
36
+
37
+    public void setHomenumber(String homenumber) {
38
+        this.homenumber = homenumber;
39
+    }
40
+}

+ 4
- 0
src/main/java/io/zipcoder/persistenceapp/home/HomeController.java 查看文件

1
+package io.zipcoder.persistenceapp.home;
2
+
3
+public class HomeController {
4
+}

+ 33
- 0
src/main/java/io/zipcoder/persistenceapp/home/HomeService.java 查看文件

1
+package io.zipcoder.persistenceapp.home;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.jdbc.core.JdbcTemplate;
5
+import org.springframework.stereotype.Service;
6
+
7
+import java.util.ArrayList;
8
+import java.util.List;
9
+import java.util.Map;
10
+
11
+@Service
12
+public class HomeService {
13
+
14
+    @Autowired
15
+    JdbcTemplate jdbcTemplate;
16
+
17
+    public HomeService() {
18
+    }
19
+
20
+    public List<Home> findAll(){
21
+        String sql = "Select * from Home";
22
+        List<Home> homes = new ArrayList<>();
23
+        List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);
24
+        for(Map row : rows){
25
+            Home h = new Home();
26
+            h.setId(Long.parseLong(String.valueOf(row.get("id"))));
27
+            h.setAddress((String) row.get("address"));
28
+            h.setHomenumber((String) row.get("homenumber"));
29
+            homes.add(h);
30
+        }
31
+        return homes;
32
+    }
33
+}

src/main/java/io/zipcoder/persistenceapp/Person.java → src/main/java/io/zipcoder/persistenceapp/person/Person.java 查看文件

1
-package io.zipcoder.persistenceapp;
1
+package io.zipcoder.persistenceapp.person;
2
 
2
 
3
 import javax.persistence.criteria.CriteriaBuilder;
3
 import javax.persistence.criteria.CriteriaBuilder;
4
 import java.util.Date;
4
 import java.util.Date;

src/main/java/io/zipcoder/persistenceapp/PersonController.java → src/main/java/io/zipcoder/persistenceapp/person/PersonController.java 查看文件

1
-package io.zipcoder.persistenceapp;
1
+package io.zipcoder.persistenceapp.person;
2
 
2
 
3
 import org.springframework.beans.factory.annotation.Autowired;
3
 import org.springframework.beans.factory.annotation.Autowired;
4
-import org.springframework.jdbc.core.JdbcOperations;
5
-import org.springframework.jdbc.core.RowMapper;
6
 import org.springframework.web.bind.annotation.PathVariable;
4
 import org.springframework.web.bind.annotation.PathVariable;
7
 import org.springframework.web.bind.annotation.RequestMapping;
5
 import org.springframework.web.bind.annotation.RequestMapping;
8
 import org.springframework.web.bind.annotation.RequestMethod;
6
 import org.springframework.web.bind.annotation.RequestMethod;
9
 import org.springframework.web.bind.annotation.RestController;
7
 import org.springframework.web.bind.annotation.RestController;
10
 
8
 
11
-import java.sql.ResultSet;
12
-import java.sql.SQLException;
13
-import java.util.Date;
14
 import java.util.List;
9
 import java.util.List;
15
 
10
 
16
 @RestController
11
 @RestController

src/main/java/io/zipcoder/persistenceapp/PersonService.java → src/main/java/io/zipcoder/persistenceapp/person/PersonService.java 查看文件

1
-package io.zipcoder.persistenceapp;
1
+package io.zipcoder.persistenceapp.person;
2
 
2
 
3
+import io.zipcoder.persistenceapp.person.Person;
3
 import org.springframework.beans.factory.annotation.Autowired;
4
 import org.springframework.beans.factory.annotation.Autowired;
4
 import org.springframework.jdbc.core.JdbcTemplate;
5
 import org.springframework.jdbc.core.JdbcTemplate;
5
-import org.springframework.jdbc.core.RowMapper;
6
 import org.springframework.stereotype.Service;
6
 import org.springframework.stereotype.Service;
7
 
7
 
8
-import java.text.DateFormat;
9
 import java.util.ArrayList;
8
 import java.util.ArrayList;
10
-import java.util.Date;
11
 import java.util.List;
9
 import java.util.List;
12
 import java.util.Map;
10
 import java.util.Map;
13
 
11