SSM框架通过姓名和ID进行查找
SSM框架通过姓名和学号进行查找
接口文件StudentDao和映射文件StudentDao.xml
public interface StudentDao {public List findStudent(Map map);}
通过姓名和学号进行查询
地址接口文件和映射文件AddressMapper和AddressMapper.xml
`public interface AddressMapper {
public Address findById(Integer id);
}`
接口文件StudentService和定义查询的方法
public interface StudentService {public List findStudent(Map map);}
``
@Autowired
private StudentDao studentdao;public List findStudent(Map map) {List students=studentdao.findStudent(map);return students;
}
控制器类StudentController
@Controller
public class StudentController {@Autowiredprivate StudentService studentService;@RequestMapping("/info")public String findStudentById(Model model,Student student) {Map map=new HashMap();String name=student.getName();String classId=student.getClassId();map.put("name", "%"+name+"%");map.put("classId", classId);List student1 = studentService.findStudent(map);model.addAttribute("student",student1);return "student";}
}
index.jsp和student.jsp页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
id 姓名 性别 班级 学号 住址 <%-- ${s} --%>${s.id} ${s.name} ${s.sex} ${s.classname} ${s.classId} ${s.address.shi}
返回
运行结果


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
