代码拉取完成,页面将自动刷新
package com.fly.test;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import com.fly.HbnApplication;
import com.fly.hbn.model.Customer;
import com.fly.hbn.service.CustomerService;
/**
* Junit 单元测试
*
* @author 00fly
* @version [版本号, 2018-09-11]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = HbnApplication.class)
public class CustomerServiceTest
{
@Autowired
CustomerService customerService;
@Autowired
private SessionFactory sessionFactory;
/**
* 事务测试(去掉@Transactional数据被插入或更新)
*
* @see [类、类#方法、类#成员]
*/
@Test
public void testTrans()
{
List<Customer> list = customerService.getAllCustomers();
System.out.println(list);
for (Customer customer : list)
{
customer.setCustomerName("custome_" + RandomStringUtils.randomNumeric(8));
customerService.updateCustomer(customer);
}
}
@Test
public void test()
{
Session session = sessionFactory.getCurrentSession();
List<?> data = session.createSQLQuery("select * from customer").addEntity(Customer.class).list();
System.out.println(data);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。