web.xml
applicationContext.xml
springmvc-servlet.xml
UserController
package com.ssi.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.ssi.entity.User;
import com.ssi.service.UserService;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/login")
public String login(String username,String password){
boolean isLogin = userService.isLogin(username, password);
if(isLogin){
return "redirect:/getList.do";
}else{
return "login";
}
}
}
EmpController
package com.ssi.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.ssi.entity.Emp;
import com.ssi.service.EmpService;
@Controller
public class EmpController {
@Autowired
private EmpService empService;
@RequestMapping("/getList")
public ModelAndView getEmplist(){
Listlist = empService.getEmpList();
/* 这个写法 和下面是一样的 不过这个你可以传递多个参数到list.jsp页面
* ModelAndView mv =new ModelAndView();
mv.setViewName("list");
mv.addObject("list", list);
return mv;
*/
return new ModelAndView("list", "list", list);
}
}
list.jsp
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
My JSP 'list.jsp' starting page雇员编号姓名工作经理编号入职日期薪资津贴部门编号
${emp.empno}${emp.ename}${emp.job}${emp.mgr}${emp.sal}${emp.deptno} 修改引入类库 fmt标签
引入fmt标签