目录
一、SpringMVC
1.工作流程:
①DispatcherServlet:接受到浏览器端发送的所有请求
②HandlerMapper处理器映射器:找到@requestMapping对应值
③HandlerAdapter处理器适配器:适配对应的方法调用执行
④modelAndView模型视图对象:方法的返回值
⑤viewResolver解析模型视图对象,得到view,返回给浏览器用户展示;
2.开发流程:
①导入pom依赖
②web.xml中添加核心类配置,DispatcherServlet,指向框架Springmvc.xml的配置文件
③配置Springmvc.xm
配置驱动包扫描<context:component-scan base-package="com.javaxl.ssm"/>
重点:配置本地资源视图解析器
<!--3) ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- viewClass需要在pom中引入两个包:standard.jar and jstl.jar -->
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
添加静态文件映射:
<mvc:resources location="/images/" mapping="/images/**"/>
④controller层,正常开发即可
要通过@controller标记当前类被spring所管理
写方法:@requestMapping
方法会有返回值:“bookList” --> /bookList.jsp
3.常用的注解:
@controller @postMapping 若依
@requestMapping @responseBody-返回json数据
@getMapping @requestBody-接受json数据
@putMapping @pathvariable
@deleteMapping @requestParam
4.springmvc怎么返回数据
转发:"forword:/list"
重定向:"redirect:/list"
二、Mybatis 是什么?
1.ORM 数据库层面的框架
O:Object
R:reference
M:Mapping
2.关联关系的配置
一对一:association javatype
一对多:Collection oftype
3.mapper.xml配置的常用标签有哪些?
if/for
<![CDATA[ ... ]]> 用于解决特殊字符转义的,没有CDATA的话,> < & 等会被当成HTML标签,而不是sql语句的组成部分;
Mybatis中的二级缓存默认关闭的
二级缓存:Mapper级别的缓存,默认关闭
一级缓存:session级别的缓存,默认就是开启的;
重点:
#{...}与${...}传参的区别
#传递参数会自带引号
S不带引号:存在SQL注入的问题,但是也有优点,可以用来做动态列/动态SQL
4.上述的不同,也就决定了$存在SQL注入的风险
UserMapper.xml 前提uid是varchar
select * from user where uid = #{uid} uid='abc' or uid is not null
select * from user where uid = ''abc' or uid is not null'
select * from user where uid = ${uid} uid='abc' or uid is not null
select * from user where uid = 'abc' or uid is not null
<select>
select * from user where uid = #{uid}
</select>
<select id="execute">
${executeSQL}
</select>
<select id="execute">
select ${fieldName} form ${tableName}
</select>
UserMapper.execute("select * from book")
本文详细介绍了SpringMVC的工作流程,从DispatcherServlet接收请求到视图解析器返回浏览器,包括控制器开发和常用注解的使用。同时,探讨了Mybatis作为ORM框架的角色,配置关联关系以及Mapper.xml中的常见标签。特别指出,使用${...}
180

被折叠的 条评论
为什么被折叠?



