前端之家收集整理的这篇文章主要介绍了
控制层 Controller 调用 xml,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1. java 代码
@ResponseBody
@RequestMapping(value = {"testMap"})
public Object testMap( HttpServletRequest request,HttpServletResponse response,Model model) throws Exception {
sqlSessionFactory sessionFactory = sqlSessionfactorybean.getObject();
sqlSession session = sessionFactory.openSession(); // 打开连接
Map sMap=new HashMap<String,String >();
sMap.put("id","72b499e409b34c12883fa73cba9ed905") ;
// Object resultObject = session.selectOne("timeUtil.findUserById",sMap);
sMap.put("procInsId","47184536c2c24584a58bad2add714cdc") ;
Object resultObject = session.selectOne("timeUtil.findBeanByProIns",sMap);
session.close(); /// 关闭连接
String string = resultObject.toString();
//String json = JsonMapper.getInstance().toJson(resultObject);
return resultObject;
}
2. xml 配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="timeUtil">
<select id="findUserById" resultType="Evection" >
SELECT * FROM FLOW_EVECTION where id= #{id}
</select>
<select id="findBeanByProIns" resultType="java.util.HashMap" >
SELECT * FROM FLOW_EVECTION where proc_ins_id= #{procInsId}
</select>
</mapper>