1、引入相应js:
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/autocomplete.js" ></script>
2、前端部分:
<div class="col-xs-4">
<label name="ModelColon" class="col-sm-4">型 号:</label>
<div class="col-sm-8">
<input type="text" id="model" name="model" οnkeyup="autoCompleteModel.start(event)" value="${(faultCodeVo.model)!''}" class="form-control"
autocomplete="off" >
<div class="auto_hidden" id="autoModel"></div>
<script type="text/javascript">
var modelData = getModel();
function getModel(){
var result;
var model = $("#model").val();
$.ajax({
type : "POST",
url : "faultCodeInfo/getModelList.do",
dataType : "json",
data : {"model":model},
cache : false,
async:false,
success : function(datas) {
result = [datas.length];
for(var i=0;i<datas.length;i++){
result[i] = datas[i].model;
}
}
});
return result;
}
var autoCompleteModel=new AutoComplete('model','autoModel',modelData);
</script>
</div>
</div>
3、controller层:
/*获取品牌*/
@RequestMapping("getBrandList")
@ResponseBody
public List<BrandVo> getBrandList(BrandVo brandVo) {
logger.debug("获取品牌");
PageResult<BrandVo> result = new PageResult<BrandVo>();
List<BrandVo> brandVoList = faultCodeService.queryBrand(brandVo);
return brandVoList;
}
4、service层:
List<BrandVo> queryBrand(BrandVo brandVo);
5、接口:
@Override
public List<BrandVo> queryBrand(BrandVo brandVo) {
List<BrandVo> list = faultCodeMapper.queryBrand(brandVo);
return list;
}
6、Mapper:
List<BrandVo> queryBrand(BrandVo brandVo);
7、查询数据库:
<select id="queryBrand" parameterType="com.gzzhongtu.forklift.core.maintain.vo.BrandVo"
resultType="com.gzzhongtu.forklift.core.maintain.vo.BrandVo">
SELECT id,brand FROM t_vehicle_brand
</select>