不使用mapper接口实现直接使用命名空间mybatis

tech2023-11-08  91

@Override public int worTestAuthor() { SqlSession sqlSession = null; try { sqlSession = MybatisUtil.getSqlSession(); Map map = sqlSession.selectOne("org.alien.mybatis.samples.mapper.AuthorMapper.workTest", null); //注意map为空的情况 String email = (String) map.get("email"); return 1; } finally { if (sqlSession != null) { sqlSession.close(); } } } <?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="org.alien.mybatis.samples.mapper.AuthorMapper"> <select id="workTest" resultType="java.util.LinkedHashMap"> select bio from author; </select> </mapper> <mappers> <mapper resource="org/alien/mybatis/samples/mapper/AuthorMapper.xml"/> </mappers>

 

转载地址:https://www.kancloud.cn/digest/andyalien-mybatis/190186(这里没有,这里是使用mapper的方式,是工作直接使用)

最新回复(0)