💖🔥作者主页:计算机毕业设计老哥🔥 💖
有问题可以主页问我
一、开发介绍
1.1 开发环境
- 开发语言:Java
- 数据库:MySQL
- 系统架构:B/S
- 后端:SpringBoot(Spring+SpringMVC+Mybatis)
- 前端:Vue
- 工具:IDEA或者Eclipse,JDK1.8,Maven
二、系统介绍
2.1图片展示
注册登录页面:
前端页面功能:首页、小说信息、交流论坛、公告资讯、个人中心、后台管理
管理员后台页面:
功能:首页、个人中心、会员管理、小说分类管理、小说信息管理、小说评分管理、交流论坛、系统管理
三、部分代码设计
3.1.Mybatis-Plus工具类-部分代码如下:
/**
* Mybatis-Plus工具类
*/
public class MPUtil {
public static final char UNDERLINE = '_';
//mybatis plus allEQ 表达式转换
public static Map allEQMapPre(Object bean,String pre) {
Map<String, Object> map =BeanUtil.beanToMap(bean);
return camelToUnderlineMap(map,pre);
}
//mybatis plus allEQ 表达式转换
public static Map allEQMap(Object bean) {
Map<String, Object> map =BeanUtil.beanToMap(bean);
return camelToUnderlineMap(map,"");
}
public static Wrapper allLikePre(Wrapper wrapper,Object bean,String pre) {
Map<String, Object> map =BeanUtil.beanToMap(bean);
Map result = camelToUnderlineMap(map,pre);
return genLike(wrapper,result);
}
public static Wrapper allLike(Wrapper wrapper,Object bean) {
Map result = BeanUtil.beanToMap(bean, true, true);
return genLike(wrapper,result);
}
public static Wrapper genLike( Wrapper wrapper,Map param) {
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
int i=0;
while (it.hasNext()) {
if(i>0) wrapper.and();
Map.Entry<String, Object> entry = it.next();
String key = entry.getKey();
String value = (String) entry.getValue();
wrapper.like(key, value);
i++;
}
return wrapper;
}
public static Wrapper likeOrEq(Wrapper wrapper,Object bean) {
Map result = BeanUtil.beanToMap(bean, true, true);
return genLikeOrEq(wrapper,result);
}
public static Wrapper genLikeOrEq( Wrapper wrapper,Map param) {
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
int i=0;
while (it.hasNext()) {
if(i>0) wrapper.and();
Map.Entry<String, Object> entry = it.next();
String key = entry.getKey();
if(entry.getValue().toString().contains("%")) {
wrapper.like(key, entry.getValue().toString().replace("%", ""));
} else {
wrapper.eq(key, entry.getValue());
}
i++;
}
return wrapper;
}
public static Wrapper allEq(Wrapper wrapper,Object bean) {
Map result = BeanUtil.beanToMap(bean, true, true);
return genEq(wrapper,result);
}
public static Wrapper genEq( Wrapper wrapper,Map param) {
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
int i=0;
while (it.hasNext()) {
if(i>0) wrapper.and();
Map.Entry<String, Object> entry = it.next();
String key = entry.getKey();
wrapper.eq(key, entry.getValue());
i++;
}
return wrapper;
}
public static Wrapper between(Wrapper wrapper,Map<String, Object> params) {
for(String key : params.keySet()) {
String columnName = "";
if(key.endsWith("_start")) {
columnName = key.substring(0, key.indexOf("_start"));
if(StringUtils.isNotBlank(params.get(key).toString())) {
wrapper.ge(columnName, params.get(key));
}
}
if(key.endsWith("_end")) {
columnName = key.substring(0, key.indexOf("_end"));
if(StringUtils.isNotBlank(params.get(key).toString())) {
wrapper.le(columnName, params.get(key));
}
}
}
return wrapper;
}
public static Wrapper sort(Wrapper wrapper,Map<String, Object> params) {
String order = "";
if(params.get("order") != null && StringUtils.isNotBlank(params.get("order").toString())) {
order = params.get("order").toString();
}
if(params.get("sort") != null && StringUtils.isNotBlank(params.get("sort").toString())) {
if(order.equalsIgnoreCase("desc")) {
wrapper.orderDesc(Arrays.asList(params.get("sort")));
} else {
wrapper.orderAsc(Arrays.asList(params.get("sort")));
}
}
return wrapper;
}
/**
* 驼峰格式字符串转换为下划线格式字符串
*
* @param param
* @return
*/
public static String camelToUnderline(String param) {
if (param == null || "".equals(param.trim())) {
return "";
}
int len = param.length();
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = param.charAt(i);
if (Character.isUpperCase(c)) {
sb.append(UNDERLINE);
sb.append(Character.toLowerCase(c));
} else {
sb.append(c);
}
}
return sb.toString();
}
public static void main(String[] ages) {
System.out.println(camelToUnderline("ABCddfANM"));
}
public static Map camelToUnderlineMap(Map param, String pre) {
Map<String, Object> newMap = new HashMap<String, Object>();
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> entry = it.next();
String key = entry.getKey();
String newKey = camelToUnderline(key);
if (pre.endsWith(".")) {
newMap.put(pre + newKey, entry.getValue());
} else if (StringUtils.isEmpty(pre)) {
newMap.put(newKey, entry.getValue());
} else {
newMap.put(pre + "." + newKey, entry.getValue());
}
}
return newMap;
}
}
3.2.校验工具类-部分代码如下:
/**
* hibernate-validator校验工具类
*/
public class ValidatorUtils {
private static Validator validator;
static {
validator = Validation.buildDefaultValidatorFactory().getValidator();
}
/**
* 校验对象
* @param object 待校验对象
* @param groups 待校验的组
* @throws EIException 校验不通过,则报EIException异常
*/
public static void validateEntity(Object object, Class<?>... groups)
throws EIException {
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
if (!constraintViolations.isEmpty()) {
ConstraintViolation<Object> constraint = (ConstraintViolation<Object>)constraintViolations.iterator().next();
throw new EIException(constraint.getMessage());
}
}
}
3.3.查询参数工具类-部分代码如下:
/**
* 查询参数
*/
public class Query<T> extends LinkedHashMap<String, Object> {
private static final long serialVersionUID = 1L;
/**
* mybatis-plus分页参数
*/
private Page<T> page;
/**
* 当前页码
*/
private int currPage = 1;
/**
* 每页条数
*/
private int limit = 10;
public Query(JQPageInfo pageInfo) {
//分页参数
if(pageInfo.getPage()!= null){
currPage = pageInfo.getPage();
}
if(pageInfo.getLimit()!= null){
limit = pageInfo.getLimit();
}
//防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
String sidx = SQLFilter.sqlInject(pageInfo.getSidx());
String order = SQLFilter.sqlInject(pageInfo.getOrder());
//mybatis-plus分页
this.page = new Page<>(currPage, limit);
//排序
if(StringUtils.isNotBlank(sidx) && StringUtils.isNotBlank(order)){
this.page.setOrderByField(sidx);
this.page.setAsc("ASC".equalsIgnoreCase(order));
}
}
public Query(Map<String, Object> params){
this.putAll(params);
//分页参数
if(params.get("page") != null){
currPage = Integer.parseInt((String)params.get("page"));
}
if(params.get("limit") != null){
limit = Integer.parseInt((String)params.get("limit"));
}
this.put("offset", (currPage - 1) * limit);
this.put("page", currPage);
this.put("limit", limit);
//防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
String sidx = SQLFilter.sqlInject((String)params.get("sidx"));
String order = SQLFilter.sqlInject((String)params.get("order"));
this.put("sidx", sidx);
this.put("order", order);
//mybatis-plus分页
this.page = new Page<>(currPage, limit);
//排序
if(StringUtils.isNotBlank(sidx) && StringUtils.isNotBlank(order)){
this.page.setOrderByField(sidx);
this.page.setAsc("ASC".equalsIgnoreCase(order));
}
}
public Page<T> getPage() {
return page;
}
public int getCurrPage() {
return currPage;
}
public int getLimit() {
return limit;
}
}
总结
大家可以帮忙点赞、收藏、关注、评论啦
有问题可以在评论区交流,或者下方主页联系问我
💖🔥作者主页:计算机毕业设计老哥🔥 💖