VUE表單校驗:某欄位有可能需要校驗,也有可能不用校驗
阿新 • • 發佈:2022-05-08
MyBatis介面方法中可以接收各種各樣的引數,MyBatis底層對於這些引數進行不同的封裝處理方式
單個引數:
-
POJO型別:
-
Map集合:
-
Collection:
-
List:
-
Array:
-
其他型別
多個引數:
MyBatis提供了ParamNameResolver類來進行引數封裝
UserMapper.xml
<select id="select" resultType="user"> select * from tb_user where username = #{param1} and password = #{param2}</select>
UserMapper.java類
/* ## MyBatis引數傳遞 MyBatis介面方法中可以接收各種各樣的引數,MyBatis底層對於這些引數進行不同的封裝處理方式 單個引數: 1. POJO型別: 2. Map集合: 3. Collection: 4. List: 5. Array: 6. 其他型別 多個引數:封裝為Map集合,可以使用@Param註解,替換Map集合中預設的arg鍵名 map.put("arg0",引數值1) map.put("param1",引數值1) map.put("param2",引數值2) map.put("arg1",引數值2) ----------------------@Param("username") map.put("username",引數值1) map.put("param1",引數值1) map.put("param2",引數值2) map.put("arg1",引數值2) MyBatis提供了ParamNameResolver類來進行引數封裝*/ User select(@Param("username") String username, String password);
UserMapperTest測試類
@Test public void testSelect() throws IOException { //1.獲取SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory= new SqlSessionFactoryBuilder().build(inputStream); //2.獲取SqlSession物件 //SqlSession sqlSession = sqlSessionFactory.openSession(); SqlSession sqlSession = sqlSessionFactory.openSession(true); //3.獲取Mapper介面的代理物件 UserMapper userMapper = sqlSession.getMapper(UserMapper.class); //4.執行方法 String username = "zhangsan"; String password = "123"; User user = userMapper.select(username, password); System.out.println(user); //提交事務 sqlSession.commit(); //5.釋放資源 sqlSession.close(); }
MyBatis引數傳遞
MyBatis介面方法中可以接收各種各樣的引數,MyBatis底層對於這些引數進行不同的封裝處理方式
單個引數:
1. POJO型別:直接使用,屬性名和引數佔位符名稱一致
2. Map集合:直接使用,鍵名和引數佔位符名稱一致
3. Collection:封裝為Map集合
map.put("arg0",collection集合);
map.put("collection",collection集合);
4. List:
map.put("arg0",list集合);
map.put("collection",list集合);
map.put("list",list集合);
5. Array:封裝為map集合
map.put("arg0",陣列);
map.put("array",陣列);
6. 其他型別: 直接使用
多個引數:封裝為Map集合,可以使用
註解哪些地方需要新增:Collection,List,Array,多個引數。