MyBatis中的查询语句
<!-- 取一个 -->
<select id="query" parameterType="map" resultType="map">
select menu_id, menu_name, parent_id, order_num
from sys_menu
where menu_id=#{menuId}
</select>
<!-- 取全部 -->
<select id="queryList" parameterType="map" resultType="map">
select menu_id, menu_name, parent_id, order_num
from sys_menu
</select>
Mapper中映射的方法
//取一个
Map<String,Object> query(Map<String,Object> paramMap);
//取全部
List<Map<String,Object>> queryList(Map<String,Object> paramMap);
Controller测试
@RestController
@RequestMapping("/")
public class TestController {
@Autowired
private SysMenuMapper sysMenuMapper;
@RequestMapping("test")
public Object httpTest(Long menuId){
Map<String, Object> paramMap = new HashMap<>();
if(StringUtils.isEmpty(menuId)){
List<Map<String, Object>> maps = sysMenuMapper.queryList(paramMap);//取全部
return maps;
}else{
paramMap.put("menuId",menuId);
Map<String, Object> query = sysMenuMapper.query(paramMap);//取一个
return query;
}
}
}
取全部返回值:http://localhost:8080/test
取一个返回值:http://localhost:8080/test?menuId=100
//一个查询返回 就是一个Map,查询出来的结果 就是一个个键值对,键:属性名,值:查询的数据
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("parent_id","1");
paramMap.put("menu_name","用户管理");
paramMap.put("order_num","1");
paramMap.put("menu_id","100");