📄 catalogtest.java
字号:
package com.sdi0708.bdifn.bookstore.domain;import java.util.List;import junit.framework.TestCase;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class CatalogTest extends TestCase { Session session = null; @Override protected void setUp() throws Exception { super.setUp(); String config = "com/sdi0708/bdifn/bookstore/domain/applicationContext.xml"; ApplicationContext context = new ClassPathXmlApplicationContext(config); SessionFactory sessionFactory = (SessionFactory) context .getBean("sessionFactory"); session = sessionFactory.openSession(); } @Override protected void tearDown() throws Exception { super.tearDown(); session.close(); } public void testSave() {// Catalog c = new Catalog();// c.setId(1000L);// c.setDescription("计算机类书");// c.setName("计算机");// session.beginTransaction();// session.save(c);// session.getTransaction().commit(); Long key = null; Long h = null; String hql = "select max(id) from Catalog"; Query q = session.createQuery(hql); List result = q.list(); //表示增加顶层类别 if(h == null){ if(result != null && result.size() == 1) { h = (Long) result.get(0)/ 100 + 1; } //如果是没有记录,从10起.下一个是11下下一个是12 else h = 10L; //它是需层类别,则后两个为零 key = h * 100 ; } else { System.out.println(result.get(0)); //把后两位数去掉 key = (h /100) * 100 + (Long) result.get(0) % 100 + 1; } System.out.println(key); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -