若依开源1.1.3发布
This commit is contained in:
@ -87,7 +87,7 @@ public class LogAspect
|
||||
// 请求的地址
|
||||
String ip = ShiroUtils.getIp();
|
||||
operLog.setOperIp(ip);
|
||||
operLog.setOperUrl(ServletUtils.getHttpServletRequest().getRequestURI());
|
||||
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
||||
if (currentUser != null)
|
||||
{
|
||||
operLog.setLoginName(currentUser.getLoginName());
|
||||
@ -148,7 +148,7 @@ public class LogAspect
|
||||
*/
|
||||
private static void setRequestValue(OperLog operLog)
|
||||
{
|
||||
Map<String, String[]> map = ServletUtils.getHttpServletRequest().getParameterMap();
|
||||
Map<String, String[]> map = ServletUtils.getRequest().getParameterMap();
|
||||
String params = JSONObject.toJSONString(map);
|
||||
operLog.setOperParam(StringUtils.substring(params, 0, 255));
|
||||
}
|
||||
|
61
src/main/java/com/ruoyi/framework/config/CaptchaConfig.java
Normal file
61
src/main/java/com/ruoyi/framework/config/CaptchaConfig.java
Normal file
@ -0,0 +1,61 @@
|
||||
package com.ruoyi.framework.config;
|
||||
|
||||
import java.util.Properties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||
import com.google.code.kaptcha.util.Config;
|
||||
|
||||
/**
|
||||
* 验证码配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
public class CaptchaConfig
|
||||
{
|
||||
@Bean(name = "captchaProducer")
|
||||
public DefaultKaptcha getKaptchaBean()
|
||||
{
|
||||
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("kaptcha.border", "yes");
|
||||
properties.setProperty("kaptcha.border.color", "105,179,90");
|
||||
properties.setProperty("kaptcha.textproducer.font.color", "blue");
|
||||
properties.setProperty("kaptcha.image.width", "160");
|
||||
properties.setProperty("kaptcha.image.height", "60");
|
||||
properties.setProperty("kaptcha.textproducer.font.size", "28");
|
||||
properties.setProperty("kaptcha.session.key", "kaptchaCode");
|
||||
properties.setProperty("kaptcha.textproducer.char.spac", "35");
|
||||
properties.setProperty("kaptcha.textproducer.char.length", "5");
|
||||
properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier");
|
||||
properties.setProperty("kaptcha.noise.color", "white");
|
||||
Config config = new Config(properties);
|
||||
defaultKaptcha.setConfig(config);
|
||||
return defaultKaptcha;
|
||||
}
|
||||
|
||||
@Bean(name = "captchaProducerMath")
|
||||
public DefaultKaptcha getKaptchaBeanMath()
|
||||
{
|
||||
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("kaptcha.border", "yes");
|
||||
properties.setProperty("kaptcha.border.color", "105,179,90");
|
||||
properties.setProperty("kaptcha.textproducer.font.color", "blue");
|
||||
properties.setProperty("kaptcha.image.width", "160");
|
||||
properties.setProperty("kaptcha.image.height", "60");
|
||||
properties.setProperty("kaptcha.textproducer.font.size", "38");
|
||||
properties.setProperty("kaptcha.session.key", "kaptchaCodeMath");
|
||||
properties.setProperty("kaptcha.textproducer.impl", "com.ruoyi.framework.config.KaptchaTextCreator");
|
||||
properties.setProperty("kaptcha.textproducer.char.spac", "5");
|
||||
properties.setProperty("kaptcha.textproducer.char.length", "6");
|
||||
properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier");
|
||||
properties.setProperty("kaptcha.noise.color", "white");
|
||||
properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");
|
||||
properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy");
|
||||
Config config = new Config(properties);
|
||||
defaultKaptcha.setConfig(config);
|
||||
return defaultKaptcha;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.ruoyi.framework.config;
|
||||
|
||||
import java.util.Random;
|
||||
import com.google.code.kaptcha.text.impl.DefaultTextCreator;
|
||||
|
||||
/**
|
||||
* 验证码文本生成器
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class KaptchaTextCreator extends DefaultTextCreator
|
||||
{
|
||||
|
||||
private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(",");
|
||||
|
||||
@Override
|
||||
public String getText()
|
||||
{
|
||||
Integer result = 0;
|
||||
Random random = new Random();
|
||||
int x = random.nextInt(10);
|
||||
int y = random.nextInt(10);
|
||||
StringBuilder suChinese = new StringBuilder();
|
||||
int randomoperands = (int) Math.round(Math.random() * 2);
|
||||
if (randomoperands == 0)
|
||||
{
|
||||
result = x * y;
|
||||
suChinese.append(CNUMBERS[x]);
|
||||
suChinese.append("*");
|
||||
suChinese.append(CNUMBERS[y]);
|
||||
}
|
||||
else if (randomoperands == 1)
|
||||
{
|
||||
if (!(x == 0) && y % x == 0)
|
||||
{
|
||||
result = y / x;
|
||||
suChinese.append(CNUMBERS[y]);
|
||||
suChinese.append("/");
|
||||
suChinese.append(CNUMBERS[x]);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = x + y;
|
||||
suChinese.append(CNUMBERS[x]);
|
||||
suChinese.append("+");
|
||||
suChinese.append(CNUMBERS[y]);
|
||||
}
|
||||
}
|
||||
else if (randomoperands == 2)
|
||||
{
|
||||
if (x >= y)
|
||||
{
|
||||
result = x - y;
|
||||
suChinese.append(CNUMBERS[x]);
|
||||
suChinese.append("-");
|
||||
suChinese.append(CNUMBERS[y]);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = y - x;
|
||||
suChinese.append(CNUMBERS[y]);
|
||||
suChinese.append("-");
|
||||
suChinese.append(CNUMBERS[x]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = x + y;
|
||||
suChinese.append(CNUMBERS[x]);
|
||||
suChinese.append("+");
|
||||
suChinese.append(CNUMBERS[y]);
|
||||
}
|
||||
suChinese.append("=?@" + result);
|
||||
return suChinese.toString();
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package com.ruoyi.framework.config;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@ -12,7 +13,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
public class BaseConfig extends WebMvcConfigurerAdapter
|
||||
public class ResourcesConfig extends WebMvcConfigurerAdapter
|
||||
{
|
||||
|
||||
/**
|
||||
@ -31,4 +32,10 @@ public class BaseConfig extends WebMvcConfigurerAdapter
|
||||
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
super.addViewControllers(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry)
|
||||
{
|
||||
registry.addResourceHandler("/profile/**").addResourceLocations("file:" + RuoYiConfig.getProfile());
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@ public class RuoYiConfig
|
||||
private String version;
|
||||
/** 版权年份 */
|
||||
private String copyrightYear;
|
||||
/** 上传路径 */
|
||||
private static String profile;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
@ -49,4 +51,14 @@ public class RuoYiConfig
|
||||
this.copyrightYear = copyrightYear;
|
||||
}
|
||||
|
||||
public static String getProfile()
|
||||
{
|
||||
return profile;
|
||||
}
|
||||
|
||||
public static void setProfile(String profile)
|
||||
{
|
||||
RuoYiConfig.profile = profile;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,25 +2,33 @@ package com.ruoyi.framework.config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
||||
import org.apache.shiro.codec.Base64;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.CookieRememberMeManager;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.apache.shiro.web.servlet.SimpleCookie;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.ruoyi.framework.shiro.realm.UserRealm;
|
||||
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
||||
import com.ruoyi.framework.shiro.session.OnlineSessionFactory;
|
||||
import com.ruoyi.framework.shiro.web.filter.LogoutFilter;
|
||||
import com.ruoyi.framework.shiro.web.filter.captcha.CaptchaValidateFilter;
|
||||
import com.ruoyi.framework.shiro.web.filter.online.OnlineSessionFilter;
|
||||
import com.ruoyi.framework.shiro.web.filter.sync.SyncOnlineSessionFilter;
|
||||
import com.ruoyi.framework.shiro.web.session.OnlineWebSessionManager;
|
||||
import com.ruoyi.framework.shiro.web.session.SpringSessionValidationScheduler;
|
||||
|
||||
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
|
||||
|
||||
/**
|
||||
@ -41,6 +49,30 @@ public class ShiroConfig
|
||||
@Value("${shiro.session.validationInterval}")
|
||||
private int validationInterval;
|
||||
|
||||
// 验证码开关
|
||||
@Value("${shiro.user.captchaEbabled}")
|
||||
private boolean captchaEbabled;
|
||||
|
||||
// 验证码类型
|
||||
@Value("${shiro.user.captchaType}")
|
||||
private String captchaType;
|
||||
|
||||
// 设置Cookie的域名
|
||||
@Value("${shiro.cookie.domain}")
|
||||
private String domain;
|
||||
|
||||
// 设置cookie的有效访问路径
|
||||
@Value("${shiro.cookie.path}")
|
||||
private String path;
|
||||
|
||||
// 设置HttpOnly属性
|
||||
@Value("${shiro.cookie.httpOnly}")
|
||||
private boolean httpOnly;
|
||||
|
||||
// 设置Cookie的过期时间,秒为单位
|
||||
@Value("${shiro.cookie.maxAge}")
|
||||
private int maxAge;
|
||||
|
||||
// 登录地址
|
||||
@Value("${shiro.user.loginUrl}")
|
||||
private String loginUrl;
|
||||
@ -160,6 +192,8 @@ public class ShiroConfig
|
||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||
// 设置realm.
|
||||
securityManager.setRealm(userRealm);
|
||||
// 记住我
|
||||
securityManager.setRememberMeManager(rememberMeManager());
|
||||
// 注入缓存管理器;
|
||||
securityManager.setCacheManager(getEhCacheManager());
|
||||
// session管理器
|
||||
@ -199,26 +233,28 @@ public class ShiroConfig
|
||||
filterChainDefinitionMap.put("/docs/**", "anon");
|
||||
filterChainDefinitionMap.put("/fonts/**", "anon");
|
||||
filterChainDefinitionMap.put("/img/**", "anon");
|
||||
filterChainDefinitionMap.put("/js/**", "anon");
|
||||
filterChainDefinitionMap.put("/ajax/**", "anon");
|
||||
filterChainDefinitionMap.put("/js/**", "anon");
|
||||
filterChainDefinitionMap.put("/ruoyi/**", "anon");
|
||||
filterChainDefinitionMap.put("/druid/**", "anon");
|
||||
// 不需要拦截的访问
|
||||
filterChainDefinitionMap.put("/login", "anon");
|
||||
filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
|
||||
// 退出 logout地址,shiro去清除session
|
||||
filterChainDefinitionMap.put("/logout", "logout");
|
||||
// 不需要拦截的访问
|
||||
filterChainDefinitionMap.put("/login", "anon,captchaValidate");
|
||||
// 系统权限列表
|
||||
// filterChainDefinitionMap.putAll(SpringUtils.getBean(IMenuService.class).selectPermsAll());
|
||||
|
||||
Map<String, Filter> filters = new LinkedHashMap<>();
|
||||
filters.put("onlineSession", onlineSessionFilter());
|
||||
filters.put("syncOnlineSession", syncOnlineSessionFilter());
|
||||
filters.put("captchaValidate", captchaValidateFilter());
|
||||
// 注销成功,则跳转到指定页面
|
||||
filters.put("logout", logoutFilter());
|
||||
shiroFilterFactoryBean.setFilters(filters);
|
||||
|
||||
// 所有请求需要认证
|
||||
filterChainDefinitionMap.put("/**", "authc");
|
||||
filterChainDefinitionMap.put("/**", "user");
|
||||
// 系统请求记录当前会话
|
||||
filterChainDefinitionMap.put("/main", "onlineSession,syncOnlineSession");
|
||||
filterChainDefinitionMap.put("/system/**", "onlineSession,syncOnlineSession");
|
||||
@ -249,6 +285,42 @@ public class ShiroConfig
|
||||
return syncOnlineSessionFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义验证码过滤器
|
||||
*/
|
||||
@Bean
|
||||
public CaptchaValidateFilter captchaValidateFilter()
|
||||
{
|
||||
CaptchaValidateFilter captchaValidateFilter = new CaptchaValidateFilter();
|
||||
captchaValidateFilter.setCaptchaEbabled(captchaEbabled);
|
||||
captchaValidateFilter.setCaptchaType(captchaType);
|
||||
return captchaValidateFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookie 属性设置
|
||||
*/
|
||||
public SimpleCookie rememberMeCookie()
|
||||
{
|
||||
SimpleCookie cookie = new SimpleCookie("rememberMe");
|
||||
cookie.setDomain(domain);
|
||||
cookie.setPath(path);
|
||||
cookie.setHttpOnly(httpOnly);
|
||||
cookie.setMaxAge(maxAge * 24 * 60 * 60);
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记住我
|
||||
*/
|
||||
public CookieRememberMeManager rememberMeManager()
|
||||
{
|
||||
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
|
||||
cookieRememberMeManager.setCookie(rememberMeCookie());
|
||||
cookieRememberMeManager.setCipherKey(Base64.decode("fCq+/xW488hMTCD+cmJ3aQ=="));
|
||||
return cookieRememberMeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启Shiro代理
|
||||
*/
|
||||
|
@ -1,265 +0,0 @@
|
||||
package com.ruoyi.framework.mybatis;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import javax.xml.bind.PropertyException;
|
||||
import org.apache.ibatis.executor.ErrorContext;
|
||||
import org.apache.ibatis.executor.ExecutorException;
|
||||
import org.apache.ibatis.executor.statement.BaseStatementHandler;
|
||||
import org.apache.ibatis.executor.statement.RoutingStatementHandler;
|
||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.ParameterMapping;
|
||||
import org.apache.ibatis.mapping.ParameterMode;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.Intercepts;
|
||||
import org.apache.ibatis.plugin.Invocation;
|
||||
import org.apache.ibatis.plugin.Plugin;
|
||||
import org.apache.ibatis.plugin.Signature;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.apache.ibatis.reflection.property.PropertyTokenizer;
|
||||
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
|
||||
/**三
|
||||
* 拦截需要分页SQL
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Intercepts({ @Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class, Integer.class }) })
|
||||
public class ExecutorPageMethodInterceptor implements Interceptor
|
||||
{
|
||||
|
||||
private static String dialect = ""; // 数据库方言
|
||||
private static String pageSqlId = ""; // mapper.xml中需要拦截的ID(正则匹配)
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation ivk) throws Throwable
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
if (ivk.getTarget() instanceof RoutingStatementHandler)
|
||||
{
|
||||
RoutingStatementHandler statementHandler = (RoutingStatementHandler) ivk.getTarget();
|
||||
BaseStatementHandler delegate = (BaseStatementHandler) ReflectHelper.getValueByFieldName(statementHandler,
|
||||
"delegate");
|
||||
MappedStatement mappedStatement = (MappedStatement) ReflectHelper.getValueByFieldName(delegate,
|
||||
"mappedStatement");
|
||||
|
||||
if (mappedStatement.getId().matches(pageSqlId))
|
||||
{ // 拦截需要分页的SQL
|
||||
BoundSql boundSql = delegate.getBoundSql();
|
||||
Object parameterObject = boundSql.getParameterObject();// 分页SQL<select>中parameterType属性对应的实体参数,即Mapper接口中执行分页方法的参数,该参数不得为空
|
||||
if (parameterObject == null)
|
||||
{
|
||||
throw new NullPointerException("parameterObject尚未实例化!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Connection connection = (Connection) ivk.getArgs()[0];
|
||||
String sql = boundSql.getSql();
|
||||
// String countSql = "select count(0) from (" + sql+ ") as tmp_count"; //记录统计
|
||||
String countSql = "select count(0) from (" + sql + ") tmp_count"; // 记录统计 == oracle 加 as 报错(SQL
|
||||
// command not properly ended)
|
||||
PreparedStatement countStmt = connection.prepareStatement(countSql);
|
||||
BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,
|
||||
boundSql.getParameterMappings(), parameterObject);
|
||||
setParameters(countStmt, mappedStatement, countBS, parameterObject);
|
||||
ResultSet rs = countStmt.executeQuery();
|
||||
int count = 0;
|
||||
if (rs.next())
|
||||
{
|
||||
count = rs.getInt(1);
|
||||
}
|
||||
rs.close();
|
||||
countStmt.close();
|
||||
// System.out.println(count);
|
||||
PageUtilEntity pageUtilEntity = null;
|
||||
if (parameterObject instanceof PageUtilEntity)
|
||||
{
|
||||
// 参数就是Page实体
|
||||
pageUtilEntity = (PageUtilEntity) parameterObject;
|
||||
pageUtilEntity.setEntityOrField(true);
|
||||
pageUtilEntity.setTotalResult(count);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 参数为某个实体,该实体拥有Page属性
|
||||
Field pageField = ReflectHelper.getFieldByFieldName(parameterObject, "PageUtilEntity");
|
||||
if (pageField != null)
|
||||
{
|
||||
pageUtilEntity = (PageUtilEntity) ReflectHelper.getValueByFieldName(parameterObject, "PageUtilEntity");
|
||||
if (pageUtilEntity == null)
|
||||
{
|
||||
pageUtilEntity = new PageUtilEntity();
|
||||
}
|
||||
pageUtilEntity.setEntityOrField(false);
|
||||
pageUtilEntity.setTotalResult(count);
|
||||
ReflectHelper.setValueByFieldName(parameterObject, "PageUtilEntity", pageUtilEntity); // 通过反射,对实体对象设置分页对象
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NoSuchFieldException(
|
||||
parameterObject.getClass().getName() + "不存在 pageUtilEntity 属性!");
|
||||
}
|
||||
}
|
||||
String pageSql = generatePageSql(sql, pageUtilEntity);
|
||||
ReflectHelper.setValueByFieldName(boundSql, "sql", pageSql); // 将分页sql语句反射回BoundSql.
|
||||
}
|
||||
}
|
||||
}
|
||||
return ivk.proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对SQL参数(?)设值,参考org.apache.ibatis.executor.parameter.DefaultParameterHandler
|
||||
*
|
||||
* @param ps
|
||||
* @param mappedStatement
|
||||
* @param boundSql
|
||||
* @param parameterObject
|
||||
* @throws SQLException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void setParameters(PreparedStatement ps, MappedStatement mappedStatement, BoundSql boundSql,
|
||||
Object parameterObject) throws SQLException
|
||||
{
|
||||
ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
|
||||
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
|
||||
if (parameterMappings != null)
|
||||
{
|
||||
Configuration configuration = mappedStatement.getConfiguration();
|
||||
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
|
||||
MetaObject metaObject = parameterObject == null ? null : configuration.newMetaObject(parameterObject);
|
||||
for (int i = 0; i < parameterMappings.size(); i++)
|
||||
{
|
||||
ParameterMapping parameterMapping = parameterMappings.get(i);
|
||||
if (parameterMapping.getMode() != ParameterMode.OUT)
|
||||
{
|
||||
Object value;
|
||||
String propertyName = parameterMapping.getProperty();
|
||||
PropertyTokenizer prop = new PropertyTokenizer(propertyName);
|
||||
if (parameterObject == null)
|
||||
{
|
||||
value = null;
|
||||
}
|
||||
else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass()))
|
||||
{
|
||||
value = parameterObject;
|
||||
}
|
||||
else if (boundSql.hasAdditionalParameter(propertyName))
|
||||
{
|
||||
value = boundSql.getAdditionalParameter(propertyName);
|
||||
}
|
||||
else if (propertyName.startsWith(ForEachSqlNode.ITEM_PREFIX)
|
||||
&& boundSql.hasAdditionalParameter(prop.getName()))
|
||||
{
|
||||
value = boundSql.getAdditionalParameter(prop.getName());
|
||||
if (value != null)
|
||||
{
|
||||
value = configuration.newMetaObject(value)
|
||||
.getValue(propertyName.substring(prop.getName().length()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
value = metaObject == null ? null : metaObject.getValue(propertyName);
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
TypeHandler typeHandler = parameterMapping.getTypeHandler();
|
||||
if (typeHandler == null)
|
||||
{
|
||||
throw new ExecutorException("There was no TypeHandler found for parameter " + propertyName
|
||||
+ " of statement " + mappedStatement.getId());
|
||||
}
|
||||
typeHandler.setParameter(ps, i + 1, value, parameterMapping.getJdbcType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数据库方言,生成特定的分页sql
|
||||
*
|
||||
* @param sql
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
private String generatePageSql(String sql, PageUtilEntity pageUtilEntity)
|
||||
{
|
||||
if (pageUtilEntity != null && StringUtils.isNotEmpty(dialect))
|
||||
{
|
||||
StringBuffer pageSql = new StringBuffer();
|
||||
if ("mysql".equals(dialect))
|
||||
{
|
||||
pageSql.append(sql);
|
||||
if(StringUtils.isNotEmpty(pageUtilEntity.getOrderByColumn()))
|
||||
{
|
||||
pageSql.append(" order by " + pageUtilEntity.getOrderByColumn() + " " + pageUtilEntity.getIsAsc());
|
||||
}
|
||||
pageSql.append(" limit " + pageUtilEntity.getPage() + "," + pageUtilEntity.getSize());
|
||||
}
|
||||
else if ("oracle".equals(dialect))
|
||||
{
|
||||
pageSql.append("select * from (select tmp_tb.*,ROWNUM row_id from (");
|
||||
pageSql.append(sql);
|
||||
// pageSql.append(") as tmp_tb where ROWNUM<=");
|
||||
pageSql.append(") tmp_tb where ROWNUM<=");
|
||||
pageSql.append(pageUtilEntity.getPage() + pageUtilEntity.getSize());
|
||||
pageSql.append(") where row_id>");
|
||||
pageSql.append(pageUtilEntity.getPage());
|
||||
}
|
||||
return pageSql.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object arg0)
|
||||
{
|
||||
return Plugin.wrap(arg0, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperties(Properties p)
|
||||
{
|
||||
dialect = p.getProperty("dialect");
|
||||
if (StringUtils.isEmpty(dialect))
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new PropertyException("dialect property is not found!");
|
||||
}
|
||||
catch (PropertyException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
pageSqlId = p.getProperty("pageSqlId");
|
||||
if (StringUtils.isEmpty(pageSqlId))
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new PropertyException("pageSqlId property is not found!");
|
||||
}
|
||||
catch (PropertyException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
package com.ruoyi.framework.mybatis;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 拦截需要分页SQL 反射工具
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ReflectHelper
|
||||
{
|
||||
/**
|
||||
* 获取obj对象fieldName的Field
|
||||
*
|
||||
* @param obj
|
||||
* @param fieldName
|
||||
* @return
|
||||
*/
|
||||
public static Field getFieldByFieldName(Object obj, String fieldName)
|
||||
{
|
||||
for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass())
|
||||
{
|
||||
try
|
||||
{
|
||||
return superClass.getDeclaredField(fieldName);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取obj对象fieldName的属性值
|
||||
*
|
||||
* @param obj
|
||||
* @param fieldName
|
||||
* @return
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchFieldException
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static Object getValueByFieldName(Object obj, String fieldName)
|
||||
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
Field field = getFieldByFieldName(obj, fieldName);
|
||||
Object value = null;
|
||||
if (field != null)
|
||||
{
|
||||
if (field.isAccessible())
|
||||
{
|
||||
value = field.get(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
field.setAccessible(true);
|
||||
value = field.get(obj);
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置obj对象fieldName的属性值
|
||||
*
|
||||
* @param obj
|
||||
* @param fieldName
|
||||
* @param value
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchFieldException
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static void setValueByFieldName(Object obj, String fieldName, Object value)
|
||||
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
|
||||
{
|
||||
Field field = obj.getClass().getDeclaredField(fieldName);
|
||||
if (field.isAccessible())
|
||||
{
|
||||
field.set(obj, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
field.setAccessible(true);
|
||||
field.set(obj, value);
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.ruoyi.common.exception.user.CaptchaException;
|
||||
import com.ruoyi.common.exception.user.RoleBlockedException;
|
||||
import com.ruoyi.common.exception.user.UserBlockedException;
|
||||
import com.ruoyi.common.exception.user.UserNotExistsException;
|
||||
@ -79,6 +80,10 @@ public class UserRealm extends AuthorizingRealm
|
||||
{
|
||||
user = loginService.login(username, password);
|
||||
}
|
||||
catch (CaptchaException e)
|
||||
{
|
||||
throw new AuthenticationException(e.getMessage(), e);
|
||||
}
|
||||
catch (UserNotExistsException e)
|
||||
{
|
||||
throw new UnknownAccountException(e.getMessage(), e);
|
||||
|
@ -4,11 +4,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import com.ruoyi.common.constant.CommonConstant;
|
||||
import com.ruoyi.common.constant.ShiroConstants;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.exception.user.CaptchaException;
|
||||
import com.ruoyi.common.exception.user.UserBlockedException;
|
||||
import com.ruoyi.common.exception.user.UserNotExistsException;
|
||||
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.SystemLogUtils;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
import com.ruoyi.project.system.user.service.IUserService;
|
||||
@ -32,6 +35,12 @@ public class LoginService
|
||||
*/
|
||||
public User login(String username, String password)
|
||||
{
|
||||
// 验证码校验
|
||||
if (!StringUtils.isEmpty(ServletUtils.getStrAttribute(ShiroConstants.CURRENT_CAPTCHA)))
|
||||
{
|
||||
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"));
|
||||
throw new CaptchaException();
|
||||
}
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password))
|
||||
{
|
||||
|
@ -85,7 +85,17 @@ public class PasswordService
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(new PasswordService().encryptPassword("admin", "admin123", "111111"));
|
||||
System.out.println(new PasswordService().encryptPassword("ry", "admin123", "222222"));
|
||||
//System.out.println(new PasswordService().encryptPassword("admin", "admin123", "111111"));
|
||||
//System.out.println(new PasswordService().encryptPassword("ry", "admin123", "222222"));
|
||||
System.out.println(new PasswordService().encryptPassword("ly", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("ce", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("zs", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("ls", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("ww", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("zl", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("sq", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("zb", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("wj", "admin123", "123456"));
|
||||
System.out.println(new PasswordService().encryptPassword("ys", "admin123", "123456"));
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import com.ruoyi.common.utils.IpUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.project.monitor.online.domain.OnlineSession;
|
||||
import com.ruoyi.project.monitor.online.domain.UserOnline;
|
||||
|
||||
import eu.bitwalker.useragentutils.UserAgent;
|
||||
|
||||
/**
|
||||
@ -42,8 +41,7 @@ public class OnlineSessionFactory implements SessionFactory
|
||||
HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
|
||||
if (request != null)
|
||||
{
|
||||
UserAgent userAgent = UserAgent
|
||||
.parseUserAgentString(ServletUtils.getHttpServletRequest().getHeader("User-Agent"));
|
||||
UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
// 获取客户端操作系统
|
||||
String os = userAgent.getOperatingSystem().getName();
|
||||
// 获取客户端浏览器
|
||||
|
@ -0,0 +1,78 @@
|
||||
package com.ruoyi.framework.shiro.web.filter.captcha;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.shiro.web.filter.AccessControlFilter;
|
||||
import com.google.code.kaptcha.Constants;
|
||||
import com.ruoyi.common.constant.ShiroConstants;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
|
||||
/**
|
||||
* 验证码过滤器
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class CaptchaValidateFilter extends AccessControlFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* 是否开启验证码
|
||||
*/
|
||||
private boolean captchaEbabled = true;
|
||||
|
||||
/**
|
||||
* 验证码类型
|
||||
*/
|
||||
private String captchaType = "math";
|
||||
|
||||
public void setCaptchaEbabled(boolean captchaEbabled)
|
||||
{
|
||||
this.captchaEbabled = captchaEbabled;
|
||||
}
|
||||
|
||||
public void setCaptchaType(String captchaType)
|
||||
{
|
||||
this.captchaType = captchaType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception
|
||||
{
|
||||
request.setAttribute(ShiroConstants.CURRENT_EBABLED, captchaEbabled);
|
||||
request.setAttribute(ShiroConstants.CURRENT_TYPE, captchaType);
|
||||
return super.onPreHandle(request, response, mappedValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
|
||||
throws Exception
|
||||
{
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
// 验证码禁用 或不是表单提交 允许访问
|
||||
if (captchaEbabled == false || !"post".equals(httpServletRequest.getMethod().toLowerCase()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return validateResponse(httpServletRequest, httpServletRequest.getParameter(ShiroConstants.CURRENT_VALIDATECODE));
|
||||
}
|
||||
|
||||
public boolean validateResponse(HttpServletRequest request, String validateCode)
|
||||
{
|
||||
Object obj = ShiroUtils.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
|
||||
String code = String.valueOf(obj != null ? obj : "");
|
||||
if (StringUtils.isEmpty(validateCode) || !validateCode.equalsIgnoreCase(code))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception
|
||||
{
|
||||
request.setAttribute(ShiroConstants.CURRENT_CAPTCHA, ShiroConstants.CAPTCHA_ERROR);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -6,9 +6,8 @@ import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.framework.web.page.PageDomain;
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.framework.web.support.TableSupport;
|
||||
import com.ruoyi.framework.web.page.TableSupport;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
@ -18,26 +17,17 @@ import com.ruoyi.project.system.user.domain.User;
|
||||
*/
|
||||
public class BaseController
|
||||
{
|
||||
/**
|
||||
* 获取请求分页数据
|
||||
*/
|
||||
public PageUtilEntity getPageUtilEntity()
|
||||
{
|
||||
PageUtilEntity pageUtilEntity = TableSupport.buildPageRequest();
|
||||
return pageUtilEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求分页数据
|
||||
*/
|
||||
protected void setPageInfo(Object obj)
|
||||
protected void startPage()
|
||||
{
|
||||
PageDomain page = (PageDomain) obj;
|
||||
if (StringUtils.isNotEmpty(page.getPageNum()) && StringUtils.isNotEmpty(page.getPageSize()))
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
Integer pageNum = pageDomain.getPageNum();
|
||||
Integer pageSize = pageDomain.getPageSize();
|
||||
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
|
||||
{
|
||||
int pageNum = Integer.valueOf(page.getPageNum());
|
||||
int pageSize = Integer.valueOf(page.getPageSize());
|
||||
String orderBy = page.getOrderBy();
|
||||
String orderBy = pageDomain.getOrderBy();
|
||||
PageHelper.startPage(pageNum, pageSize, orderBy);
|
||||
}
|
||||
}
|
||||
@ -58,7 +48,7 @@ public class BaseController
|
||||
{
|
||||
return ShiroUtils.getUser();
|
||||
}
|
||||
|
||||
|
||||
public void setUser(User user)
|
||||
{
|
||||
ShiroUtils.setUser(user);
|
||||
|
@ -1,207 +0,0 @@
|
||||
package com.ruoyi.framework.web.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 数据DAO层通用数据处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DynamicObjectBaseDao
|
||||
{
|
||||
@Resource(name = "sqlSessionTemplate")
|
||||
private SqlSessionTemplate sqlSessionTemplate;
|
||||
|
||||
/**
|
||||
* 保存对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int save(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.insert(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int batchSave(String str, List<?> objs)
|
||||
{
|
||||
return sqlSessionTemplate.insert(str, objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int update(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.update(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public void batchUpdate(String str, List<?> objs) throws Exception
|
||||
{
|
||||
SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
|
||||
// 批量执行器
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
try
|
||||
{
|
||||
if (objs != null)
|
||||
{
|
||||
for (int i = 0, size = objs.size(); i < size; i++)
|
||||
{
|
||||
sqlSession.update(str, objs.get(i));
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
sqlSession.commit();
|
||||
sqlSession.clearCache();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除 根据对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int batchDelete(String str, List<?> objs) throws Exception
|
||||
{
|
||||
return sqlSessionTemplate.delete(str, objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除 根据数组
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int batchDelete(String str, Long[] objs)
|
||||
{
|
||||
return sqlSessionTemplate.delete(str, objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int delete(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.delete(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找单条对象
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public <T> T findForObject(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.selectOne(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找总数
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public int count(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.selectOne(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找对象 - 无条件
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public <E> List<E> findForList(String str)
|
||||
{
|
||||
return sqlSessionTemplate.selectList(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找对象 - 有条件
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public <E> List<E> findForList(String str, Object obj)
|
||||
{
|
||||
return sqlSessionTemplate.selectList(str, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义分页方法
|
||||
*
|
||||
* @param str mapper 节点
|
||||
* @param obj 对象
|
||||
* @return 结果
|
||||
* @throws Exception
|
||||
*/
|
||||
public TableDataInfo findForList(String str, PageUtilEntity pageUtilEntity)
|
||||
{
|
||||
List<?> pageList = sqlSessionTemplate.selectList(str, pageUtilEntity);
|
||||
TableDataInfo tableDataInfo = new TableDataInfo(pageList, pageUtilEntity.getTotalResult());
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
public Object findForMap(String str, Object obj, String key, String value) throws Exception
|
||||
{
|
||||
return sqlSessionTemplate.selectMap(str, obj, key);
|
||||
}
|
||||
|
||||
}
|
98
src/main/java/com/ruoyi/framework/web/domain/BaseEntity.java
Normal file
98
src/main/java/com/ruoyi/framework/web/domain/BaseEntity.java
Normal file
@ -0,0 +1,98 @@
|
||||
package com.ruoyi.framework.web.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
|
||||
/**
|
||||
* Entity基类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class BaseEntity implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
/** 搜索值 */
|
||||
private String searchValue;
|
||||
/** 创建者 */
|
||||
private String createBy;
|
||||
/** 创建时间 */
|
||||
private Date createTime;
|
||||
/** 更新者 */
|
||||
private String updateBy;
|
||||
/** 更新时间 */
|
||||
private Date updateTime;
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
|
||||
public String getSearchValue()
|
||||
{
|
||||
return searchValue;
|
||||
}
|
||||
|
||||
public void setSearchValue(String searchValue)
|
||||
{
|
||||
this.searchValue = searchValue;
|
||||
}
|
||||
|
||||
public String getCreateBy()
|
||||
{
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(String createBy)
|
||||
{
|
||||
this.createBy = createBy;
|
||||
}
|
||||
|
||||
public String getCreateTimeStr()
|
||||
{
|
||||
return createTime != null ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, createTime) : "";
|
||||
}
|
||||
|
||||
public String getCreateDateTimeStr()
|
||||
{
|
||||
return createTime != null ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, createTime) : "";
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime)
|
||||
{
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getUpdateBy()
|
||||
{
|
||||
return updateBy;
|
||||
}
|
||||
|
||||
public void setUpdateBy(String updateBy)
|
||||
{
|
||||
this.updateBy = updateBy;
|
||||
}
|
||||
|
||||
public String getUpdateTimeStr()
|
||||
{
|
||||
return updateTime != null ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, updateTime) : "";
|
||||
}
|
||||
|
||||
public String getUpdateDateTimeStr()
|
||||
{
|
||||
return updateTime != null ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, updateTime) : "";
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime)
|
||||
{
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public String getRemark()
|
||||
{
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark)
|
||||
{
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.ruoyi.framework.web.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 操作消息提醒
|
||||
@ -13,12 +12,10 @@ public class Message extends HashMap<String, Object>
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 初始化一个新创建的 Message 对象,默认成功。
|
||||
* 初始化一个新创建的 Message 对象
|
||||
*/
|
||||
public Message()
|
||||
{
|
||||
put("code", 0);
|
||||
put("msg", "操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,34 +60,22 @@ public class Message extends HashMap<String, Object>
|
||||
* @param msg 内容
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static Message ok(String msg)
|
||||
public static Message success(String msg)
|
||||
{
|
||||
Message json = new Message();
|
||||
json.put("msg", msg);
|
||||
json.put("code", 0);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @param map 内容
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static Message ok(Map<String, Object> map)
|
||||
{
|
||||
Message json = new Message();
|
||||
json.putAll(map);
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static Message ok()
|
||||
public static Message success()
|
||||
{
|
||||
return new Message();
|
||||
return Message.success("操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,82 +0,0 @@
|
||||
package com.ruoyi.framework.web.page;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* 分页数据
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class PageDomain
|
||||
{
|
||||
/** 当前记录起始索引 */
|
||||
private String pageNum;
|
||||
/** 每页显示记录数 */
|
||||
private String pageSize;
|
||||
/** 排序列 */
|
||||
private String orderByColumn;
|
||||
/** 排序的方向 "desc" 或者 "asc". */
|
||||
private String isAsc;
|
||||
/** 搜索值 */
|
||||
private String searchValue;
|
||||
|
||||
public String getOrderBy()
|
||||
{
|
||||
if (StringUtils.isEmpty(orderByColumn))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return orderByColumn + " " + isAsc;
|
||||
}
|
||||
|
||||
public String getPageNum()
|
||||
{
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(String pageNum)
|
||||
{
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public String getPageSize()
|
||||
{
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(String pageSize)
|
||||
{
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getOrderByColumn()
|
||||
{
|
||||
return orderByColumn;
|
||||
}
|
||||
|
||||
public void setOrderByColumn(String orderByColumn)
|
||||
{
|
||||
this.orderByColumn = orderByColumn;
|
||||
}
|
||||
|
||||
public String getIsAsc()
|
||||
{
|
||||
return isAsc;
|
||||
}
|
||||
|
||||
public void setIsAsc(String isAsc)
|
||||
{
|
||||
this.isAsc = isAsc;
|
||||
}
|
||||
|
||||
public String getSearchValue()
|
||||
{
|
||||
return searchValue;
|
||||
}
|
||||
|
||||
public void setSearchValue(String searchValue)
|
||||
{
|
||||
this.searchValue = searchValue;
|
||||
}
|
||||
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
package com.ruoyi.framework.web.page;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 表格请求参数封装
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class PageUtilEntity
|
||||
{
|
||||
/** 当前记录起始索引 */
|
||||
private int page;
|
||||
/** 每页显示记录数 */
|
||||
private int size;
|
||||
/** 排序列 */
|
||||
private String orderByColumn;
|
||||
/** 排序的方向 "desc" 或者 "asc". */
|
||||
private String isAsc;
|
||||
/** true:需要分页的地方,传入的参数就是Page实体;false:需要分页的地方,传入的参数所代表的实体拥有Page属性 */
|
||||
private boolean entityOrField;
|
||||
/** 总记录数 */
|
||||
private int totalResult;
|
||||
/** 搜索值 */
|
||||
private String searchValue;
|
||||
/** 请求参数 */
|
||||
protected Map<String, Object> reqMap;
|
||||
|
||||
public int getPage()
|
||||
{
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(int page)
|
||||
{
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int size)
|
||||
{
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getOrderByColumn()
|
||||
{
|
||||
return orderByColumn;
|
||||
}
|
||||
|
||||
public void setOrderByColumn(String orderByColumn)
|
||||
{
|
||||
this.orderByColumn = orderByColumn;
|
||||
}
|
||||
|
||||
public String getIsAsc()
|
||||
{
|
||||
return isAsc;
|
||||
}
|
||||
|
||||
public void setIsAsc(String isAsc)
|
||||
{
|
||||
this.isAsc = isAsc;
|
||||
}
|
||||
|
||||
public boolean isEntityOrField()
|
||||
{
|
||||
return entityOrField;
|
||||
}
|
||||
|
||||
public void setEntityOrField(boolean entityOrField)
|
||||
{
|
||||
this.entityOrField = entityOrField;
|
||||
}
|
||||
|
||||
public int getTotalResult()
|
||||
{
|
||||
return totalResult;
|
||||
}
|
||||
|
||||
public void setTotalResult(int totalResult)
|
||||
{
|
||||
this.totalResult = totalResult;
|
||||
}
|
||||
|
||||
public String getSearchValue()
|
||||
{
|
||||
return searchValue;
|
||||
}
|
||||
|
||||
public void setSearchValue(String searchValue)
|
||||
{
|
||||
this.searchValue = searchValue;
|
||||
}
|
||||
|
||||
public Map<String, Object> getReqMap()
|
||||
{
|
||||
return reqMap;
|
||||
}
|
||||
|
||||
public void setReqMap(Map<String, Object> reqMap)
|
||||
{
|
||||
this.reqMap = reqMap;
|
||||
}
|
||||
|
||||
}
|
31
src/main/java/com/ruoyi/framework/web/page/TableSupport.java
Normal file
31
src/main/java/com/ruoyi/framework/web/page/TableSupport.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.ruoyi.framework.web.page;
|
||||
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.constant.CommonConstant;
|
||||
|
||||
/**
|
||||
* 表格数据处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class TableSupport
|
||||
{
|
||||
/**
|
||||
* 封装分页对象
|
||||
*/
|
||||
public static PageDomain getPageDomain()
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(ServletUtils.getIntParameter(CommonConstant.PAGENUM));
|
||||
pageDomain.setPageSize(ServletUtils.getIntParameter(CommonConstant.PAGESIZE));
|
||||
pageDomain.setOrderByColumn(ServletUtils.getStrParameter(CommonConstant.ORDERBYCOLUMN));
|
||||
pageDomain.setIsAsc(ServletUtils.getStrParameter(CommonConstant.ISASC));
|
||||
return pageDomain;
|
||||
}
|
||||
|
||||
public static PageDomain buildPageRequest()
|
||||
{
|
||||
return getPageDomain();
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.ruoyi.framework.web.support;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.MapDataUtil;
|
||||
import com.ruoyi.framework.web.page.PageUtilEntity;
|
||||
|
||||
/**
|
||||
* 表格数据处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class TableSupport
|
||||
{
|
||||
/**
|
||||
* 封装分页对象
|
||||
*/
|
||||
public static PageUtilEntity getPageUtilEntity()
|
||||
{
|
||||
HttpServletRequest request = ServletUtils.getHttpServletRequest();
|
||||
PageUtilEntity pageUtilEntity = new PageUtilEntity();
|
||||
pageUtilEntity.setPage(Integer.valueOf(request.getParameter("offset")));
|
||||
pageUtilEntity.setSize(Integer.valueOf(request.getParameter("limit")));
|
||||
pageUtilEntity.setOrderByColumn(request.getParameter("sort"));
|
||||
pageUtilEntity.setIsAsc(request.getParameter("order"));
|
||||
pageUtilEntity.setSearchValue(request.getParameter("search"));
|
||||
pageUtilEntity.setReqMap(MapDataUtil.convertDataMap(request));
|
||||
return pageUtilEntity;
|
||||
}
|
||||
|
||||
public static PageUtilEntity buildPageRequest()
|
||||
{
|
||||
return getPageUtilEntity();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user