📄 producttest.java
字号:
package com.sdi0708.bdifn.bookstore.domain;import junit.framework.TestCase;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class ProductTest 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("计算机"); Product p = new Product(); p.setCatalog(c); p.setDescription("编程类书藉"); p.setProductName("java 编程思想"); p.setUnitPrice(108.00); session.beginTransaction(); session.save(p); session.getTransaction().commit(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -