记录一下我的模糊综合查询的实现过程:
controller层 ItemsController :类
@Controller
public class ItemsController {
@Autowired
private ItemsService itemsService;
@RequestMapping("/queryItems")
public ModelAndView queryItems(HttpServletRequest request, ItemsQueryVo itemsQueryVo) throws Exception {
List itemsList = itemsService.finditemsList(itemsQueryVo);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("itemsList", itemsList);
modelAndView.setViewName("/items/itemsList");
return modelAndView;
}
}
mapper层:ItemsMapperCustom :接口
public interface ItemsMapperCustom {
public ListfinditemsList(ItemsQueryVo itemsQueryVo)throws Exception;
}
mapper层的映射文件:ItemsMapperCustom.xml
items.name like '%${itemsCustom.name}%'
pojo层: 实体类item+实体类的拓展类itemCustom
public class Items {
private Integer id;
private String name;
private Float price;
private String pic;
private Date createtime;
private String detail;
//省略getter,setter
}
public class ItemsCustom extends Items {
}
service层 ItemsService接口和ItemsServiceImpl实现类:
public interface ItemsService {
public List finditemsList(ItemsQueryVo itemsQueryVo)throws Exception;
}
@Service
public class ItemsServiceImpl implements ItemsService {
@Autowired
private ItemsMapperCustom itemsMapperCustom;
@Override
public List finditemsList(ItemsQueryVo itemsQueryVo) throws Exception {
List list=itemsMapperCustom.finditemsList(itemsQueryVo);
return list;
}
}
视图层jsp页面: itemsList.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
查询商品列表
<%----%>
测试方法: 浏览器输入:http://localhost:8080/queryItems.action
写批量删除前先记录一个js动态修改表单的报错:
js的代码:
开始时我写成
document.itemsForm.action ="/xxxxx.action";
document.itemsForm.submit ;
我在浏览器输入的地址的是:http://localhost:8080/queryItems.action
访问到页面后,我点击按钮,浏览器地址变为:http://localhost:8080/queryItems.action#(但仍能访问我的页面),后台报错:
cann't set property 'action' of null;
这样写当然是错的了,但有的真能正常无误的运行,不知为啥,
找到原因了,如果要 document.itemsForm.action ="/xxxxx.action";,则要给form增加name属性,及改成