daily 2017 5 26 cookie session - wtdig/study GitHub Wiki

一对多的分页查询

1、表结构 one:id,name,city more:id,name,city,one_id

2、select o.id,o.name,o.city,m.id,m.name,m.city

from (select a.id,a.name,a.city from one a where condition='' order by a.id limit begin,end) o

left join (select b.id,b.name,b.city,b.one_id from more b where condition='' ) m

on o.id=m.one_id

实例:mybatis

select

t.id temp_id,t.subject_rule_name,t.bt,t.creator,

r.id rule_id,r.accounting_rule_name,r.coa_code,r.rule_condition

from

(select a.id,a.creator,a.bt,a.subject_rule_name

from sac_accounting_subject_rule a

where a.is_deleted = 'n'

and a.bt in

#{item}

and a.creator = #{cond.creator,jdbcType=VARCHAR}

and a.subject_rule_name = #{cond.subjectRuleName,jdbcType=VARCHAR}

and exists(select c.id

from sac_accounting_rule c

where c.is_deleted = 'n'

and a.id = c.subject_rule_id

and c.accounting_rule_name = #

{cond.accountingRuleName,jdbcType=VARCHAR}

and c.coa_code = #

{cond.coa,jdbcType=VARCHAR}

)

order by a.id desc

limit #{cond.begin,jdbcType=BIGINT}, #{cond.pageSize,jdbcType=BIGINT}

) t

left join

(select b.id,b.accounting_rule_name,b.coa_code,b.rule_condition,b.subject_rule_id

from sac_accounting_rule b

where b.is_deleted = 'n'

and b.accounting_rule_name = #{cond.accountingRuleName,jdbcType=VARCHAR}

and b.coa_code = #{cond.coa,jdbcType=VARCHAR}

) r

on t.id = r.subject_rule_id

order by t.id desc


cookie\session

1、获取cookie

httpServletRequest requst httpServletResponse response

// 获取cookie

Cookie[] cookies = request.getCookies();

for (Cookie cookie : cookies) {

String name = cookie.getName();

String value = cookie.getValue();

}

//新建一个cookie

Cookie newCookie = new Cookie("name", "value");

// 设置生命周期 60单位为秒

newCookie.setMaxAge(60);

response.addCookie(newCookie);

2、获取session

//获取session session可以看成一个map的数据结构

HttpSession session = request.getSession();

//根据key获取seesion中的值

session.getAttribute("");

//向seesion中设置键和值

session.setAttribute("", "");

//根据key移除session中的值

session.removeAttribute("");

//判断该session是否是一个新的session

boolean new1 = session.isNew();

//获取session的key值,一般为JSESSIONID

String id = session.getId();

3、session的生效时间

session会在请求的时候由tomcat服务器自行创建,并创建一个唯一标识JSESSIONID=“.......”,保存在服务器上,通过cookie技术,将 JSESSIONID回传到浏览器端,浏览器再次发生请求时,会携带cookie信息(JSESSIONID),去与服务器中的保存的id值去匹配,匹配到后 取其值,这样就可以从session中获取到值了

session默认当没有请求时,超过30分钟就会自动销毁掉,或者服务器关闭,获取手动销毁

手动销毁session

// 手动摧毁session

session.invalidate();

设置session有效时间的方法:

(1)web.xml中

30

(2)程序中设置

session.setMaxInactiveInterval(30 * 60);//设置单位为秒,设置为-1永不过期

(3)tomcat服务器中设置

tomcat也可以修改session过期时间,在server.xml中定义context时采用如下定义:

isWARExpanded="true"   isWARValidated="false" isInvokerEnabled="true"   isWorkDirPersistent="false"/>

三种方式优先级:3<1<2

⚠️ **GitHub.com Fallback** ⚠️