1.Convert转成String,在用Like查询。select * from table1 where convert(varchar,date,120) like '2006-04-01%'
我在项目中要用到like查询日期时间我接收到的参数时String类型数据库里面的日期字段类型为datetime的
@RequestMapping(params = "getSelectDatagrid")
public void getSelectDatagrid(HttpServletRequest request,HttpServletResponse response){
JsonResult jr = new JsonResult();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try{
String name = request.getParameter("selectName");
String technicalGrade = request.getParameter("selectTechnicalGrade");
String birthdayDate = request.getParameter("selectBirthdayDate");
String joinWorkDate = request.getParameter("selectJoinWorkDate");
String hql = "FROM ExportInfoEntity WHERE 1=1" ;
if(StringUtil.isNotEmpty(name)){
hql += " AND name LIKE '%" + name + "%'";
}
if(StringUtil.isNotEmpty(technicalGrade)&& !technicalGrade.equals("0")){
hql += " AND technicalGrade LIKE '%" + technicalGrade + "%'";
}
if(StringUtil.isNotEmpty(birthdayDate)){
hql += " AND convert(varchar,birthdayDate,120) LIKE '%" + birthdayDate + "%'";
}
if(StringUtil.isNotEmpty(joinWorkDate)){
hql += " AND convert(varchar,joinWorkDate,120) LIKE '%" + joinWorkDate + "%'";
}
List<ExportInfoEntity> list = systemService.findByQueryString(hql);
if(list.size()>0 && list!=null){
for(ExportInfoEntity exportInfoEntity : list){
if(oConvertUtils.isNotEmpty(exportInfoEntity)){
if(exportInfoEntity.getTechnicalGrade()==1){
exportInfoEntity.setStrTechnicalGrade("一般");
}else if(exportInfoEntity.getTechnicalGrade()==2){
exportInfoEntity.setStrTechnicalGrade("良好");
}else if(exportInfoEntity.getTechnicalGrade()==3){
exportInfoEntity.setStrTechnicalGrade("优秀");
}
}
}
}
jr.setResultCode(0);
jr.setResultObject(list);
}catch(Exception e){
e.printStackTrace();
}
this.flushObjectJson(jr, response);
}
转载请注明原文地址: https://ju.6miu.com/read-377.html