2017.3.1我工作中遇到小问题的总结
1.这几天在研究shiro的知识,就是简单的java代码,shiro并没有与spring进行集成,但是我在读取shiro.ini文件时,出现了总是读不到文件的问题,
package shiro1;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.Ini;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.junit.Test;
import junit.framework.Assert;
public class LoginTest1 {
@Test
public void testLogin() {
// 声明ini实例
Ini ini = new Ini();
LoginTest1.class.getClassLoader();
ini.load(ClassLoader.getSystemResourceAsStream("shiro1.ini"));
Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(ini);
// 从工厂的实例中获取安全管理器
org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
// 获取主体
Subject subject = SecurityUtils.getSubject();
// 收集用户名和密码
UsernamePasswordToken token = new UsernamePasswordToken("wang", "123");
try {
subject.login(token);
} catch (AuthenticationException e) {
System.out.println("用户名或密码错误,用户登录失败");
e.printStackTrace();
}
// 断言用户已经登录
Assert.assertEquals(true, subject.isAuthenticated());
subject.logout();
}
}
后来发现只需要这样写便可以读取到classpath下面的.ini文件
这是shiro1.ini文件:
[users]
zhang=123,role1
wang=123
[roles]
role1 = printer:print,printer:query
2.工作中正某页面列表进行搜索时,需要进行日期的搜索,那么日期有起始日期和结束日期,我们用的是一个date[]来接收起始和结束的这两个时间段.
但是前台传值时,如果有一个日期传成空,我们的sql就会报错,所以我们要给空的日期值,一个默认的最大值或者最小值
if (dto.getCondition().getCloseCaseDate() != null) {
dto.getCondition().getCloseCaseDate()[0] = dto.getCondition().getCloseCaseDate()[0] == null ? new Date(0) : dto.getCondition().getCloseCaseDate()[0];
dto.getCondition().getCloseCaseDate()[1] = dto.getCondition().getCloseCaseDate()[1] == null ? new Date(Long.MAX_VALUE) : dto.getCondition().getCloseCaseDate()[1];
}
3.还有插入的insert 语句的了解
如果想插入多条语句
insert into 表名() values(),()()..
这样就可以啦

浙公网安备 33010602011771号