Skip to content

Commit dc4e9d8

Browse files
committed
add es
1 parent d413685 commit dc4e9d8

File tree

15 files changed

+658
-0
lines changed

15 files changed

+658
-0
lines changed

springboot-elasticsearch/pom.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>cn.abel</groupId>
8+
<artifactId>springboot-elasticserach</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<parent>
11+
<groupId>org.springframework.boot</groupId>
12+
<artifactId>spring-boot-starter-parent</artifactId>
13+
<version>2.0.4.RELEASE</version>
14+
<relativePath/>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-web</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-test</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-freemarker</artifactId>
31+
</dependency>
32+
33+
<!--mybatis-->
34+
<dependency>
35+
<groupId>org.mybatis.spring.boot</groupId>
36+
<artifactId>mybatis-spring-boot-starter</artifactId>
37+
<version>1.3.2</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.github.pagehelper</groupId>
41+
<artifactId>pagehelper-spring-boot-starter</artifactId>
42+
<version>1.2.5</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>mysql</groupId>
46+
<artifactId>mysql-connector-java</artifactId>
47+
<version>5.1.40</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>org.apache.commons</groupId>
52+
<artifactId>commons-lang3</artifactId>
53+
<version>3.4</version>
54+
</dependency>
55+
</dependencies>
56+
57+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.abel;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* @author yyb
8+
* @time 2019/3/26
9+
*/
10+
@SpringBootApplication
11+
public class Application {
12+
public static void main(String[] args) {
13+
SpringApplication.run(Application.class, args);
14+
}
15+
16+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package cn.abel.bean;
2+
3+
4+
public class News {
5+
private Integer id;
6+
private String title;
7+
private String content;
8+
private String imagePath;
9+
private Integer readSum;
10+
11+
public Integer getId() {
12+
return id;
13+
}
14+
15+
public void setId(Integer id) {
16+
this.id = id;
17+
}
18+
19+
public String getTitle() {
20+
return title;
21+
}
22+
23+
public void setTitle(String title) {
24+
this.title = title;
25+
}
26+
27+
public String getContent() {
28+
return content;
29+
}
30+
31+
public void setContent(String content) {
32+
this.content = content;
33+
}
34+
35+
public String getImagePath() {
36+
return imagePath;
37+
}
38+
39+
public void setImagePath(String imagePath) {
40+
this.imagePath = imagePath;
41+
}
42+
43+
public Integer getReadSum() {
44+
return readSum;
45+
}
46+
47+
public void setReadSum(Integer readSum) {
48+
this.readSum = readSum;
49+
}
50+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package cn.abel.bean;
2+
3+
import java.util.Date;
4+
5+
6+
public class User {
7+
private Integer id;
8+
private String name;
9+
private String address;
10+
private String mobile;
11+
private String email;
12+
private Date createTime;
13+
private Integer role;
14+
15+
public Integer getId() {
16+
return id;
17+
}
18+
19+
public void setId(Integer id) {
20+
this.id = id;
21+
}
22+
23+
public String getName() {
24+
return name;
25+
}
26+
27+
public void setName(String name) {
28+
this.name = name;
29+
}
30+
31+
public String getAddress() {
32+
return address;
33+
}
34+
35+
public void setAddress(String address) {
36+
this.address = address;
37+
}
38+
39+
public String getMobile() {
40+
return mobile;
41+
}
42+
43+
public void setMobile(String mobile) {
44+
this.mobile = mobile;
45+
}
46+
47+
public String getEmail() {
48+
return email;
49+
}
50+
51+
public void setEmail(String email) {
52+
this.email = email;
53+
}
54+
55+
public Date getCreateTime() {
56+
return createTime;
57+
}
58+
59+
public void setCreateTime(Date createTime) {
60+
this.createTime = createTime;
61+
}
62+
63+
public Integer getRole() {
64+
return role;
65+
}
66+
67+
public void setRole(Integer role) {
68+
this.role = role;
69+
}
70+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cn.abel.dao;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import cn.abel.bean.News;
7+
import org.apache.ibatis.annotations.Mapper;
8+
import org.springframework.stereotype.Repository;
9+
10+
@Repository
11+
@Mapper
12+
public interface NewsDao {
13+
14+
List<News> getByMap(Map<String, Object> map);
15+
16+
News getById(Integer id);
17+
18+
Integer create(News news);
19+
20+
int update(News news);
21+
22+
int delete(Integer id);
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cn.abel.dao;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import cn.abel.bean.User;
7+
import org.apache.ibatis.annotations.Mapper;
8+
import org.springframework.stereotype.Repository;
9+
10+
@Repository
11+
@Mapper
12+
public interface UserDao {
13+
14+
List<User> getByMap(Map<String, Object> map);
15+
16+
User getById(Integer id);
17+
18+
Integer create(User user);
19+
20+
int update(User user);
21+
22+
int delete(Integer id);
23+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cn.abel.service;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import cn.abel.config.DynamicDataSource;
7+
import cn.abel.config.DynamicDataSourceContextHolder;
8+
import cn.abel.enums.DatabaseTypeEnum;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.stereotype.Service;
11+
12+
import cn.abel.dao.NewsDao;
13+
import cn.abel.bean.News;
14+
15+
@Service
16+
public class NewsService {
17+
@Autowired
18+
private NewsDao newsDao;
19+
20+
public List<News> getByMap(Map<String, Object> map) {
21+
DynamicDataSourceContextHolder.resetDatabaseType();
22+
return newsDao.getByMap(map);
23+
}
24+
25+
public News getById(Integer id) {
26+
DynamicDataSourceContextHolder.resetDatabaseType();
27+
return newsDao.getById(id);
28+
}
29+
30+
public News create(News news) {
31+
DynamicDataSourceContextHolder.resetDatabaseType();
32+
newsDao.create(news);
33+
return news;
34+
}
35+
36+
public News update(News news) {
37+
DynamicDataSourceContextHolder.resetDatabaseType();
38+
newsDao.update(news);
39+
return news;
40+
}
41+
42+
public int delete(Integer id) {
43+
DynamicDataSourceContextHolder.resetDatabaseType();
44+
return newsDao.delete(id);
45+
}
46+
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cn.abel.service;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import cn.abel.config.DynamicDataSourceContextHolder;
7+
import cn.abel.enums.DatabaseTypeEnum;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.stereotype.Service;
10+
11+
import cn.abel.dao.UserDao;
12+
import cn.abel.bean.User;
13+
14+
@Service
15+
public class UserService {
16+
@Autowired
17+
private UserDao userDao;
18+
19+
public List<User> getByMap(Map<String,Object> map){
20+
DynamicDataSourceContextHolder.setDatabaseType(DatabaseTypeEnum.USER);
21+
return userDao.getByMap(map);
22+
}
23+
24+
public User getById(Integer id){
25+
DynamicDataSourceContextHolder.setDatabaseType(DatabaseTypeEnum.USER);
26+
return userDao.getById(id);
27+
}
28+
29+
public User create(User user){
30+
DynamicDataSourceContextHolder.setDatabaseType(DatabaseTypeEnum.USER);
31+
userDao.create(user);
32+
return user;
33+
}
34+
35+
public User update(User user){
36+
DynamicDataSourceContextHolder.setDatabaseType(DatabaseTypeEnum.USER);
37+
userDao.update(user);
38+
return user;
39+
}
40+
41+
public int delete(Integer id){
42+
DynamicDataSourceContextHolder.setDatabaseType(DatabaseTypeEnum.USER);
43+
return userDao.delete(id);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)