().eq("brand_id",1));
+
+ list.forEach((item)->{
+ System.out.println(item);
+ });
+
+ }
+
+}
diff --git a/mall-common/mall-common.iml b/mall-common/mall-common.iml
index ddaeab8..1729aec 100644
--- a/mall-common/mall-common.iml
+++ b/mall-common/mall-common.iml
@@ -1,5 +1,10 @@
+
+
+
+
+
@@ -11,5 +16,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mall-common/pom.xml b/mall-common/pom.xml
index 7bd59e0..d0366e5 100644
--- a/mall-common/pom.xml
+++ b/mall-common/pom.xml
@@ -3,17 +3,76 @@
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">
- bookmall
- com.bookstore.bookmall
- 0.0.1-SNAPSHOT
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.1
+
4.0.0
+ com.bookstore.bookmall
mall-common
+ 0.0.1-SNAPSHOT
+ 每一个微服务公共的依赖,bean,工具类
+
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.5.3
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.26
+
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ 4.4.16
+
+
+ commons-lang
+ commons-lang
+ 2.6
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+ provided
+
+
+ javax.validation
+ validation-api
+ 2.0.1.Final
+
+
+
+
+
+
+
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.17
+
+
+
+
8
8
+
+
\ No newline at end of file
diff --git a/mall-common/src/main/java/com/bookstore/common/utils/Constant.java b/mall-common/src/main/java/com/bookstore/common/utils/Constant.java
new file mode 100644
index 0000000..5e25c3a
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/utils/Constant.java
@@ -0,0 +1,153 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.utils;
+
+import com.bookstore.common.validator.group.AliyunGroup;
+import com.bookstore.common.validator.group.QcloudGroup;
+import com.bookstore.common.validator.group.QiniuGroup;
+
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+/**
+ * 常量
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class Constant {
+ /**
+ * 超级管理员ID
+ */
+ public static final int SUPER_ADMIN = 1;
+ /**
+ * 当前页码
+ */
+ public static final String PAGE = "page";
+ /**
+ * 每页显示记录数
+ */
+ public static final String LIMIT = "limit";
+ /**
+ * 排序字段
+ */
+ public static final String ORDER_FIELD = "sidx";
+ /**
+ * 排序方式
+ */
+ public static final String ORDER = "order";
+ /**
+ * 升序
+ */
+ public static final String ASC = "asc";
+
+ /**
+ * 菜单类型
+ *
+ * @author chenshun
+ * @email sunlightcs@gmail.com
+ * @date 2016年11月15日 下午1:24:29
+ */
+ public enum MenuType {
+ /**
+ * 目录
+ */
+ CATALOG(0),
+ /**
+ * 菜单
+ */
+ MENU(1),
+ /**
+ * 按钮
+ */
+ BUTTON(2);
+
+ private int value;
+
+ MenuType(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ /**
+ * 定时任务状态
+ *
+ * @author chenshun
+ * @email sunlightcs@gmail.com
+ * @date 2016年12月3日 上午12:07:22
+ */
+ public enum ScheduleStatus {
+ /**
+ * 正常
+ */
+ NORMAL(0),
+ /**
+ * 暂停
+ */
+ PAUSE(1);
+
+ private int value;
+
+ ScheduleStatus(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ /**
+ * 云服务商
+ */
+ public enum CloudService {
+ /**
+ * 七牛云
+ */
+ QINIU(1, QiniuGroup.class),
+ /**
+ * 阿里云
+ */
+ ALIYUN(2, AliyunGroup.class),
+ /**
+ * 腾讯云
+ */
+ QCLOUD(3, QcloudGroup.class);
+
+ private int value;
+
+ private Class> validatorGroupClass;
+
+ CloudService(int value, Class> validatorGroupClass) {
+ this.value = value;
+ this.validatorGroupClass = validatorGroupClass;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public Class> getValidatorGroupClass() {
+ return this.validatorGroupClass;
+ }
+
+ public static CloudService getByValue(Integer value) {
+ Optional first = Stream.of(CloudService.values()).filter(cs -> value.equals(cs.value)).findFirst();
+ if (!first.isPresent()) {
+ throw new IllegalArgumentException("非法的枚举值:" + value);
+ }
+ return first.get();
+ }
+ }
+
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/utils/PageUtils.java b/mall-common/src/main/java/com/bookstore/common/utils/PageUtils.java
new file mode 100644
index 0000000..6735643
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/utils/PageUtils.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.utils;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 分页工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class PageUtils implements Serializable {
+ private static final long serialVersionUID = 1L;
+ /**
+ * 总记录数
+ */
+ private int totalCount;
+ /**
+ * 每页记录数
+ */
+ private int pageSize;
+ /**
+ * 总页数
+ */
+ private int totalPage;
+ /**
+ * 当前页数
+ */
+ private int currPage;
+ /**
+ * 列表数据
+ */
+ private List> list;
+
+ /**
+ * 分页
+ * @param list 列表数据
+ * @param totalCount 总记录数
+ * @param pageSize 每页记录数
+ * @param currPage 当前页数
+ */
+ public PageUtils(List> list, int totalCount, int pageSize, int currPage) {
+ this.list = list;
+ this.totalCount = totalCount;
+ this.pageSize = pageSize;
+ this.currPage = currPage;
+ this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
+ }
+
+ /**
+ * 分页
+ */
+ public PageUtils(IPage> page) {
+ this.list = page.getRecords();
+ this.totalCount = (int)page.getTotal();
+ this.pageSize = (int)page.getSize();
+ this.currPage = (int)page.getCurrent();
+ this.totalPage = (int)page.getPages();
+ }
+
+ public int getTotalCount() {
+ return totalCount;
+ }
+
+ public void setTotalCount(int totalCount) {
+ this.totalCount = totalCount;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ public int getTotalPage() {
+ return totalPage;
+ }
+
+ public void setTotalPage(int totalPage) {
+ this.totalPage = totalPage;
+ }
+
+ public int getCurrPage() {
+ return currPage;
+ }
+
+ public void setCurrPage(int currPage) {
+ this.currPage = currPage;
+ }
+
+ public List> getList() {
+ return list;
+ }
+
+ public void setList(List> list) {
+ this.list = list;
+ }
+
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/utils/Query.java b/mall-common/src/main/java/com/bookstore/common/utils/Query.java
new file mode 100644
index 0000000..23b1a64
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/utils/Query.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.utils;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.bookstore.common.xss.SQLFilter;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Map;
+
+/**
+ * 查询参数
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class Query {
+
+ public IPage getPage(Map params) {
+ return this.getPage(params, null, false);
+ }
+
+ public IPage getPage(Map params, String defaultOrderField, boolean isAsc) {
+ //分页参数
+ long curPage = 1;
+ long limit = 10;
+
+ if(params.get(Constant.PAGE) != null){
+ curPage = Long.parseLong((String)params.get(Constant.PAGE));
+ }
+ if(params.get(Constant.LIMIT) != null){
+ limit = Long.parseLong((String)params.get(Constant.LIMIT));
+ }
+
+ //分页对象
+ Page page = new Page<>(curPage, limit);
+
+ //分页参数
+ params.put(Constant.PAGE, page);
+
+ //排序字段
+ //防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
+ String orderField = SQLFilter.sqlInject((String)params.get(Constant.ORDER_FIELD));
+ String order = (String)params.get(Constant.ORDER);
+
+
+ //前端字段排序
+ if(StringUtils.isNotEmpty(orderField) && StringUtils.isNotEmpty(order)){
+ if(Constant.ASC.equalsIgnoreCase(order)) {
+ return page.addOrder(OrderItem.asc(orderField));
+ }else {
+ return page.addOrder(OrderItem.desc(orderField));
+ }
+ }
+
+ //没有排序字段,则不排序
+ if(StringUtils.isBlank(defaultOrderField)){
+ return page;
+ }
+
+ //默认排序
+ if(isAsc) {
+ page.addOrder(OrderItem.asc(defaultOrderField));
+ }else {
+ page.addOrder(OrderItem.desc(defaultOrderField));
+ }
+
+ return page;
+ }
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/utils/R.java b/mall-common/src/main/java/com/bookstore/common/utils/R.java
new file mode 100644
index 0000000..db45256
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/utils/R.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.utils;
+
+import org.apache.http.HttpStatus;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 返回数据
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class R extends HashMap {
+ private static final long serialVersionUID = 1L;
+
+ public R() {
+ put("code", 0);
+ put("msg", "success");
+ }
+
+ public static R error() {
+ return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员");
+ }
+
+ public static R error(String msg) {
+ return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
+ }
+
+ public static R error(int code, String msg) {
+ R r = new R();
+ r.put("code", code);
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static R ok(String msg) {
+ R r = new R();
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static R ok(Map map) {
+ R r = new R();
+ r.putAll(map);
+ return r;
+ }
+
+ public static R ok() {
+ return new R();
+ }
+
+ public R put(String key, Object value) {
+ super.put(key, value);
+ return this;
+ }
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/utils/RRException.java b/mall-common/src/main/java/com/bookstore/common/utils/RRException.java
new file mode 100644
index 0000000..ebc7dd5
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/utils/RRException.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.utils;
+
+/**
+ * 自定义异常
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class RRException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ private String msg;
+ private int code = 500;
+
+ public RRException(String msg) {
+ super(msg);
+ this.msg = msg;
+ }
+
+ public RRException(String msg, Throwable e) {
+ super(msg, e);
+ this.msg = msg;
+ }
+
+ public RRException(String msg, int code) {
+ super(msg);
+ this.msg = msg;
+ this.code = code;
+ }
+
+ public RRException(String msg, int code, Throwable e) {
+ super(msg, e);
+ this.msg = msg;
+ this.code = code;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/validator/group/AddGroup.java b/mall-common/src/main/java/com/bookstore/common/validator/group/AddGroup.java
new file mode 100644
index 0000000..ca7fecf
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/validator/group/AddGroup.java
@@ -0,0 +1,17 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.validator.group;
+
+/**
+ * 新增数据 Group
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public interface AddGroup {
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/validator/group/AliyunGroup.java b/mall-common/src/main/java/com/bookstore/common/validator/group/AliyunGroup.java
new file mode 100644
index 0000000..ef97821
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/validator/group/AliyunGroup.java
@@ -0,0 +1,17 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.validator.group;
+
+/**
+ * 阿里云
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public interface AliyunGroup {
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/validator/group/Group.java b/mall-common/src/main/java/com/bookstore/common/validator/group/Group.java
new file mode 100644
index 0000000..6c96bee
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/validator/group/Group.java
@@ -0,0 +1,21 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.validator.group;
+
+import javax.validation.GroupSequence;
+
+/**
+ * 定义校验顺序,如果AddGroup组失败,则UpdateGroup组不会再校验
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+@GroupSequence({AddGroup.class, UpdateGroup.class})
+public interface Group {
+
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/validator/group/QcloudGroup.java b/mall-common/src/main/java/com/bookstore/common/validator/group/QcloudGroup.java
new file mode 100644
index 0000000..ac9d797
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/validator/group/QcloudGroup.java
@@ -0,0 +1,17 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.validator.group;
+
+/**
+ * 腾讯云
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public interface QcloudGroup {
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/validator/group/QiniuGroup.java b/mall-common/src/main/java/com/bookstore/common/validator/group/QiniuGroup.java
new file mode 100644
index 0000000..fafba2f
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/validator/group/QiniuGroup.java
@@ -0,0 +1,17 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.validator.group;
+
+/**
+ * 七牛
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public interface QiniuGroup {
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/validator/group/UpdateGroup.java b/mall-common/src/main/java/com/bookstore/common/validator/group/UpdateGroup.java
new file mode 100644
index 0000000..6a3b3da
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/validator/group/UpdateGroup.java
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.validator.group;
+
+/**
+ * 更新数据 Group
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+
+public interface UpdateGroup {
+
+}
diff --git a/mall-common/src/main/java/com/bookstore/common/xss/HTMLFilter.java b/mall-common/src/main/java/com/bookstore/common/xss/HTMLFilter.java
new file mode 100644
index 0000000..99a1272
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/xss/HTMLFilter.java
@@ -0,0 +1,530 @@
+package com.bookstore.common.xss;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ *
+ * HTML filtering utility for protecting against XSS (Cross Site Scripting).
+ *
+ * This code is licensed LGPLv3
+ *
+ * This code is a Java port of the original work in PHP by Cal Hendersen.
+ * http://code.iamcal.com/php/lib_filter/
+ *
+ * The trickiest part of the translation was handling the differences in regex handling
+ * between PHP and Java. These resources were helpful in the process:
+ *
+ * http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
+ * http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php
+ * http://www.regular-expressions.info/modifiers.html
+ *
+ * A note on naming conventions: instance variables are prefixed with a "v"; global
+ * constants are in all caps.
+ *
+ * Sample use:
+ * String input = ...
+ * String clean = new HTMLFilter().filter( input );
+ *
+ * The class is not thread safe. Create a new instance if in doubt.
+ *
+ * If you find bugs or have suggestions on improvement (especially regarding
+ * performance), please contact us. The latest version of this
+ * source, and our contact details, can be found at http://xss-html-filter.sf.net
+ *
+ * @author Joseph O'Connell
+ * @author Cal Hendersen
+ * @author Michael Semb Wever
+ */
+public final class HTMLFilter {
+
+ /** regex flag union representing /si modifiers in php **/
+ private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;
+ private static final Pattern P_COMMENTS = Pattern.compile("", Pattern.DOTALL);
+ private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI);
+ private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL);
+ private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI);
+ private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI);
+ private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI);
+ private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI);
+ private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI);
+ private static final Pattern P_ENTITY = Pattern.compile("(\\d+);?");
+ private static final Pattern P_ENTITY_UNICODE = Pattern.compile("([0-9a-f]+);?");
+ private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?");
+ private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))");
+ private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL);
+ private static final Pattern P_END_ARROW = Pattern.compile("^>");
+ private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)");
+ private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)");
+ private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)");
+ private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)");
+ private static final Pattern P_AMP = Pattern.compile("&");
+ private static final Pattern P_QUOTE = Pattern.compile("<");
+ private static final Pattern P_LEFT_ARROW = Pattern.compile("<");
+ private static final Pattern P_RIGHT_ARROW = Pattern.compile(">");
+ private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>");
+
+ // @xxx could grow large... maybe use sesat's ReferenceMap
+ private static final ConcurrentMap P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap();
+ private static final ConcurrentMap P_REMOVE_SELF_BLANKS = new ConcurrentHashMap();
+
+ /** set of allowed html elements, along with allowed attributes for each element **/
+ private final Map> vAllowed;
+ /** counts of open tags for each (allowable) html element **/
+ private final Map vTagCounts = new HashMap();
+
+ /** html elements which must always be self-closing (e.g. "
") **/
+ private final String[] vSelfClosingTags;
+ /** html elements which must always have separate opening and closing tags (e.g. "") **/
+ private final String[] vNeedClosingTags;
+ /** set of disallowed html elements **/
+ private final String[] vDisallowed;
+ /** attributes which should be checked for valid protocols **/
+ private final String[] vProtocolAtts;
+ /** allowed protocols **/
+ private final String[] vAllowedProtocols;
+ /** tags which should be removed if they contain no content (e.g. "" or "") **/
+ private final String[] vRemoveBlanks;
+ /** entities allowed within html markup **/
+ private final String[] vAllowedEntities;
+ /** flag determining whether comments are allowed in input String. */
+ private final boolean stripComment;
+ private final boolean encodeQuotes;
+ private boolean vDebug = false;
+ /**
+ * flag determining whether to try to make tags when presented with "unbalanced"
+ * angle brackets (e.g. "" becomes " text "). If set to false,
+ * unbalanced angle brackets will be html escaped.
+ */
+ private final boolean alwaysMakeTags;
+
+ /** Default constructor.
+ *
+ */
+ public HTMLFilter() {
+ vAllowed = new HashMap<>();
+
+ final ArrayList a_atts = new ArrayList();
+ a_atts.add("href");
+ a_atts.add("target");
+ vAllowed.put("a", a_atts);
+
+ final ArrayList img_atts = new ArrayList();
+ img_atts.add("src");
+ img_atts.add("width");
+ img_atts.add("height");
+ img_atts.add("alt");
+ vAllowed.put("img", img_atts);
+
+ final ArrayList no_atts = new ArrayList();
+ vAllowed.put("b", no_atts);
+ vAllowed.put("strong", no_atts);
+ vAllowed.put("i", no_atts);
+ vAllowed.put("em", no_atts);
+
+ vSelfClosingTags = new String[]{"img"};
+ vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"};
+ vDisallowed = new String[]{};
+ vAllowedProtocols = new String[]{"http", "mailto", "https"}; // no ftp.
+ vProtocolAtts = new String[]{"src", "href"};
+ vRemoveBlanks = new String[]{"a", "b", "strong", "i", "em"};
+ vAllowedEntities = new String[]{"amp", "gt", "lt", "quot"};
+ stripComment = true;
+ encodeQuotes = true;
+ alwaysMakeTags = true;
+ }
+
+ /** Set debug flag to true. Otherwise use default settings. See the default constructor.
+ *
+ * @param debug turn debug on with a true argument
+ */
+ public HTMLFilter(final boolean debug) {
+ this();
+ vDebug = debug;
+
+ }
+
+ /** Map-parameter configurable constructor.
+ *
+ * @param conf map containing configuration. keys match field names.
+ */
+ public HTMLFilter(final Map conf) {
+
+ assert conf.containsKey("vAllowed") : "configuration requires vAllowed";
+ assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags";
+ assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags";
+ assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed";
+ assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols";
+ assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts";
+ assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks";
+ assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities";
+
+ vAllowed = Collections.unmodifiableMap((HashMap>) conf.get("vAllowed"));
+ vSelfClosingTags = (String[]) conf.get("vSelfClosingTags");
+ vNeedClosingTags = (String[]) conf.get("vNeedClosingTags");
+ vDisallowed = (String[]) conf.get("vDisallowed");
+ vAllowedProtocols = (String[]) conf.get("vAllowedProtocols");
+ vProtocolAtts = (String[]) conf.get("vProtocolAtts");
+ vRemoveBlanks = (String[]) conf.get("vRemoveBlanks");
+ vAllowedEntities = (String[]) conf.get("vAllowedEntities");
+ stripComment = conf.containsKey("stripComment") ? (Boolean) conf.get("stripComment") : true;
+ encodeQuotes = conf.containsKey("encodeQuotes") ? (Boolean) conf.get("encodeQuotes") : true;
+ alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true;
+ }
+
+ private void reset() {
+ vTagCounts.clear();
+ }
+
+ private void debug(final String msg) {
+ if (vDebug) {
+ Logger.getAnonymousLogger().info(msg);
+ }
+ }
+
+ //---------------------------------------------------------------
+ // my versions of some PHP library functions
+ public static String chr(final int decimal) {
+ return String.valueOf((char) decimal);
+ }
+
+ public static String htmlSpecialChars(final String s) {
+ String result = s;
+ result = regexReplace(P_AMP, "&", result);
+ result = regexReplace(P_QUOTE, """, result);
+ result = regexReplace(P_LEFT_ARROW, "<", result);
+ result = regexReplace(P_RIGHT_ARROW, ">", result);
+ return result;
+ }
+
+ //---------------------------------------------------------------
+ /**
+ * given a user submitted input String, filter out any invalid or restricted
+ * html.
+ *
+ * @param input text (i.e. submitted by a user) than may contain html
+ * @return "clean" version of input, with only valid, whitelisted html elements allowed
+ */
+ public String filter(final String input) {
+ reset();
+ String s = input;
+
+ debug("************************************************");
+ debug(" INPUT: " + input);
+
+ s = escapeComments(s);
+ debug(" escapeComments: " + s);
+
+ s = balanceHTML(s);
+ debug(" balanceHTML: " + s);
+
+ s = checkTags(s);
+ debug(" checkTags: " + s);
+
+ s = processRemoveBlanks(s);
+ debug("processRemoveBlanks: " + s);
+
+ s = validateEntities(s);
+ debug(" validateEntites: " + s);
+
+ debug("************************************************\n\n");
+ return s;
+ }
+
+ public boolean isAlwaysMakeTags(){
+ return alwaysMakeTags;
+ }
+
+ public boolean isStripComments(){
+ return stripComment;
+ }
+
+ private String escapeComments(final String s) {
+ final Matcher m = P_COMMENTS.matcher(s);
+ final StringBuffer buf = new StringBuffer();
+ if (m.find()) {
+ final String match = m.group(1); //(.*?)
+ m.appendReplacement(buf, Matcher.quoteReplacement(""));
+ }
+ m.appendTail(buf);
+
+ return buf.toString();
+ }
+
+ private String balanceHTML(String s) {
+ if (alwaysMakeTags) {
+ //
+ // try and form html
+ //
+ s = regexReplace(P_END_ARROW, "", s);
+ s = regexReplace(P_BODY_TO_END, "<$1>", s);
+ s = regexReplace(P_XML_CONTENT, "$1<$2", s);
+
+ } else {
+ //
+ // escape stray brackets
+ //
+ s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s);
+ s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s);
+
+ //
+ // the last regexp causes '<>' entities to appear
+ // (we need to do a lookahead assertion so that the last bracket can
+ // be used in the next pass of the regexp)
+ //
+ s = regexReplace(P_BOTH_ARROWS, "", s);
+ }
+
+ return s;
+ }
+
+ private String checkTags(String s) {
+ Matcher m = P_TAGS.matcher(s);
+
+ final StringBuffer buf = new StringBuffer();
+ while (m.find()) {
+ String replaceStr = m.group(1);
+ replaceStr = processTag(replaceStr);
+ m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr));
+ }
+ m.appendTail(buf);
+
+ s = buf.toString();
+
+ // these get tallied in processTag
+ // (remember to reset before subsequent calls to filter method)
+ for (String key : vTagCounts.keySet()) {
+ for (int ii = 0; ii < vTagCounts.get(key); ii++) {
+ s += "" + key + ">";
+ }
+ }
+
+ return s;
+ }
+
+ private String processRemoveBlanks(final String s) {
+ String result = s;
+ for (String tag : vRemoveBlanks) {
+ if(!P_REMOVE_PAIR_BLANKS.containsKey(tag)){
+ P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?>" + tag + ">"));
+ }
+ result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result);
+ if(!P_REMOVE_SELF_BLANKS.containsKey(tag)){
+ P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>"));
+ }
+ result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result);
+ }
+
+ return result;
+ }
+
+ private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) {
+ Matcher m = regex_pattern.matcher(s);
+ return m.replaceAll(replacement);
+ }
+
+ private String processTag(final String s) {
+ // ending tags
+ Matcher m = P_END_TAG.matcher(s);
+ if (m.find()) {
+ final String name = m.group(1).toLowerCase();
+ if (allowed(name)) {
+ if (!inArray(name, vSelfClosingTags)) {
+ if (vTagCounts.containsKey(name)) {
+ vTagCounts.put(name, vTagCounts.get(name) - 1);
+ return "" + name + ">";
+ }
+ }
+ }
+ }
+
+ // starting tags
+ m = P_START_TAG.matcher(s);
+ if (m.find()) {
+ final String name = m.group(1).toLowerCase();
+ final String body = m.group(2);
+ String ending = m.group(3);
+
+ //debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
+ if (allowed(name)) {
+ String params = "";
+
+ final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body);
+ final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body);
+ final List paramNames = new ArrayList();
+ final List paramValues = new ArrayList();
+ while (m2.find()) {
+ paramNames.add(m2.group(1)); //([a-z0-9]+)
+ paramValues.add(m2.group(3)); //(.*?)
+ }
+ while (m3.find()) {
+ paramNames.add(m3.group(1)); //([a-z0-9]+)
+ paramValues.add(m3.group(3)); //([^\"\\s']+)
+ }
+
+ String paramName, paramValue;
+ for (int ii = 0; ii < paramNames.size(); ii++) {
+ paramName = paramNames.get(ii).toLowerCase();
+ paramValue = paramValues.get(ii);
+
+// debug( "paramName='" + paramName + "'" );
+// debug( "paramValue='" + paramValue + "'" );
+// debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
+
+ if (allowedAttribute(name, paramName)) {
+ if (inArray(paramName, vProtocolAtts)) {
+ paramValue = processParamProtocol(paramValue);
+ }
+ params += " " + paramName + "=\"" + paramValue + "\"";
+ }
+ }
+
+ if (inArray(name, vSelfClosingTags)) {
+ ending = " /";
+ }
+
+ if (inArray(name, vNeedClosingTags)) {
+ ending = "";
+ }
+
+ if (ending == null || ending.length() < 1) {
+ if (vTagCounts.containsKey(name)) {
+ vTagCounts.put(name, vTagCounts.get(name) + 1);
+ } else {
+ vTagCounts.put(name, 1);
+ }
+ } else {
+ ending = " /";
+ }
+ return "<" + name + params + ending + ">";
+ } else {
+ return "";
+ }
+ }
+
+ // comments
+ m = P_COMMENT.matcher(s);
+ if (!stripComment && m.find()) {
+ return "<" + m.group() + ">";
+ }
+
+ return "";
+ }
+
+ private String processParamProtocol(String s) {
+ s = decodeEntities(s);
+ final Matcher m = P_PROTOCOL.matcher(s);
+ if (m.find()) {
+ final String protocol = m.group(1);
+ if (!inArray(protocol, vAllowedProtocols)) {
+ // bad protocol, turn into local anchor link instead
+ s = "#" + s.substring(protocol.length() + 1, s.length());
+ if (s.startsWith("#//")) {
+ s = "#" + s.substring(3, s.length());
+ }
+ }
+ }
+
+ return s;
+ }
+
+ private String decodeEntities(String s) {
+ StringBuffer buf = new StringBuffer();
+
+ Matcher m = P_ENTITY.matcher(s);
+ while (m.find()) {
+ final String match = m.group(1);
+ final int decimal = Integer.decode(match).intValue();
+ m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
+ }
+ m.appendTail(buf);
+ s = buf.toString();
+
+ buf = new StringBuffer();
+ m = P_ENTITY_UNICODE.matcher(s);
+ while (m.find()) {
+ final String match = m.group(1);
+ final int decimal = Integer.valueOf(match, 16).intValue();
+ m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
+ }
+ m.appendTail(buf);
+ s = buf.toString();
+
+ buf = new StringBuffer();
+ m = P_ENCODE.matcher(s);
+ while (m.find()) {
+ final String match = m.group(1);
+ final int decimal = Integer.valueOf(match, 16).intValue();
+ m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
+ }
+ m.appendTail(buf);
+ s = buf.toString();
+
+ s = validateEntities(s);
+ return s;
+ }
+
+ private String validateEntities(final String s) {
+ StringBuffer buf = new StringBuffer();
+
+ // validate entities throughout the string
+ Matcher m = P_VALID_ENTITIES.matcher(s);
+ while (m.find()) {
+ final String one = m.group(1); //([^&;]*)
+ final String two = m.group(2); //(?=(;|&|$))
+ m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two)));
+ }
+ m.appendTail(buf);
+
+ return encodeQuotes(buf.toString());
+ }
+
+ private String encodeQuotes(final String s){
+ if(encodeQuotes){
+ StringBuffer buf = new StringBuffer();
+ Matcher m = P_VALID_QUOTES.matcher(s);
+ while (m.find()) {
+ final String one = m.group(1); //(>|^)
+ final String two = m.group(2); //([^<]+?)
+ final String three = m.group(3); //(<|$)
+ m.appendReplacement(buf, Matcher.quoteReplacement(one + regexReplace(P_QUOTE, """, two) + three));
+ }
+ m.appendTail(buf);
+ return buf.toString();
+ }else{
+ return s;
+ }
+ }
+
+ private String checkEntity(final String preamble, final String term) {
+
+ return ";".equals(term) && isValidEntity(preamble)
+ ? '&' + preamble
+ : "&" + preamble;
+ }
+
+ private boolean isValidEntity(final String entity) {
+ return inArray(entity, vAllowedEntities);
+ }
+
+ private static boolean inArray(final String s, final String[] array) {
+ for (String item : array) {
+ if (item != null && item.equals(s)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean allowed(final String name) {
+ return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed);
+ }
+
+ private boolean allowedAttribute(final String name, final String paramName) {
+ return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName));
+ }
+}
\ No newline at end of file
diff --git a/mall-common/src/main/java/com/bookstore/common/xss/SQLFilter.java b/mall-common/src/main/java/com/bookstore/common/xss/SQLFilter.java
new file mode 100644
index 0000000..83cd6af
--- /dev/null
+++ b/mall-common/src/main/java/com/bookstore/common/xss/SQLFilter.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.bookstore.common.xss;
+
+
+
+import com.bookstore.common.utils.RRException;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * SQL过滤
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class SQLFilter {
+
+ /**
+ * SQL注入过滤
+ * @param str 待验证的字符串
+ */
+ public static String sqlInject(String str){
+ if(StringUtils.isBlank(str)){
+ return null;
+ }
+ //去掉'|"|;|\字符
+ str = StringUtils.replace(str, "'", "");
+ str = StringUtils.replace(str, "\"", "");
+ str = StringUtils.replace(str, ";", "");
+ str = StringUtils.replace(str, "\\", "");
+
+ //转换成小写
+ str = str.toLowerCase();
+
+ //非法字符
+ String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"};
+
+ //判断是否包含非法字符
+ for(String keyword : keywords){
+ if(str.indexOf(keyword) != -1){
+ throw new RRException("包含非法字符");
+ }
+ }
+
+ return str;
+ }
+}
diff --git a/renren-generator/src/main/resources/application.yml b/renren-generator/src/main/resources/application.yml
index 15392d7..ae65a0a 100644
--- a/renren-generator/src/main/resources/application.yml
+++ b/renren-generator/src/main/resources/application.yml
@@ -7,7 +7,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
#MySQL配置
driverClassName: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://192.168.88.131:3306/mall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://192.168.88.131:3306/mall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 7536981
#oracle配置
diff --git a/renren-generator/src/main/resources/generator.properties b/renren-generator/src/main/resources/generator.properties
index e86f25c..0543eab 100644
--- a/renren-generator/src/main/resources/generator.properties
+++ b/renren-generator/src/main/resources/generator.properties
@@ -3,13 +3,13 @@
mainPath=com.bookstore
#\u5305\u540D
package=com.bookstore.bookmall
-moduleName=product
+moduleName=coupon
#\u4F5C\u8005
author=dy
#Email
email=2073699128@qq.com
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00)
-tablePrefix=pms_
+tablePrefix=sms_
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
tinyint=Integer
diff --git a/renren-generator/src/main/resources/template/Controller.java.vm b/renren-generator/src/main/resources/template/Controller.java.vm
index 2387ca6..3acd259 100644
--- a/renren-generator/src/main/resources/template/Controller.java.vm
+++ b/renren-generator/src/main/resources/template/Controller.java.vm
@@ -3,7 +3,7 @@ package ${package}.${moduleName}.controller;
import java.util.Arrays;
import java.util.Map;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@@ -35,7 +35,7 @@ public class ${className}Controller {
* 列表
*/
@RequestMapping("/list")
- @RequiresPermissions("${moduleName}:${pathName}:list")
+ //@RequiresPermissions("${moduleName}:${pathName}:list")
public R list(@RequestParam Map params){
PageUtils page = ${classname}Service.queryPage(params);
@@ -47,7 +47,7 @@ public class ${className}Controller {
* 信息
*/
@RequestMapping("/info/{${pk.attrname}}")
- @RequiresPermissions("${moduleName}:${pathName}:info")
+ //@RequiresPermissions("${moduleName}:${pathName}:info")
public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
${className}Entity ${classname} = ${classname}Service.getById(${pk.attrname});
@@ -58,7 +58,7 @@ public class ${className}Controller {
* 保存
*/
@RequestMapping("/save")
- @RequiresPermissions("${moduleName}:${pathName}:save")
+ //@RequiresPermissions("${moduleName}:${pathName}:save")
public R save(@RequestBody ${className}Entity ${classname}){
${classname}Service.save(${classname});
@@ -69,7 +69,7 @@ public class ${className}Controller {
* 修改
*/
@RequestMapping("/update")
- @RequiresPermissions("${moduleName}:${pathName}:update")
+ //@RequiresPermissions("${moduleName}:${pathName}:update")
public R update(@RequestBody ${className}Entity ${classname}){
${classname}Service.updateById(${classname});
@@ -80,7 +80,7 @@ public class ${className}Controller {
* 删除
*/
@RequestMapping("/delete")
- @RequiresPermissions("${moduleName}:${pathName}:delete")
+ //@RequiresPermissions("${moduleName}:${pathName}:delete")
public R delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){
${classname}Service.removeByIds(Arrays.asList(${pk.attrname}s));