Skip to content

Commit 079fee3

Browse files
committed
友链
1 parent 82e5130 commit 079fee3

3 files changed

Lines changed: 183 additions & 2 deletions

File tree

admin/src/main/java/info/xiaomo/admin/controller/LinkController.java

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
package info.xiaomo.admin.controller;
22

3+
import info.xiaomo.core.controller.BaseController;
4+
import info.xiaomo.core.model.LinkModel;
5+
import info.xiaomo.core.service.LinkService;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.PageRequest;
39
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestParam;
411
import org.springframework.web.bind.annotation.RestController;
512

13+
import java.util.HashMap;
14+
615
/**
716
* 把今天最好的表现当作明天最新的起点..~
817
* いま 最高の表現 として 明日最新の始発..~
@@ -19,5 +28,84 @@
1928
**/
2029
@RestController
2130
@RequestMapping("/admin/link")
22-
public class LinkController {
31+
public class LinkController extends BaseController {
32+
33+
@Autowired
34+
private LinkService service;
35+
36+
@RequestMapping("findById")
37+
public HashMap<String, Object> findLinkById(@RequestParam Long id) {
38+
LinkModel model = service.findById(id);
39+
if (model == null) {
40+
result.put(code, notFound);
41+
return result;
42+
}
43+
result.put(code, success);
44+
result.put(link, model);
45+
return result;
46+
}
47+
48+
@RequestMapping("findByName")
49+
public HashMap<String, Object> findByName(@RequestParam String name) {
50+
LinkModel model = service.findByName(name);
51+
if (model == null) {
52+
result.put(code, notFound);
53+
return result;
54+
}
55+
result.put(code, success);
56+
result.put(link, model);
57+
return result;
58+
}
59+
60+
61+
@RequestMapping("findAll")
62+
public HashMap<String, Object> findAll(@RequestParam int start, @RequestParam int pageSize) {
63+
Page<LinkModel> models = service.findAll(new PageRequest(start - 1, pageSize));
64+
result.put(code, success);
65+
result.put(links, models);
66+
return result;
67+
}
68+
69+
70+
@RequestMapping("add")
71+
public HashMap<String, Object> add(@RequestParam String name) {
72+
LinkModel linkModel = service.findByName(name);
73+
if (linkModel != null) {
74+
result.put(code, repeat);
75+
return result;
76+
}
77+
linkModel = new LinkModel();
78+
linkModel.setName(name);
79+
LinkModel add = service.add(linkModel);
80+
result.put(code, success);
81+
result.put(link, add);
82+
return result;
83+
}
84+
85+
@RequestMapping("update")
86+
public HashMap<String, Object> update(@RequestParam String name) {
87+
LinkModel LinkModel = service.findByName(name);
88+
if (LinkModel == null) {
89+
result.put(code, notFound);
90+
return result;
91+
}
92+
LinkModel.setName(name);
93+
LinkModel update = service.update(LinkModel);
94+
result.put(code, success);
95+
result.put(link, update);
96+
return result;
97+
}
98+
99+
@RequestMapping("delete")
100+
public HashMap<String, Object> delete(@RequestParam Long id) {
101+
LinkModel LinkModel = service.findById(id);
102+
if (LinkModel == null) {
103+
result.put(code, notFound);
104+
return result;
105+
}
106+
LinkModel delete = service.delete(id);
107+
result.put(code, success);
108+
result.put(link, delete);
109+
return result;
110+
}
23111
}

core/src/main/java/info/xiaomo/core/service/impl/LinkServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.springframework.data.domain.Pageable;
99
import org.springframework.stereotype.Service;
1010

11+
import java.util.Date;
12+
1113
/**
1214
* 把今天最好的表现当作明天最新的起点..~
1315
* いま 最高の表現 として 明日最新の始発..~
@@ -45,6 +47,8 @@ public Page<LinkModel> findAll(Pageable pageable) {
4547

4648
@Override
4749
public LinkModel add(LinkModel model) {
50+
model.setCreateTime(new Date());
51+
model.setUpdateTime(new Date());
4852
return dao.save(model);
4953
}
5054

@@ -57,6 +61,7 @@ public LinkModel update(LinkModel model) {
5761
if (!model.getUrl().equals(updateModel.getUrl())) {
5862
updateModel.setUrl(model.getName());
5963
}
64+
model.setUpdateTime(new Date());
6065
return dao.save(updateModel);
6166
}
6267

web/src/main/java/info/xiaomo/web/controller/LinkController.java

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
package info.xiaomo.web.controller;
22

3+
import info.xiaomo.core.controller.BaseController;
4+
import info.xiaomo.core.model.LinkModel;
5+
import info.xiaomo.core.service.LinkService;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.PageRequest;
39
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestParam;
411
import org.springframework.web.bind.annotation.RestController;
512

13+
import java.util.HashMap;
14+
615
/**
716
* 把今天最好的表现当作明天最新的起点..~
817
* いま 最高の表現 として 明日最新の始発..~
@@ -19,5 +28,84 @@
1928
**/
2029
@RestController
2130
@RequestMapping("/web/link")
22-
public class LinkController {
31+
public class LinkController extends BaseController {
32+
33+
@Autowired
34+
private LinkService service;
35+
36+
@RequestMapping("findById")
37+
public HashMap<String, Object> findLinkById(@RequestParam Long id) {
38+
LinkModel model = service.findById(id);
39+
if (model == null) {
40+
result.put(code, notFound);
41+
return result;
42+
}
43+
result.put(code, success);
44+
result.put(link, model);
45+
return result;
46+
}
47+
48+
@RequestMapping("findByName")
49+
public HashMap<String, Object> findByName(@RequestParam String name) {
50+
LinkModel model = service.findByName(name);
51+
if (model == null) {
52+
result.put(code, notFound);
53+
return result;
54+
}
55+
result.put(code, success);
56+
result.put(link, model);
57+
return result;
58+
}
59+
60+
61+
@RequestMapping("findAll")
62+
public HashMap<String, Object> findAll(@RequestParam int start, @RequestParam int pageSize) {
63+
Page<LinkModel> models = service.findAll(new PageRequest(start - 1, pageSize));
64+
result.put(code, success);
65+
result.put(links, models);
66+
return result;
67+
}
68+
69+
70+
@RequestMapping("add")
71+
public HashMap<String, Object> add(@RequestParam String name) {
72+
LinkModel linkModel = service.findByName(name);
73+
if (linkModel != null) {
74+
result.put(code, repeat);
75+
return result;
76+
}
77+
linkModel = new LinkModel();
78+
linkModel.setName(name);
79+
LinkModel add = service.add(linkModel);
80+
result.put(code, success);
81+
result.put(link, add);
82+
return result;
83+
}
84+
85+
@RequestMapping("update")
86+
public HashMap<String, Object> update(@RequestParam String name) {
87+
LinkModel LinkModel = service.findByName(name);
88+
if (LinkModel == null) {
89+
result.put(code, notFound);
90+
return result;
91+
}
92+
LinkModel.setName(name);
93+
LinkModel update = service.update(LinkModel);
94+
result.put(code, success);
95+
result.put(link, update);
96+
return result;
97+
}
98+
99+
@RequestMapping("delete")
100+
public HashMap<String, Object> delete(@RequestParam Long id) {
101+
LinkModel LinkModel = service.findById(id);
102+
if (LinkModel == null) {
103+
result.put(code, notFound);
104+
return result;
105+
}
106+
LinkModel delete = service.delete(id);
107+
result.put(code, success);
108+
result.put(link, delete);
109+
return result;
110+
}
23111
}

0 commit comments

Comments
 (0)