开发框架
2016-12-05 14:59:39 27 举报
AI智能生成
未完成,欢迎留言
作者其他创作
大纲/内容
web层框架<br>
struts1<br>
springMVC
优点<br>
属于SpringFrameWork的后续产品,已经融合在spring web flow里面,不用整合<br>
使用起来简单<br>
缺点<br>
功能不如struts2强大<br>
应用
1.引入jar包<br>
2.配置核心控制器(前端控制器)<br>
class : DispatcherServlet
web中配置 <servlet><br>
配置servlet启动的优先级<br>
<init-param>下<load-on-startup>1</load-on-startup>
当值为0或者大于0时,容器在应用启动时就加载这个servlet
当是一个负数时或者没有指定时,则指示容器在该servlet被选择时才加载
正数的值越小,启动该servlet的优先级越高
如果值重复也不会出现异常,服务器会自己决定初始化顺序
3.配置文件<br>
位置/文件名 <br>
默认位置 /WEB-INF/
默认文件名 web.xml文件中的servlet-name 加上 '-servlet.xml'<br>
改名改位置 <init-param><br> <param-name>contextConfigLocation</param-name><br> <param-value>/WEB-INF/spring-servlet.xml,/WEB-INF/spring-user.xml</param-value><br> </init-param><br>
多个配置文件 用逗号分隔<br>
启动spring的注解<br>
<context:annotation-config /><br>
文件头部<br>
<?xml version="1.0" encoding="UTF-8"?><br><beans xmlns="http://www.springframework.org/schema/beans" <!--默认命名空间 --><br> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <!-- 命名空间里的元素或者属性必须要以xsi:这种方式来写 --><br> xmlns:p="http://www.springframework.org/schema/p"<br> xmlns:mvc="http://www.springframework.org/schema/mvc"<br> xmlns:context="http://www.springframework.org/schema/context"<br> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd<br> http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd <br> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><br> <!-- 把定义命名空间的schema文件引入,让eclipse能够解析和验证xml文件是否符合语法规范 -->
启动spring bean扫描<br>
<!-- base-package属性:自动扫描base-package包下及其子包下的Java文件,如果扫描到有@Component @Controller @Service等注解的类,则把这些类注册为bean <br> use-default-filters属性:默认为true,意味着会扫描指定包下的全部的标有@Component注解及其子注解@Service @Reposity的类<br> Use-dafault-filters=”false”的情况下:<context:exclude-filter>指定的包不扫描,<context:include-filter>指定的包扫描<br> --><br> <context:component-scan base-package="com.txzb.cfx.controller" /><br> <context:component-scan base-package="com.json" />
开启springMVC的注解<br>
<em style="font-size: 13px; font-style: normal; color: rgb(204, 0, 0); font-family: arial; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">xmlns <br>(xml </em><em style="font-size: 13px; font-style: normal; color: rgb(204, 0, 0); font-family: arial; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Namespaces</span> xml命名空间)<br></em>
1. 定义<br>
位置 最外层的<span style="color: rgb(102, 102, 102); font-family: 宋体; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);"></span>beans开始标签中<br>
<span style="color: rgb(102, 102, 102); font-family: 'Times New Roman'; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">xmlns:namespace-prefix="namespaceURI"</span>
使用xmlns的必要性: <span style="word-wrap: break-word; color: rgb(102, 102, 102); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-family: 宋体; background-color: rgb(255, 255, 255);">命名空间被定义之后,所有带有相同前缀的子元素都会与同一个命名空间相关联。避免</span><span style="word-wrap: break-word; color: rgb(102, 102, 102); font-family: 宋体, Arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" lang="EN-US"><font style="word-wrap: break-word;" face="Times New Roman">XML</font></span><span style="word-wrap: break-word; color: rgb(102, 102, 102); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-family: 宋体; background-color: rgb(255, 255, 255);">解析器对</span><span style="word-wrap: break-word; color: rgb(102, 102, 102); font-family: 宋体, Arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" lang="EN-US"><font style="word-wrap: break-word;" face="Times New Roman">xml</font></span><span style="word-wrap: break-word; color: rgb(102, 102, 102); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-family: 宋体; background-color: rgb(255, 255, 255);">解析时的发送名字冲突</span>
2.使用<br>
<span style="word-wrap: break-word; color: rgb(102, 102, 102); font-family: 宋体, Arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" lang="EN-US"><font style="word-wrap: break-word;" face="Times New Roman">namespace-prefix</font></span><span style="word-wrap: break-word; color: rgb(102, 102, 102); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: auto; text-align: left; text-indent: 28px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-family: 宋体; background-color: rgb(255, 255, 255);">(前缀):属性</span>
方式一: <mvc:annotation-driven/>
方式二:AnnotationMethodHandlerAdapter
4.普通java类<br>
1.类: 普通java类即可,不用继承<br>
2.方法: 返回值、方法名、参数列表都任意 建议返回String,作为返回路径<br>
@Controller 表示此类是控制层<br>
@RequestMapping 配置类或方法的访问路径<br>
value="" 访问路径<br>
method=RequestMethod.GET/POST/PUT/DELETE
param="method=delete" 访问方法 ?method=delete<br>
@RequestParam<br>
@PathVariable<br>
@ModelAttribute 获取请求参数<br>
@ExceptionHandler({NullPointerException.class}) 声明式异常处理<br>
获取客户端提交的数据<br>
1. HttpServletRequest request 2.request.getParameter("username");<br>
1. @RequestParam("username") String name, int age 2.直接使用<br>
1. @RequestMapping("/login/{name}/{age}") 2. @PathVariable("name") String name, @PathVariable("age") int age 3.直接使用<br>
参数列表中加@ModelAttribute User user 获取请求参数<br>
注意Date类型 要写转换器<br>
将值返回给客户端<br>
request.setAttribute("error", "username or passoword is wrong !")
ModelMap map<br>
ModelAndView 返回类型 先new, 再设置视图setViewName("/index.jsp"),设置addObject("name", "此处放值")<br>
Controller中使用Session<br>
通过request获取<br>
类上使用@SessionAttributes("name", "list") 的ModelMap中保存的数据 在session中也会保存一份<br>
跳转<br>
return 默认转发<br>
重定向 return "redirect: index.jsp"<br>
配置视图 前缀后缀设置 InternalResourceViewResolver<br>
声明式异常处理<br>
文件上传<br>
整合
构造restful风格<br>
<span style="font-family:Arial; font-size:14px; line-height:21px">浏览器form表单只支持get/post请求,不支持put/delete请求<br></span>
jsp
子主题
web.xml<br>
子主题
<span style="color:rgb(0,128,0)">静态资源映射</span>
<span style="color:rgb(0,128,0)">从/改为/static/目录</span>
JSF/JBOSS Seam<br>
webwork - struts2
Tapestry<br>
DAO层框架<br>
JDBC
传统的操作数据库的类 - java database connectivity java数据库连接
Hibernate
hibernate在C,U,D的时候省效率,但对复杂的查询的场景,例如报表统计,就不太好控制
优点
缺点
mybatis<br>
iBatis,MyBatis是JDBC的封装一层的框架,什么都要自己写SQL,不像Hibernate那样自动生成,而且跨数据库需要改写一些SQL语句,但胜在sql可以自己控制,可以优化SQL来达到提高查询效率
优点
缺点
dbutil<br>
spring jdbc<br>
spring<br>
子主题
子主题
web前端框架<br>
子主题
子主题
编码过滤器<br>
0 条评论
下一页