Spring MVC 学习笔记(一) 基于spring2.5的纯xml配置

写在前面的小尾巴 其实这个还有spring都是看尚学堂的视频 基本差不离 人家交的就是好 恩 这个就是做个学习笔记什么的 以上

常见MVC框架比较

运行性能上: Jsp+servlet>struts1>spring mvc>struts2+freemarker>>struts2,ognl,值栈。 开发效率上,基本正好相反。值得强调的是,spring mvc开发效率和struts2不相上下。

Struts2的性能低的原因是因为OGNL和值栈造成的。所以,,如果你的系统并发量高,可以使用freemaker进行显示,而不是采用OGNL和值栈。这样,在性能上会有相当大得提高。

本篇基于xml配置 集成hibernate spring MVC+hibernate+spring的开发架构

建立web项目

导入jar包(spring.jar, spring-webmvc.jar, commons-logging.jar。其他jar包为hibernate相关jar包)

3.在web—inf目录下配置web.xml文件 同时这里的其他的层xml配置文件采取同级目录

==”http://www.w3.org/2001/XMLSchema-instance”xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee”>>>org.springframework.web.servlet.DispatcherServlet>contextConfigLocation>>>*.do>

4 . 增加web-config.xml(这里包含spring mvc相关的相关配置)

==” “>===>===>===>==></bean></beans>

5 . 在WEB-INF下增加service-config.xml(这里包含service层类的相关配置)

==” “>==></bean></beans>

6 . 在WEB-INF下增加hib-config.xml(这里包含spring集成hibernate相关的配置)

===”http://www.springframework.org/schema/context”xsi:schemaLocation=” http://www.springframework.org/schema/txhttp://www.springframework.org/schema/aop “>/>==>==>=>=====”hibernate.dialect”>org.hibernate.dialect.MySQLDialect==>>com.sxt.po> ==>==>==>===> ===”NOT_SUPPORTED” /><!– get开头的方法不需要在事务中运行 。有些情况是没有必要使用事务的,比如获取数据。开启事务本身对性能是有一定的影响的–>> </tx:advice> </beans>

7 .在WEB-INF下增加dao-config.xml(这里包含dao层类的相关配置)

==” “>==></bean></beans>

8 .建立相关类和包结构,如下图所示

9 .各类代码如下:

package com.sxt.po;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;{@Id@GeneratedValue(strategy=GenerationType.AUTO)private int id;private String uname;() {return id;}(int id) {this.id = id;}public String getUname() {return uname;}(String uname) {this.uname = uname;}}package com.sxt.dao;import org.springframework.orm.hibernate3.HibernateTemplate;import com.sxt.po.User;{private HibernateTemplate hibernateTemplate;(User u){System.out.println(“UserDao.add()”);hibernateTemplate.save(u);}public HibernateTemplate getHibernateTemplate() {return hibernateTemplate;}(HibernateTemplate hibernateTemplate) {this.hibernateTemplate = hibernateTemplate;}}package com.sxt.service;import com.sxt.dao.UserDao;import com.sxt.po.User;{private UserDao userDao;(String uname){System.out.println(“UserService.add()”);User u = new User();u.setUname(uname);userDao.add(u);}public UserDao getUserDao() {return userDao;}(UserDao userDao) {this.userDao = userDao;}}package com.sxt.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller;import com.sxt.service.UserService;{private UserService userService;@Overridepublic ModelAndView handleRequest(HttpServletRequest req,HttpServletResponse resp) throws Exception {System.out.println(“HelloController.handleRequest()”);req.setAttribute(“a”, “aaaa”);userService.add(req.getParameter(“uname”));return new ModelAndView(“index”);}public UserService getUserService() {return userService;}(UserService userService) {this.userService = userService;}}

那些曾经以为念念不忘的事情就在我们念念不忘的过程里,被我们遗忘了。

Spring MVC 学习笔记(一) 基于spring2.5的纯xml配置

相关文章:

你感兴趣的文章:

标签云: