entity:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
private Integer id;
private String username;
private String password;
private String phone;
private String address;
}
dao接口:
public interface UserDAO {
List<User> selectAllByNameAndPhone(String username,String phone);
List<User> selectAllByDTO(UserDTO userDTO);
List<User> selectByMap(Map<String,String> map);
User selectById(Integer id);
List<User> selectByName(String username);
List<User> orderByColumn(String column);
}
mapper.xml映射文件:
<!-- <select id="selectAllByNameAndPhone" resultType="user">-->
<!-- <include refid="baseQuery"/> where username like concat('%',#{username},'%') and phone like concat('%',#{phone},'%')-->
<!-- </select>-->
<select id="selectAllByNameAndPhone" resultType="user">
<include refid="baseQuery"/> where username like concat('%',#{arg0},'%') and phone like concat('%',#{arg1},'%')
</select>
<!-- <select id="selectAllByNameAndPhone" resultType="user">-->
<!-- <include refid="baseQuery"/> where username like concat('%',#{param1},'%') and phone like concat('%',#{param2},'%')-->
<!-- </select>-->
<!-- <select id="selectAllByNameAndPhone" resultType="user">-->
<!-- <include refid="baseQuery"/> where username like concat('%',#{arg0},'%') and phone like concat('%',#{param2},'%')-->
<!-- </select>-->
测试类:
@Test
public void selectAllByNameAndPhone(){
List<User> userList = userDAO.selectAllByNameAndPhone("sm", "4");
userList.forEach(System.out::println);
}
@Test
public void selectAllByDTO(){
List<User> userList = userDAO.selectAllByDTO(new UserDTO("sm","4"));
userList.forEach(System.out::println);
}
@Test
public void selectByMap(){
Map<String,String> map = new HashMap<>(2);
map.put("username","smith");
map.put("phone","1");
List<User> userList = userDAO.selectByMap(map);
userList.forEach(System.out::println);
}
测试结果: