奋斗是表现给自己的
Example类是指定构建一个动态的where子句
mybatis的配置文件可以使用mybatis-generator工具生成
它就可以帮我们生成example类
配置网上都有 这里具体说一下里面句子的使用主要说一个属性id
1根据名字查询信息@RequestMapping(value = "/get/{name}", method = RequestMethod.GET)
@ResponseBody public Object index1(@PathVariable("name") String name) {
HomeExample h1 = new HomeExample();
h1.createCriteria().andHomelinkEqualTo(name);
List homeList = homeService.selectHomeByExample(h1);
return homeList; }
2,根据两个字段来查询信息 这里用到了 and关键词 查询name和name2都有的信息@RequestMapping(value = "/get/{name}/{names}", method = RequestMethod.GET)
@ResponseBody public Object index2(@PathVariable("name1") String name,@PathVariable("name2") String names) {
HomeExample h2 = new HomeExample(); h2.or().andHomelinkEqualTo(name1).andHomedescEqualTo(name2);
List homeList = homeService.selectHomeByExample(h2);
return homeList; }
3,这里用到between关键词查询ID在1——100之间的信息@RequestMapping(value = "/get/", method = RequestMethod.GET)
@ResponseBody public Object index3() {
HomeExample h3 = new HomeExample();
h3.createCriteria().andIdBetween(1, 100);
List homeList = homeService.selectHomeByExample(h3);
return homeList; }
4,这里用到 >符号来判断ID大于100的信息 其他> >=<=都一样@RequestMapping(value = "/get/", method = RequestMethod.GET)
@ResponseBody public Object index4() {
HomeExample h4= new HomeExample();
h4.createCriteria().andIdGreaterThan(100);
List homeList = homeService.selectHomeByExample(h4);
return homeList; }
5,这里用到了like模糊查询 查询有li的信息 注意拼接%符号@RequestMapping(value = "/get/", method = RequestMethod.GET,)
@ResponseBody public Object index5() {
HomeExample h5 = new HomeExample();
h5.createCriteria().andHomedescLike("%"+"li"+"%");
List homeList = homeService.selectHomeByExample(h5);
return homeList; }