Spring 集成到web项目中
来源:互联网 发布:淘宝促销时间表 编辑:程序博客网 时间:2024/05/29 15:36
1. 在web.xml中配置实例化spring容器
2. 在controller中获取spring容器实例
<context-param><!-- location of spring config --><param-name>contextConfigLocation</param-name><param-value>classpath:spring.xml</param-value></context-param><!-- initialize spring context--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
2. 在controller中获取spring容器实例
@Controller("accountController") //让spring管理Controller@RequestMapping("/accountController.do")@SessionAttributes({"account"}) //put account to session, //as a result both request and session have the two attribute.public class AccountController {@Resource //自动注入Service实例AccountService accountService;@RequestMapping(params="method=login", method=RequestMethod.POST) public String login(String username, String password, ModelMap map, HttpServletRequest request){Account account = accountService.Login(username, password);if(account!=null){//request.getSession().setAttribute("account", account);System.out.println("Hello "+ username);map.put("message", "welcome "+ username +"!");return "main";}else{map.put("message", "username or password is wrong! ");return "index";}}@RequestMapping(params="method=register", method=RequestMethod.POST)public ModelAndView register(Account account, HttpServletRequest request){ModelAndView mav =new ModelAndView("main");mav.addObject("account", account);try {accountService.reqister(account);} catch (Exception e) {e.printStackTrace();mav.addObject("message", "register failed!");mav =new ModelAndView("account/account_register");}mav.addObject("message", "register successed!");mav =new ModelAndView("main");return mav;}}
阅读全文
0 0
- Spring 集成到web项目中
- 在web项目中集成Spring
- FineReport 集成到web项目
- 将jax-ws webservice集成到web项目中
- jax-ws开发的webservice集成到web项目中
- 集成p6spy到spring中
- Spring Boot集成MyBatis开发Web项目
- 实战-web项目集成spring框架
- editor.md集成到web项目
- FineReport 集成到web项目(二)
- java web项目(spring项目)中集成webservice ,实现对外开放接口
- java web项目(spring项目)中集成webservice ,实现对外开放接口
- java web项目(spring项目)中集成webservice ,实现对外开放接口
- idea java web项目(spring项目)中集成webservice ,实现对外开放接口
- java web项目(spring项目)中集成webservice ,实现对外开放接口
- pushlet 2.0.3 集成 到你的 web 项目中 教程 例子
- Xfire集成到web 项目中遇到的问题 及解决方法
- Xfire集成到web 项目中遇到的问题 及解决方法
- Spring 事务传播属性
- [python]自问自答:python -m参数?
- PCB设计预处理-cadence
- Spring XML配置事务管理
- Spring + hibernate + ehcache
- Spring 集成到web项目中
- shell脚本的命令代换
- Google net v1-v4 paper 简介
- 重定向和转发以及包含的细节
- spring 与struts 和 Hibernate集成时可能遇到的问题
- AngularJS 日期格式化详解
- fabfile 使用
- 3秒钟完成50万条并发日志 文件写入
- ubuntu下命令行设置代理的方法