代码区
packagecn.sxt.action;importjava.util.List;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.context.annotation.Scope;importorg.springframework.stereotype.Controller;importcn.sxt.service.UserService;importcn.sxt.vo.User;
@Controller("userAction")
@Scope("prototype")public classUserAction {private Listlist;
@AutowiredprivateUserService userService;publicString list(){
list=userService.getAll();return "success";
}public ListgetList() {returnlist;
}public void setList(Listlist) {this.list =list;
}publicUserService getUserService() {returnuserService;
}public voidsetUserService(UserService userService) {this.userService =userService;
}
}
UserAction
packagecn.sxt.dao;importjava.util.List;importcn.sxt.vo.User;public interfaceUserDao {public ListgetAll();
}
UserDao
packagecn.sxt.dao.impl;importjava.util.List;importorg.apache.ibatis.session.SqlSessionFactory;importorg.mybatis.spring.support.SqlSessionDaoSupport;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Repository;importcn.sxt.dao.UserDao;importcn.sxt.vo.User;
@Repository("userDao")public class UserDaoImpl extends SqlSessionDaoSupport implementsUserDao{
@Autowired
@Overridepublic voidsetSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {super.setSqlSessionFactory(sqlSessionFactory);
}public ListgetAll() {return this.getSqlSession().selectList("cn.sxt.vo.user.mapper.getAll");
}
}
UserDaoImpl
packagecn.sxt.service;importjava.util.List;importcn.sxt.vo.User;public interfaceUserService {public ListgetAll();
}
UserService
packagecn.sxt.service.impl;importjava.util.List;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importcn.sxt.dao.UserDao;importcn.sxt.service.UserService;importcn.sxt.vo.User;
@Service("userService")public class UserServiceImpl implementsUserService{
@AutowiredprivateUserDao userDao;public voidsetUserDao(UserDao userDao) {this.userDao =userDao;
}public ListgetAll() {returnuserDao.getAll();
}
}
UserServiceImpl
packagecn.sxt.test;importjava.util.List;importorg.springframework.context.ApplicationContext;importorg.springframework.context.support.ClassPathXmlApplicationContext;importcn.sxt.dao.UserDao;public classTest {public static voidmain(String[] args) {
ApplicationContext ac= new ClassPathXmlApplicationContext("applicationContext.xml");
UserDao userDao= (UserDao)ac.getBean("userDao");
List list=userDao.getAll();
System.out.println(list.size());
}
}
Test
packagecn.sxt.vo;public classUser {private intid;privateString name;privateString pwd;public intgetId() {returnid;
}public void setId(intid) {this.id =id;
}publicString getName() {returnname;
}public voidsetName(String name) {this.name =name;
}publicString getPwd() {returnpwd;
}public voidsetPwd(String pwd) {this.pwd =pwd;
}
}
User
/p>
PUBLIC"-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
select*from user
user.mapper.xml
applicationContext.xml
/p>
PUBLIC"-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
mybatis.cfg.xml
/p>
"http://struts.apache.org/dtds/struts-2.3.dtd">
/list.jsp
struts.xml
17ssm_annotation
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
web.xml
String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
My JSP 'index.jsp' starting page编号 | 姓名 | 密码 |
${bean.id } | ${bean.name } | ${bean.pwd } |
list.jsp