init project
This commit is contained in:
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
57
bootstrap/pom.xml
Normal file
57
bootstrap/pom.xml
Normal file
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>forever</artifactId>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>bootstrap</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<artifactId>web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<outputDirectory>../target/boot</outputDirectory>
|
||||
<classifier>executable</classifier>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
13
bootstrap/src/main/java/com/qn/DemoApplication.java
Normal file
13
bootstrap/src/main/java/com/qn/DemoApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.qn;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
23
bootstrap/src/main/resources/application.properties
Normal file
23
bootstrap/src/main/resources/application.properties
Normal file
@@ -0,0 +1,23 @@
|
||||
server.port=8088
|
||||
|
||||
|
||||
mybatis.config-locations=classpath:mybatis/mybatis-config.xml
|
||||
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
|
||||
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.druid.filters=stat
|
||||
spring.datasource.druid.initialSize=1
|
||||
spring.datasource.druid.minIdle=1
|
||||
spring.datasource.druid.maxActive=40
|
||||
spring.datasource.druid.maxWait=600000
|
||||
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
|
||||
spring.datasource.druid.minEvictableIdleTimeMillis=300000
|
||||
spring.datasource.druid.testWhileIdle=true
|
||||
spring.datasource.druid.testOnBorrow=false
|
||||
spring.datasource.druid.testOnReturn=false
|
||||
spring.datasource.druid.poolPreparedStatements=true
|
||||
spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20
|
||||
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=123456
|
||||
22
common/pom.xml
Normal file
22
common/pom.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>forever</artifactId>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>${version}</version>
|
||||
<artifactId>common</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
154
common/src/main/java/com/qn/utils/HTTPUtils.java
Normal file
154
common/src/main/java/com/qn/utils/HTTPUtils.java
Normal file
@@ -0,0 +1,154 @@
|
||||
package com.qn.utils;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HTTPUtils {
|
||||
|
||||
public static String doGet(String url, Map<String, String> param) {
|
||||
// 创建Httpclient对象
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
String resultString = "";
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
// 创建uri
|
||||
URIBuilder builder = new URIBuilder(url);
|
||||
if (param != null) {
|
||||
for (String key : param.keySet()) {
|
||||
builder.addParameter(key, param.get(key));
|
||||
}
|
||||
}
|
||||
URI uri = builder.build();
|
||||
// 创建http GET请求
|
||||
HttpGet httpGet = new HttpGet(uri);
|
||||
// 执行请求
|
||||
response = httpclient.execute(httpGet);
|
||||
// 判断返回状态是否为200
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
httpclient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
public static String doGet(String url) {
|
||||
return doGet(url, null);
|
||||
}
|
||||
|
||||
public static String doPost(String url, Map<String, String> param) {
|
||||
// 创建Httpclient对象
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = null;
|
||||
String resultString = "";
|
||||
try {
|
||||
// 创建Http Post请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 创建参数列表
|
||||
if (param != null) {
|
||||
List<NameValuePair> paramList = new ArrayList<>();
|
||||
for (String key : param.keySet()) {
|
||||
paramList.add(new BasicNameValuePair(key, param.get(key)));
|
||||
}
|
||||
// 模拟表单
|
||||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,"utf-8");
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
// 执行http请求
|
||||
response = httpClient.execute(httpPost);
|
||||
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
public static String doPost(String url) {
|
||||
return doPost(url, null);
|
||||
}
|
||||
|
||||
public static String doPostJson(String url, String json) {
|
||||
// 创建Httpclient对象
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = null;
|
||||
String resultString = "";
|
||||
try {
|
||||
// 创建Http Post请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 创建请求内容
|
||||
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
|
||||
httpPost.setEntity(entity);
|
||||
// 执行http请求
|
||||
response = httpClient.execute(httpPost);
|
||||
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return resultString;
|
||||
}
|
||||
|
||||
public static String doPostXml(String url, String json) {
|
||||
// 创建Httpclient对象
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = null;
|
||||
String resultString = "";
|
||||
try {
|
||||
// 创建Http Post请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 创建请求内容
|
||||
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_XML);
|
||||
httpPost.setEntity(entity);
|
||||
// 执行http请求
|
||||
response = httpClient.execute(httpPost);
|
||||
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
}
|
||||
75
common/src/main/java/com/qn/utils/SignUtils.java
Normal file
75
common/src/main/java/com/qn/utils/SignUtils.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.qn.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SignUtils {
|
||||
|
||||
private static String token = "wxTokenfromqnforever";//这里是自定义的token,需和你提交的token一致
|
||||
|
||||
/**
|
||||
* 校验签名
|
||||
*
|
||||
* @param signature
|
||||
* 签名
|
||||
* @param timestamp
|
||||
* 时间戳
|
||||
* @param nonce
|
||||
* 随机数
|
||||
* @return 布尔值
|
||||
*/
|
||||
public static boolean checkSignature(String signature, String timestamp, String nonce) {
|
||||
String checktext = null;
|
||||
if (null != signature) {
|
||||
// 对ToKen,timestamp,nonce 按字典排序
|
||||
String[] paramArr = new String[] { token, timestamp, nonce };
|
||||
Arrays.sort(paramArr);
|
||||
// 将排序后的结果拼成一个字符串
|
||||
String content = paramArr[0].concat(paramArr[1]).concat(paramArr[2]);
|
||||
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||
// 对接后的字符串进行sha1加密
|
||||
byte[] digest = md.digest(content.toString().getBytes());
|
||||
checktext = byteToStr(digest);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// 将加密后的字符串与signature进行对比
|
||||
return checktext != null ? checktext.equals(signature.toUpperCase()) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节数组转化为16进制字符串
|
||||
*
|
||||
* @param byteArrays
|
||||
* 字符数组
|
||||
* @return 字符串
|
||||
*/
|
||||
private static String byteToStr(byte[] byteArrays) {
|
||||
String str = "";
|
||||
for (int i = 0; i < byteArrays.length; i++) {
|
||||
str += byteToHexStr(byteArrays[i]);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节转化为十六进制字符串
|
||||
*
|
||||
* @param myByte
|
||||
* 字节
|
||||
* @return 字符串
|
||||
*/
|
||||
private static String byteToHexStr(byte myByte) {
|
||||
char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
char[] tampArr = new char[2];
|
||||
tampArr[0] = Digit[(myByte >>> 4) & 0X0F];
|
||||
tampArr[1] = Digit[myByte & 0X0F];
|
||||
String str = new String(tampArr);
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
63
common/src/main/java/model/wx/TextMessage.java
Normal file
63
common/src/main/java/model/wx/TextMessage.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package model.wx;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TextMessage implements Serializable {
|
||||
private String ToUserName;
|
||||
|
||||
private String FromUserName;
|
||||
|
||||
private Long CreateTime;
|
||||
|
||||
private String MsgType;
|
||||
private String Content;
|
||||
private String MsgId;
|
||||
|
||||
public String getToUserName() {
|
||||
return ToUserName;
|
||||
}
|
||||
|
||||
public void setToUserName(String toUserName) {
|
||||
ToUserName = toUserName;
|
||||
}
|
||||
|
||||
public String getFromUserName() {
|
||||
return FromUserName;
|
||||
}
|
||||
|
||||
public void setFromUserName(String fromUserName) {
|
||||
FromUserName = fromUserName;
|
||||
}
|
||||
|
||||
public Long getCreateTime() {
|
||||
return CreateTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Long createTime) {
|
||||
CreateTime = createTime;
|
||||
}
|
||||
|
||||
public String getMsgType() {
|
||||
return MsgType;
|
||||
}
|
||||
|
||||
public void setMsgType(String msgType) {
|
||||
MsgType = msgType;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return Content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
Content = content;
|
||||
}
|
||||
|
||||
public String getMsgId() {
|
||||
return MsgId;
|
||||
}
|
||||
|
||||
public void setMsgId(String msgId) {
|
||||
MsgId = msgId;
|
||||
}
|
||||
}
|
||||
52
dal/pom.xml
Normal file
52
dal/pom.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>forever</artifactId>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>dal</artifactId>
|
||||
<version>${version}</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.41</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.mybatis.generator</groupId>
|
||||
<artifactId>mybatis-generator-maven-plugin</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<configuration>
|
||||
<verbose>true</verbose>
|
||||
<overwrite>true</overwrite>
|
||||
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<!-- 数据库驱动 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.41</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
54
dal/src/main/java/com/qn/entity/User.java
Normal file
54
dal/src/main/java/com/qn/entity/User.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.qn.entity;
|
||||
|
||||
public class User {
|
||||
private String openid;
|
||||
|
||||
private String username;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String avatarUrl;
|
||||
|
||||
public User(String openid, String username, String phone, String avatarUrl) {
|
||||
this.openid = openid;
|
||||
this.username = username;
|
||||
this.phone = phone;
|
||||
this.avatarUrl = avatarUrl;
|
||||
}
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid == null ? null : openid.trim();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username == null ? null : username.trim();
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone == null ? null : phone.trim();
|
||||
}
|
||||
|
||||
public String getAvatarUrl() {
|
||||
return avatarUrl;
|
||||
}
|
||||
|
||||
public void setAvatarUrl(String avatarUrl) {
|
||||
this.avatarUrl = avatarUrl == null ? null : avatarUrl.trim();
|
||||
}
|
||||
}
|
||||
410
dal/src/main/java/com/qn/entity/UserExample.java
Normal file
410
dal/src/main/java/com/qn/entity/UserExample.java
Normal file
@@ -0,0 +1,410 @@
|
||||
package com.qn.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserExample {
|
||||
protected String orderByClause;
|
||||
|
||||
protected boolean distinct;
|
||||
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
public UserExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<Criterion>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
public Criteria andOpenidIsNull() {
|
||||
addCriterion("openid is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidIsNotNull() {
|
||||
addCriterion("openid is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidEqualTo(String value) {
|
||||
addCriterion("openid =", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidNotEqualTo(String value) {
|
||||
addCriterion("openid <>", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidGreaterThan(String value) {
|
||||
addCriterion("openid >", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("openid >=", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidLessThan(String value) {
|
||||
addCriterion("openid <", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidLessThanOrEqualTo(String value) {
|
||||
addCriterion("openid <=", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidLike(String value) {
|
||||
addCriterion("openid like", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidNotLike(String value) {
|
||||
addCriterion("openid not like", value, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidIn(List<String> values) {
|
||||
addCriterion("openid in", values, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidNotIn(List<String> values) {
|
||||
addCriterion("openid not in", values, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidBetween(String value1, String value2) {
|
||||
addCriterion("openid between", value1, value2, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOpenidNotBetween(String value1, String value2) {
|
||||
addCriterion("openid not between", value1, value2, "openid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameIsNull() {
|
||||
addCriterion("username is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameIsNotNull() {
|
||||
addCriterion("username is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameEqualTo(String value) {
|
||||
addCriterion("username =", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameNotEqualTo(String value) {
|
||||
addCriterion("username <>", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameGreaterThan(String value) {
|
||||
addCriterion("username >", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("username >=", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameLessThan(String value) {
|
||||
addCriterion("username <", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameLessThanOrEqualTo(String value) {
|
||||
addCriterion("username <=", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameLike(String value) {
|
||||
addCriterion("username like", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameNotLike(String value) {
|
||||
addCriterion("username not like", value, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameIn(List<String> values) {
|
||||
addCriterion("username in", values, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameNotIn(List<String> values) {
|
||||
addCriterion("username not in", values, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameBetween(String value1, String value2) {
|
||||
addCriterion("username between", value1, value2, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUsernameNotBetween(String value1, String value2) {
|
||||
addCriterion("username not between", value1, value2, "username");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneIsNull() {
|
||||
addCriterion("phone is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneIsNotNull() {
|
||||
addCriterion("phone is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneEqualTo(String value) {
|
||||
addCriterion("phone =", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneNotEqualTo(String value) {
|
||||
addCriterion("phone <>", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneGreaterThan(String value) {
|
||||
addCriterion("phone >", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("phone >=", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneLessThan(String value) {
|
||||
addCriterion("phone <", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneLessThanOrEqualTo(String value) {
|
||||
addCriterion("phone <=", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneLike(String value) {
|
||||
addCriterion("phone like", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneNotLike(String value) {
|
||||
addCriterion("phone not like", value, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneIn(List<String> values) {
|
||||
addCriterion("phone in", values, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneNotIn(List<String> values) {
|
||||
addCriterion("phone not in", values, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneBetween(String value1, String value2) {
|
||||
addCriterion("phone between", value1, value2, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPhoneNotBetween(String value1, String value2) {
|
||||
addCriterion("phone not between", value1, value2, "phone");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
dal/src/main/java/com/qn/mapper/UserMapper.java
Normal file
36
dal/src/main/java/com/qn/mapper/UserMapper.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.qn.mapper;
|
||||
|
||||
import com.qn.entity.User;
|
||||
import com.qn.entity.UserExample;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface UserMapper {
|
||||
int countByExample(UserExample example);
|
||||
|
||||
int deleteByExample(UserExample example);
|
||||
|
||||
int deleteByPrimaryKey(String openid);
|
||||
|
||||
int insert(User record);
|
||||
|
||||
int insertSelective(User record);
|
||||
|
||||
List<User> selectByExampleWithBLOBs(UserExample example);
|
||||
|
||||
List<User> selectByExample(UserExample example);
|
||||
|
||||
User selectByPrimaryKey(String openid);
|
||||
|
||||
int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);
|
||||
|
||||
int updateByExampleWithBLOBs(@Param("record") User record, @Param("example") UserExample example);
|
||||
|
||||
int updateByExample(@Param("record") User record, @Param("example") UserExample example);
|
||||
|
||||
int updateByPrimaryKeySelective(User record);
|
||||
|
||||
int updateByPrimaryKeyWithBLOBs(User record);
|
||||
|
||||
int updateByPrimaryKey(User record);
|
||||
}
|
||||
101
dal/src/main/resources/generatorConfig.xml
Normal file
101
dal/src/main/resources/generatorConfig.xml
Normal file
@@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<!-- 配置生成器 -->
|
||||
<generatorConfiguration>
|
||||
|
||||
<!--id:必选,上下文id,用于在生成错误时提示-->
|
||||
<context id="mysql" targetRuntime="MyBatis3">
|
||||
<!-- 生成的Java文件的编码 -->
|
||||
<property name="javaFileEncoding" value="UTF-8"/>
|
||||
<!-- 对注释进行控制 -->
|
||||
<commentGenerator>
|
||||
<!-- suppressDate是去掉生成日期那行注释 -->
|
||||
<property name="suppressDate" value="true"/>
|
||||
<!-- suppressAllComments是去掉所有的注解 -->
|
||||
<property name="suppressAllComments" value="true"/>
|
||||
</commentGenerator>
|
||||
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection
|
||||
driverClass="com.mysql.jdbc.Driver"
|
||||
connectionURL="jdbc:mysql://127.0.0.1:3306/smallapp_point?serverTimezone=GMT%2b8"
|
||||
userId="root"
|
||||
password="123456">
|
||||
</jdbcConnection>
|
||||
|
||||
<!-- java类型处理器
|
||||
用于处理DB中的类型到Java中的类型,默认使用JavaTypeResolverDefaultImpl;
|
||||
注意一点,默认会先尝试使用Integer,Long,Short等来对应DECIMAL和 NUMERIC数据类型;
|
||||
-->
|
||||
<javaTypeResolver type="org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl">
|
||||
<!--
|
||||
true:使用BigDecimal对应DECIMAL和 NUMERIC数据类型
|
||||
false:默认,
|
||||
scale>0;length>18:使用BigDecimal;
|
||||
scale=0;length[10,18]:使用Long;
|
||||
scale=0;length[5,9]:使用Integer;
|
||||
scale=0;length<5:使用Short;
|
||||
-->
|
||||
<property name="forceBigDecimals" value="false"/>
|
||||
</javaTypeResolver>
|
||||
|
||||
|
||||
<!-- java模型创建器,是必须要的元素
|
||||
负责:1,key类(见context的defaultModelType);2,java类;3,查询类
|
||||
targetPackage:生成的类要放的包,真实的包受enableSubPackages属性控制;
|
||||
targetProject:目标项目,指定一个存在的目录下,生成的内容会放到指定目录中,如果目录不存在,MBG不会自动建目录
|
||||
-->
|
||||
<javaModelGenerator targetPackage="com.qn.entity" targetProject="src/main/java">
|
||||
<!-- 是否允许子包,即targetPackage.schemaName.tableName -->
|
||||
<property name="enableSubPackages" value="true"/>
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 是否对类CHAR类型的列的数据进行trim操作 -->
|
||||
<property name="trimStrings" value="true"/>
|
||||
<!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 -->
|
||||
<property name="immutable" value="false"/>
|
||||
</javaModelGenerator>
|
||||
|
||||
<!-- 生成SQL map的XML文件生成器,
|
||||
注意,在Mybatis3之后,我们可以使用mapper.xml文件+Mapper接口(或者不用mapper接口),
|
||||
或者只使用Mapper接口+Annotation,
|
||||
所以,如果 javaClientGenerator配置中配置了需要生成XML的话,这个元素就必须配置
|
||||
targetPackage/targetProject:同javaModelGenerator
|
||||
-->
|
||||
<sqlMapGenerator targetPackage="mybatis.mapper" targetProject="src/main/resources">
|
||||
<!-- 在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false -->
|
||||
<property name="enableSubPackages" value="true"/>
|
||||
</sqlMapGenerator>
|
||||
|
||||
|
||||
<!-- 对于mybatis来说,即生成Mapper接口,注意,如果没有配置该元素,那么默认不会生成Mapper接口
|
||||
targetPackage/targetProject:同javaModelGenerator
|
||||
type:选择怎么生成mapper接口(在MyBatis3/MyBatis3Simple下):
|
||||
1,ANNOTATEDMAPPER:会生成使用Mapper接口+Annotation的方式创建(SQL生成在annotation中),不会生成对应的XML;
|
||||
2,MIXEDMAPPER:使用混合配置,会生成Mapper接口,并适当添加合适的Annotation,但是XML会生成在XML中;
|
||||
3,XMLMAPPER:会生成Mapper接口,接口完全依赖XML;
|
||||
注意,如果context是MyBatis3Simple:只支持ANNOTATEDMAPPER和XMLMAPPER
|
||||
-->
|
||||
<javaClientGenerator targetPackage="com.qn.mapper" type="XMLMAPPER" targetProject="src/main/java">
|
||||
<!-- 在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false -->
|
||||
<property name="enableSubPackages" value="true"/>
|
||||
</javaClientGenerator>
|
||||
|
||||
<!-- 选择一个table来生成相关文件,可以有一个或多个table,必须要有table元素
|
||||
tableName(必要):要生成对象的表名;
|
||||
domainObjectName 给表对应的 model 起名字
|
||||
注意:大小写敏感问题。
|
||||
-->
|
||||
<table tableName="tb_gw_user" domainObjectName="User">
|
||||
|
||||
<!--用来修改表中某个列的属性,一个table元素中可以有多个columnOverride元素哈.
|
||||
property属性来指定列要生成的属性名称.
|
||||
-->
|
||||
<!--<columnOverride column="username" property="userName" />-->
|
||||
</table>
|
||||
|
||||
</context>
|
||||
|
||||
</generatorConfiguration>
|
||||
241
dal/src/main/resources/mybatis/mapper/UserMapper.xml
Normal file
241
dal/src/main/resources/mybatis/mapper/UserMapper.xml
Normal file
@@ -0,0 +1,241 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.qn.mapper.UserMapper" >
|
||||
<resultMap id="BaseResultMap" type="com.qn.entity.User" >
|
||||
<constructor >
|
||||
<idArg column="openid" jdbcType="VARCHAR" javaType="java.lang.String" />
|
||||
<arg column="username" jdbcType="VARCHAR" javaType="java.lang.String" />
|
||||
<arg column="phone" jdbcType="VARCHAR" javaType="java.lang.String" />
|
||||
</constructor>
|
||||
</resultMap>
|
||||
<resultMap id="ResultMapWithBLOBs" type="com.qn.entity.User" >
|
||||
<constructor >
|
||||
<idArg column="openid" jdbcType="VARCHAR" javaType="java.lang.String" />
|
||||
<arg column="username" jdbcType="VARCHAR" javaType="java.lang.String" />
|
||||
<arg column="phone" jdbcType="VARCHAR" javaType="java.lang.String" />
|
||||
<arg column="avatar_url" jdbcType="LONGVARCHAR" javaType="java.lang.String" />
|
||||
</constructor>
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause" >
|
||||
<where >
|
||||
<foreach collection="oredCriteria" item="criteria" separator="or" >
|
||||
<if test="criteria.valid" >
|
||||
<trim prefix="(" suffix=")" prefixOverrides="and" >
|
||||
<foreach collection="criteria.criteria" item="criterion" >
|
||||
<choose >
|
||||
<when test="criterion.noValue" >
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue" >
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue" >
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue" >
|
||||
and ${criterion.condition}
|
||||
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Update_By_Example_Where_Clause" >
|
||||
<where >
|
||||
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
|
||||
<if test="criteria.valid" >
|
||||
<trim prefix="(" suffix=")" prefixOverrides="and" >
|
||||
<foreach collection="criteria.criteria" item="criterion" >
|
||||
<choose >
|
||||
<when test="criterion.noValue" >
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue" >
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue" >
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue" >
|
||||
and ${criterion.condition}
|
||||
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List" >
|
||||
openid, username, phone
|
||||
</sql>
|
||||
<sql id="Blob_Column_List" >
|
||||
avatar_url
|
||||
</sql>
|
||||
<select id="selectByExampleWithBLOBs" resultMap="ResultMapWithBLOBs" parameterType="com.qn.entity.UserExample" >
|
||||
select
|
||||
<if test="distinct" >
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List" />
|
||||
,
|
||||
<include refid="Blob_Column_List" />
|
||||
from tb_gw_user
|
||||
<if test="_parameter != null" >
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
<if test="orderByClause != null" >
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.qn.entity.UserExample" >
|
||||
select
|
||||
<if test="distinct" >
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List" />
|
||||
from tb_gw_user
|
||||
<if test="_parameter != null" >
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
<if test="orderByClause != null" >
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String" >
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
,
|
||||
<include refid="Blob_Column_List" />
|
||||
from tb_gw_user
|
||||
where openid = #{openid,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
|
||||
delete from tb_gw_user
|
||||
where openid = #{openid,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
<delete id="deleteByExample" parameterType="com.qn.entity.UserExample" >
|
||||
delete from tb_gw_user
|
||||
<if test="_parameter != null" >
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.qn.entity.User" >
|
||||
insert into tb_gw_user (openid, username, phone,
|
||||
avatar_url)
|
||||
values (#{openid,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
|
||||
#{avatarUrl,jdbcType=LONGVARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.qn.entity.User" >
|
||||
insert into tb_gw_user
|
||||
<trim prefix="(" suffix=")" suffixOverrides="," >
|
||||
<if test="openid != null" >
|
||||
openid,
|
||||
</if>
|
||||
<if test="username != null" >
|
||||
username,
|
||||
</if>
|
||||
<if test="phone != null" >
|
||||
phone,
|
||||
</if>
|
||||
<if test="avatarUrl != null" >
|
||||
avatar_url,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
||||
<if test="openid != null" >
|
||||
#{openid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="username != null" >
|
||||
#{username,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="phone != null" >
|
||||
#{phone,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="avatarUrl != null" >
|
||||
#{avatarUrl,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="com.qn.entity.UserExample" resultType="java.lang.Integer" >
|
||||
select count(*) from tb_gw_user
|
||||
<if test="_parameter != null" >
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</select>
|
||||
<update id="updateByExampleSelective" parameterType="map" >
|
||||
update tb_gw_user
|
||||
<set >
|
||||
<if test="record.openid != null" >
|
||||
openid = #{record.openid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.username != null" >
|
||||
username = #{record.username,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.phone != null" >
|
||||
phone = #{record.phone,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.avatarUrl != null" >
|
||||
avatar_url = #{record.avatarUrl,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null" >
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByExampleWithBLOBs" parameterType="map" >
|
||||
update tb_gw_user
|
||||
set openid = #{record.openid,jdbcType=VARCHAR},
|
||||
username = #{record.username,jdbcType=VARCHAR},
|
||||
phone = #{record.phone,jdbcType=VARCHAR},
|
||||
avatar_url = #{record.avatarUrl,jdbcType=LONGVARCHAR}
|
||||
<if test="_parameter != null" >
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByExample" parameterType="map" >
|
||||
update tb_gw_user
|
||||
set openid = #{record.openid,jdbcType=VARCHAR},
|
||||
username = #{record.username,jdbcType=VARCHAR},
|
||||
phone = #{record.phone,jdbcType=VARCHAR}
|
||||
<if test="_parameter != null" >
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.qn.entity.User" >
|
||||
update tb_gw_user
|
||||
<set >
|
||||
<if test="username != null" >
|
||||
username = #{username,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="phone != null" >
|
||||
phone = #{phone,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="avatarUrl != null" >
|
||||
avatar_url = #{avatarUrl,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where openid = #{openid,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.qn.entity.User" >
|
||||
update tb_gw_user
|
||||
set username = #{username,jdbcType=VARCHAR},
|
||||
phone = #{phone,jdbcType=VARCHAR},
|
||||
avatar_url = #{avatarUrl,jdbcType=LONGVARCHAR}
|
||||
where openid = #{openid,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.qn.entity.User" >
|
||||
update tb_gw_user
|
||||
set username = #{username,jdbcType=VARCHAR},
|
||||
phone = #{phone,jdbcType=VARCHAR}
|
||||
where openid = #{openid,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
||||
24
dal/src/main/resources/mybatis/mybatis-config.xml
Normal file
24
dal/src/main/resources/mybatis/mybatis-config.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
|
||||
|
||||
<configuration>
|
||||
<settings>
|
||||
<setting name="cacheEnabled" value="true" />
|
||||
<!-- 打印sql日志 -->
|
||||
<setting name="logImpl" value="SLF4J" />
|
||||
</settings>
|
||||
|
||||
<typeAliases>
|
||||
<typeAlias alias="Integer" type="java.lang.Integer" />
|
||||
<typeAlias alias="Byte" type="java.lang.Byte"/>
|
||||
<typeAlias alias="String" type="java.lang.String" />
|
||||
<typeAlias alias="Long" type="java.lang.Long" />
|
||||
<typeAlias alias="HashMap" type="java.util.HashMap" />
|
||||
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" />
|
||||
<typeAlias alias="ArrayList" type="java.util.ArrayList" />
|
||||
<typeAlias alias="LinkedList" type="java.util.LinkedList" />
|
||||
</typeAliases>
|
||||
|
||||
</configuration>
|
||||
8
docker/Dockerfile
Normal file
8
docker/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM java:8
|
||||
|
||||
ADD ../target/boot/bootstrap-1.0.0-executable.jar /home
|
||||
ADD run.sh /home
|
||||
|
||||
EXPOSE 8088
|
||||
|
||||
ENTRYPOINT [ "sh", "/home/run.sh" ]
|
||||
1
docker/run.sh
Normal file
1
docker/run.sh
Normal file
@@ -0,0 +1 @@
|
||||
java -jar /home/web-1.0.0.jar
|
||||
83
pom.xml
Normal file
83
pom.xml
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.3.RELEASE</version>
|
||||
</parent>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<artifactId>forever</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<version>1.0.0</version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<artifactId>web</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<artifactId>dal</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
<version>3.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.20</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
<threadCount>1</threadCount>
|
||||
<includes>
|
||||
<include>**/*Tests.java</include>
|
||||
<include>**/*Test.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<modules>
|
||||
<module>web</module>
|
||||
<module>common</module>
|
||||
<module>dal</module>
|
||||
<module>bootstrap</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
52
web/pom.xml
Normal file
52
web/pom.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>forever</artifactId>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>web</artifactId>
|
||||
<version>${version}</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.love.qn</groupId>
|
||||
<artifactId>dal</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>1.4.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
<version>3.9.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
29
web/src/main/java/com/qn/controller/HomeController.java
Normal file
29
web/src/main/java/com/qn/controller/HomeController.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.qn.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Controller
|
||||
public class HomeController {
|
||||
/**
|
||||
* 表白
|
||||
*/
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public void enter(HttpServletResponse response) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><head></head>");
|
||||
sb.append("<body><h1>欢迎光临QN恋爱中!</h1>");
|
||||
sb.append("<p>此网站没有网页,只为【惊喜女友的微信小程序】提供必要的后台支持,该网页为备案号专用网页。</p>");
|
||||
// 设置备案号
|
||||
sb.append("<a href = 'https://beian.miit.gov.cn'>浙ICP备2020031991号</a>");
|
||||
sb.append("</body></html>");
|
||||
response.setStatus(200);
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write(sb.toString());
|
||||
response.flushBuffer();
|
||||
}
|
||||
}
|
||||
33
web/src/main/java/com/qn/controller/TestController.java
Normal file
33
web/src/main/java/com/qn/controller/TestController.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.qn.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
/**
|
||||
* 表白
|
||||
*/
|
||||
@RequestMapping(value = "/to/{name}", method = RequestMethod.GET)
|
||||
public void enter(@PathVariable("name") String name, HttpServletResponse response) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><head></head>");
|
||||
sb.append("<body><h1>");
|
||||
if (name==null || "".equals(name)){
|
||||
name = "王娜";
|
||||
}
|
||||
sb.append(name);
|
||||
sb.append(",I love you!!!</h1></body></html>");
|
||||
response.setStatus(200);
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write(sb.toString());
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
}
|
||||
75
web/src/main/java/com/qn/controller/WXTokenController.java
Normal file
75
web/src/main/java/com/qn/controller/WXTokenController.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.qn.controller;
|
||||
|
||||
import com.qn.controller.utils.MessageUtils;
|
||||
import com.qn.utils.SignUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class WXTokenController {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger("WXTokenController");
|
||||
|
||||
/**
|
||||
* 微信TokenCheck
|
||||
*/
|
||||
@RequestMapping(value = "/wx", method = RequestMethod.GET)
|
||||
public void wxTokenCheck(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
if (!StringUtils.isEmpty(request.getParameter("signature"))) {
|
||||
String signature = request.getParameter("signature");
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
String nonce = request.getParameter("nonce");
|
||||
String echostr = request.getParameter("echostr");
|
||||
logger.info("signature[{}], timestamp[{}], nonce[{}], echostr[{}]", signature, timestamp, nonce, echostr);
|
||||
if (SignUtils.checkSignature(signature, timestamp, nonce)) {
|
||||
logger.info("数据源为微信后台,将echostr[{}]返回!", echostr);
|
||||
response.getOutputStream().println(echostr);
|
||||
response.flushBuffer();
|
||||
}
|
||||
}else {
|
||||
logger.info("不是微信请求,不操作");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信TokenCheck
|
||||
*/
|
||||
@RequestMapping(value = "/wx", method = RequestMethod.POST)
|
||||
public void wxMessage(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Map<String,String> map = MessageUtils.xmlToMap(request);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
map.forEach((x,y) ->
|
||||
sb.append(x + "===" + y + ";"));
|
||||
logger.info("此次微信请求的消息内容为:" + sb.toString());
|
||||
String toUserName = map.get("ToUserName");
|
||||
String fromUserName = map.get("FromUserName");
|
||||
String msgType = map.get("MsgType");
|
||||
String content = map.get("Content");
|
||||
String message = null;
|
||||
// HTTPUtils.doPost()
|
||||
if ("text".equals(msgType)){
|
||||
//回复文本信息触发的消息
|
||||
message = MessageUtils.initText(toUserName,fromUserName,"text",fromUserName + "您好!" + content);
|
||||
}else if ("text".equals(msgType)){
|
||||
//关注时触发的消息
|
||||
String event = map.get("Event");
|
||||
if ("subscribe".equals(event)){
|
||||
message = MessageUtils.initText(toUserName,fromUserName,"text","Welcome lmq love nn");
|
||||
}
|
||||
}
|
||||
logger.info("返回微信的数据为" + message);
|
||||
response.setContentType("text/xml;charset=utf-8");
|
||||
response.getWriter().write(message);
|
||||
response.flushBuffer();
|
||||
}
|
||||
}
|
||||
69
web/src/main/java/com/qn/controller/utils/MessageUtils.java
Normal file
69
web/src/main/java/com/qn/controller/utils/MessageUtils.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.qn.controller.utils;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import model.wx.TextMessage;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MessageUtils {
|
||||
/**
|
||||
* xml转Map
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static Map<String,String> xmlToMap(HttpServletRequest request) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
SAXReader reader = new SAXReader();
|
||||
ServletInputStream in = null;
|
||||
try{
|
||||
in = request.getInputStream();
|
||||
Document doc = reader.read(in);
|
||||
Element root = doc.getRootElement();
|
||||
List<Element> list = root.elements();
|
||||
for (Element e: list){
|
||||
map.put(e.getName(),e.getText());
|
||||
}
|
||||
in.close();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本对象转换成xml
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public static String textMessageToXml(Object message){
|
||||
XStream xStream = new XStream();
|
||||
xStream.alias("xml",message.getClass());
|
||||
return xStream.toXML(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化文本信息
|
||||
* @param toUserName
|
||||
* @param fromUserName
|
||||
* @param msgType
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
public static String initText(String toUserName,String fromUserName,String msgType,String content){
|
||||
TextMessage textMessage = new TextMessage();
|
||||
textMessage.setFromUserName(toUserName);
|
||||
textMessage.setToUserName(fromUserName);
|
||||
textMessage.setMsgType(msgType);
|
||||
textMessage.setCreateTime(new Date().getTime());
|
||||
textMessage.setContent(content);
|
||||
return MessageUtils.textMessageToXml(textMessage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user