标签:hide 相同 obj 分表 for ble doctype play inf
package com.xuweiwei.mybatis.mapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.annotations.Param; public interface EmployeeMapper { Employee fineEmployeeByIdAndName(@Param("id") Integer id, @Param("lastName") String lastName); }
<?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"> <!--namespace命名空间 指定接口的全类名--> <mapper namespace="com.xuweiwei.mybatis.mapper.EmployeeMapper"> <select id="fineEmployeeByIdAndName" resultType="com.xuweiwei.mybatis.pojo.Employee"> select * from employee where id = ${id} and last_name = #{lastName} </select> </mapper>
package com.xuweiwei.mybatis.test; import com.xuweiwei.mybatis.mapper.EmployeeMapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Test; import java.io.IOException; import java.io.InputStream; public class MybatisTest { /** * 测试增加 * @throws IOException */ @Test public void test() throws IOException { /** * 创建SqlSessionFactory对象 */ String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); /** * 创建SqlSession */ SqlSession sqlSession = sqlSessionFactory.openSession(true); EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Employee employee = employeeMapper.fineEmployeeByIdAndName(1, "许威威"); System.out.println(employee); sqlSession.close(); } }
select * from ${year}_salary;
select * from employee order by ${orderColumn} ${order}
select * from ${tableName}
package com.xuweiwei.mybatis.mapper; import com.xuweiwei.mybatis.pojo.Employee; import java.util.List; public interface EmployeeMapper { List<Employee> findEmployeeListLikeLastName(String lastName); }
<?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"> <!--namespace命名空间 指定接口的全类名--> <mapper namespace="com.xuweiwei.mybatis.mapper.EmployeeMapper"> <select id="findEmployeeListLikeLastName" resultType="com.xuweiwei.mybatis.pojo.Employee"> select * from employee where last_name like #{lastName} </select> </mapper>
package com.xuweiwei.mybatis.test; import com.xuweiwei.mybatis.mapper.EmployeeMapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Test; import java.io.IOException; import java.io.InputStream; import java.util.List; public class MybatisTest { /** * 测试增加 * @throws IOException */ @Test public void test() throws IOException { /** * 创建SqlSessionFactory对象 */ String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); /** * 创建SqlSession */ SqlSession sqlSession = sqlSessionFactory.openSession(true); EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); List<Employee> employeeList = employeeMapper.findEmployeeListLikeLastName("%许%"); for (Employee employee : employeeList) { System.out.println(employee); } sqlSession.close(); } }
package com.xuweiwei.mybatis.mapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.annotations.ResultType; import org.apache.ibatis.annotations.Select; import java.util.List; public interface EmployeeMapper { @ResultType(Employee.class) @Select(" select * from employee where id = #{id} ") List<Employee> findEmployeeListLikeLastName(String lastName); }
package com.xuweiwei.mybatis.mapper; import java.util.Map; public interface EmployeeMapper { Map<String,Object> selectEmployeeById(Integer id); }
<?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"> <!--namespace命名空间 指定接口的全类名--> <mapper namespace="com.xuweiwei.mybatis.mapper.EmployeeMapper"> <select id="selectEmployeeById" resultType="java.util.Map"> select * from employee where id = #{id} </select> </mapper>
package com.xuweiwei.mybatis.test; import com.xuweiwei.mybatis.mapper.EmployeeMapper; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Test; import java.io.IOException; import java.io.InputStream; import java.util.Map; public class MybatisTest { /** * 测试增加 * * @throws IOException */ @Test public void test() throws IOException { /** * 创建SqlSessionFactory对象 */ String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); /** * 创建SqlSession */ SqlSession sqlSession = sqlSessionFactory.openSession(true); EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Map<String, Object> map = employeeMapper.selectEmployeeById(1); for (Map.Entry<String, Object> m : map.entrySet()) { System.out.println("key:" + m.getKey()); System.out.println("value:" + m.getValue()); } sqlSession.close(); } }
package com.xuweiwei.mybatis.mapper; import org.apache.ibatis.annotations.ResultType; import org.apache.ibatis.annotations.Select; import java.util.Map; public interface EmployeeMapper { @ResultType(Map.class) @Select("select * from employee where id = #{id}") Map<String,Object> selectEmployeeById(Integer id); }
package com.xuweiwei.mybatis.mapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.annotations.MapKey; import java.util.Map; public interface EmployeeMapper { /** * 使用注解MapKey告诉Mybatis那个是key * @return */ @MapKey("id") Map<Integer, Employee> findEmployeeMap(); }
<?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"> <!--namespace命名空间 指定接口的全类名--> <mapper namespace="com.xuweiwei.mybatis.mapper.EmployeeMapper"> <!--这边的resultType实际测试下来既可以是Map中元素Employee也可以是java.util.Map--> <select id="findEmployeeMap" resultType="com.xuweiwei.mybatis.pojo.Employee"> select * from employee </select> </mapper>
package com.xuweiwei.mybatis.test; import com.xuweiwei.mybatis.mapper.EmployeeMapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Test; import java.io.IOException; import java.io.InputStream; import java.util.Map; public class MybatisTest { /** * 测试增加 * * @throws IOException */ @Test public void test() throws IOException { /** * 创建SqlSessionFactory对象 */ String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); /** * 创建SqlSession */ SqlSession sqlSession = sqlSessionFactory.openSession(true); EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Map<Integer, Employee> employeeMap = employeeMapper.findEmployeeMap(); System.out.println(employeeMap); sqlSession.close(); } }
package com.xuweiwei.mybatis.mapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.ResultType; import org.apache.ibatis.annotations.Select; import java.util.Map; public interface EmployeeMapper { @MapKey("id") @ResultType(Map.class) @Select(" select * from employee ") Map<Integer, Employee> findEmployeeMap(); }
标签:hide 相同 obj 分表 for ble doctype play inf
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/10171458.html