mybatismysql调⽤视图
java代码
@RequestMapping(value = "/testView", method = RequestMethod.GET)
public @ResponseBody String testView(HttpServletRequest request, HttpServletResponse response) throws IOException { Map<String, Object> paraMap = new HashMap<String, Object>();
paraMap.put("userType", "doctor");
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
list = stView(paraMap);
if(list != null && list.size() > 0){
for (int i = 0; i < list.size(); i++) {
System.out.(i));
}
}
return null;
}
mapper
package cn.zsmy.mapper;
import java.util.List;
import java.util.Map;
import ity.User;
import cn.zsmy.form.UserForm;
import cn.zsmy.mapper.base.SimpleMapper;
import p.core.MyBatisRepository;
/
**
* @ClassName: ProcedureMapper
* @Description: 调⽤存储过程与视图
* @author师海明
* @date 2016年6⽉13⽇上午11:52:38
*
*/
@MyBatisRepository
public interface ProcedureMapper extends SimpleMapper<UserForm,User>{
mysql视图和存储过程Map<String, Object> testProcedure(Map<String, Object> paraMap);
List<Map<String, Object>> testView(Map<String, Object> paraMap);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.zsmy.mapper.ProcedureMapper" >
<!-- 调⽤存储过程查询 -->
<select id="testProcedure" parameterType="java.util.Map" statementType="CALLABLE" resultType="java.util.HashMap"> {call loginandreg(
#{out_ret,mode=OUT,javaType=java.lang.Integer,jdbcType=INTEGER},
#{out_desc,mode=OUT,javaType=java.lang.String,jdbcType=VARCHAR},
#{userId,jdbcType=VARCHAR,mode=OUT},
#{user_pwd,jdbcType=VARCHAR,mode=IN},
#{nickname,jdbcType=VARCHAR,mode=IN}
)
}
</select>
<!-- 调⽤视图查询 -->
<select id="testView" parameterType="java.util.Map" resultType="java.util.HashMap">
select username, nickname, dept from test_view where user_type=#{userType}
</select>
</mapper>
视图
DROP VIEW IF EXISTS `palm_2_0_16`.`test_view`;
CREATE VIEW `palm_2_0_16`.`test_view`
AS
SELECT u.username,u.nickname,d.dept, u.user_type FROM tb_user u, tb_doctor d WHERE d.id=u.id ;
备注:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论