|
@@ -0,0 +1,59 @@
|
|
1
|
+package com.controller;
|
|
2
|
+
|
|
3
|
+import com.pojo.entity.AEntity;
|
|
4
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
5
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
6
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
7
|
+import org.springframework.stereotype.Controller;
|
|
8
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
9
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
10
|
+
|
|
11
|
+import java.util.HashMap;
|
|
12
|
+import java.util.List;
|
|
13
|
+import java.util.Map;
|
|
14
|
+
|
|
15
|
+@Controller
|
|
16
|
+@RequestMapping("jdbc")
|
|
17
|
+public class JdbcTemplateController {
|
|
18
|
+ @Autowired
|
|
19
|
+ JdbcTemplate jdbcTemplate;
|
|
20
|
+ @RequestMapping("jdbc1")
|
|
21
|
+ @ResponseBody
|
|
22
|
+ public String jdbc1() {
|
|
23
|
+ return String.valueOf(jdbcTemplate.update("insert into `wb_tbl_a`(company_id,status) values (?,?)", 100, 100));
|
|
24
|
+ }
|
|
25
|
+ /**
|
|
26
|
+ * jdbc查询所有
|
|
27
|
+ */
|
|
28
|
+ @RequestMapping("queryAll")
|
|
29
|
+ @ResponseBody
|
|
30
|
+ public Map jdbc2() {
|
|
31
|
+ HashMap<String, String> stringStringHashMap = new HashMap<>();
|
|
32
|
+ stringStringHashMap.put("111","zxy");
|
|
33
|
+ List<AEntity> query = jdbcTemplate.query("select * from wb_tbl_a",
|
|
34
|
+ new BeanPropertyRowMapper<AEntity>(AEntity.class));
|
|
35
|
+ return stringStringHashMap;
|
|
36
|
+ }
|
|
37
|
+ /**
|
|
38
|
+ * 查询单个
|
|
39
|
+ *
|
|
40
|
+ */
|
|
41
|
+ @RequestMapping("queryOne")
|
|
42
|
+ @ResponseBody
|
|
43
|
+ public AEntity queryOne() {
|
|
44
|
+ return jdbcTemplate.queryForObject("select * from wb_tbl_a where id =?",
|
|
45
|
+ new BeanPropertyRowMapper<AEntity>(AEntity.class),
|
|
46
|
+ "10"
|
|
47
|
+ );
|
|
48
|
+ }
|
|
49
|
+ /**
|
|
50
|
+ * 聚合查询 查询总数
|
|
51
|
+ */
|
|
52
|
+ @RequestMapping("queryCount")
|
|
53
|
+ @ResponseBody
|
|
54
|
+ public Long queryCount() {
|
|
55
|
+ return jdbcTemplate.queryForObject("select count(*) from wb_tbl_a ",
|
|
56
|
+ Long.class
|
|
57
|
+ );
|
|
58
|
+ }
|
|
59
|
+}
|