producttest.java
来自「巴巴运动网源码 传智博客出品 不全 一部分代码 可以参考」· Java 代码 · 共 78 行
JAVA
78 行
package junit.test;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import junit.framework.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.itcast.bean.QueryResult;
import com.itcast.bean.product.ProductType;
import com.itcast.service.product.ProductTypeService;
public class ProductTest {
private static ApplicationContext cxt;
private static ProductTypeService productService;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
try {
cxt = new ClassPathXmlApplicationContext("beans.xml");
productService = (ProductTypeService)cxt.getBean("productTypeServiceBean");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 四舍五入,保留一位小数
* @param dSource
* @return
*/
public static float round(float dSource){
BigDecimal deSource = new BigDecimal(dSource);
return deSource.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
}
@Test
public void testSave(){
for(int i=0;i<20;i++){
ProductType type = new ProductType();
type.setName(i+ "蓝球用品");
type.setNote("好蓝球");
productService.save(type);
}
}
@Test
public void testFind(){
ProductType type = productService.find(ProductType.class, 1);
Assert.assertNotNull("获取不到id为1的记录", type);
}
@Test
public void testUpdate(){
ProductType type = productService.find(ProductType.class, 1);
type.setName("足球");
type.setNote("好足球");
productService.update(type);
}
@Test
public void testDelete(){
productService.delete(ProductType.class, 2);
}
@Test
public void testgetScrollData(){
LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
orderby.put("typeid", "asc");
QueryResult<ProductType> qr = productService.getScrollData(ProductType.class);
for(ProductType t : qr.getResultlist()){
System.out.println(t.getName());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?