1. param参数
了解<jsp:param场合> 在requestScope增加setAttribute
2. EL表达式如果,了解null与“”区别为null为没有分配空间,""为分配了空间,但值为空。
值为null 用${ empty param.sort }
值为空 用 ${ “” == param.sort }
3. 增删改查,一般HQL都是下面个范本
LinkedHashMap<String,String> orderBy = new LinkedHashMap<String,String>();
orderBy.put("typeid", "desc");
StringBuffer hqlwhere = new StringBuffer();
List<Object> params = new ArrayList<Object>();
hqlwhere.append(" o.visible = ?"+(params.size()+1));
params.add(true);
if("query".equals(formbean.getQuery())){
//查询,去掉parentid
hqlwhere.append(" and o.name like ?"+(params.size()+1));
params.add("%"+formbean.getName()+"%");
}else{
//非查询,按照parentid筛选
if(formbean.getParentid()==null || formbean.getParentid()==0){
hqlwhere.append(" and o.parent.typeid IS NULL");
}else{
hqlwhere.append(" and o.parent.typeid = ?"+(params.size()+1));
params.add(formbean.getParentid());
}
}
//2.组装HQL的List集
QueryResult<ProductType> qr = productTypeService.getScrollData(ProductType.class,firstIndex,maxresult,hqlwhere.toString(),params.toArray(),orderBy);
PageView<ProductType> pageView = new PageView<ProductType>(qr.getResultlist(),qr.getTotalrecord(),currentpage);
request.setAttribute("pageView", pageView);
如果有必要在做一遍,了解文件的操作 ,清楚项目路径与绝对路径的操作
1) file.exists()
2) file.mkdirs()
3) FileOutputStream out = new FileOutputStream(new File(logoRealPath+"/"+logoFileName))
if (logofile != null && logofile.getFileSize() != 0) {
String logoPathDir = "images/brand/"
+ new SimpleDateFormat("yyyy/MM/dd").format(new Date());
String logoRealPath = request.getSession().getServletContext()
.getRealPath(logoPathDir);
// 3.构建图片保存的目录
if (!file.exists())
file.mkdirs();
// 4.构建文件名称
String ext = logofile.getFileName().substring(
logofile.getFileName().indexOf("."));
String logoFileName = UUID.randomUUID().toString() + ext;
FileOutputStream out = new FileOutputStream(new File(logoRealPath
+ "/" + logoFileName));
out.write(logofile.getFileData());
out.close();
String logopath = logoPathDir + "/" + logoFileName;
brand.setLogopath(logopath);
}
brandService.save(brand);
5. @Temporal
日期: @Temporal(TemporalType.DATE)
时间: @Temporal(TemporalType.TIME)
日期和时间:@Temporal(TemporalType.TIMESTAMP)
6.枚举值的用法
enum FruitEnum {
APPLE(1), ORANGE(2); // 调用构造函数来构造枚举项
private int value = 0;
private FruitEnum(int value) { // 必须是private的,否则编译错误
this.value = value;
}
public static FruitEnum valueOf(int value) { // 手写的从int到enum的转换函数
switch (value) {
case 1:
return APPLE;
case 2:
return ORANGE;
default:
return null;
}
}
public int value() {
return this.value;
}
}