【SSM_SpringMVC】学习笔记03_SSM三大框架整合-配置-参数绑定

本文详细介绍了SSM(Spring、SpringMVC、MyBatis)三大框架的整合过程,包括项目创建、配置文件设置、数据库配置、注解扫描等关键步骤。同时,深入探讨了参数绑定的多种方式,如默认参数、基本数据类型、bean对象、包装类参数绑定,以及解决中文乱码问题的方法。

一、SSM三大框架整合-配置

1、创建项目,导包

2、配置web.xml:配置springmvc前端控制器、读取spring配置文件、设置页面拦截规则

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>ssm_project_springmvc</display-name>
  <!-- 配置springmvc前端控制器 和读取配置文件 -->
  <servlet>
  	<servlet-name>springmvc</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<!-- 读取配置文件 -->
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>classpath:applicationContext.xml</param-value>
  	</init-param>
  </servlet>
  
  <servlet-mapping>
  	<!-- 拦截规则 -->
  	<servlet-name>springmvc</servlet-name>
  	<url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

3、数据库配置文件db.properties、spring配置文件applicationContext.xml

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm
jdbc.user=root
jdbc.password=root

 数据库配置连接、注解扫描、事务(事务核心管理器、注解事务)、视图解析器、Mybatis、Mapper动态扫描。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
	
	<!-- 读取db.properties文件信息 -->
	<context:property-placeholder location="db.properties"/>
	
	<!-- 配置连接池 -->
	<!-- 配置c3p0连接池 -->
	<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClass}"/>
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>
		<property name="user" value="${jdbc.user}"/>
		<property name="password" value="${jdbc.password}"/>
	</bean>
	
	<!-- 开启注解扫描 -->
	<context:component-scan base-package="com.dunka"/>
	
	<!-- 事务核心管理器 -->
	<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
	</bean>
	<!-- 开启注解事务 -->
	<tx:annotation-driven/>
	
	<!-- 配置视图解析器 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/"/>
		<property name="suffix" value=".jsp"/>
	</bean>
	
	<!-- 配置Mybatis -->
	<bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"/>
		<!-- 配置别名,就不用另起炉灶太麻烦了 -->
		<property name="typeAliasesPackage" value="com.dunka.bean"/>
	</bean>
	<!-- Mapper工厂  mapper动态代理开发 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.dunka.mapper"/>
	</bean>
	
</beans>

4、准备测试用例,以上篇的例子为数据。

Mapper:

/**
 * 
 * @author Dunka
 * @Time   2019年2月28日
 * @Todo   ItemMapper
 */
public interface ItemMapper {
	//查询所有游戏
	public List<ItemInfo> selectAll();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  <mapper namespace="com.dunka.mapper.ItemMapper">
  	<select id="selectAll" resultType="ItemInfo">
  		select * from item_info
  	</select>
  </mapper>

Service:

public interface ItemService {
	   //查询所有游戏
		public List<ItemInfo> selectAll();
}
@Service
public class ItemServiceImpl implements ItemService {

	@Autowired
	private ItemMapper mapper; 
	@Override
	public List<ItemInfo> selectAll() {
		return mapper.selectAll();
	}

}

Controller:

@Controller
@RequestMapping("/item/")
public class ItemController {
	
	@Autowired
	private ItemService service;
	@RequestMapping("allList.do")
	public ModelAndView list() {
		ModelAndView mav = new ModelAndView();
		
		//查询
		List<ItemInfo> itemList = service.selectAll();
		//将结果赋值给ModelAndView
		mav.addObject("itemList", itemList);
		//将视图名设置
		mav.setViewName("item_list");
		return mav;
	}
}

Tomcat跑起来,ok。

二、参数绑定

1、默认参数绑定

//默认参数绑定
	@RequestMapping("select.do")
	public String select(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model model) {
		//获取参数
		String id = request.getParameter("id");
		//查询
		ItemInfo itemInfo = service.selectItemInfoById(id);
		
		List<ItemInfo> itemList = new ArrayList<ItemInfo>();
		itemList.add(itemInfo);
		//传回对象
		model.addAttribute("itemList", itemList);
		//设置视图名
		return "item_list";
	}

2、基本数据类型参数绑定

//基本类型 参数绑定
	@RequestMapping("delete.do")
	//public String delete(@RequestParam(value="id",required=false,defaultValue="5")String itemId) {
	public String delete(String id) {
		System.out.println("delete id:"+id);
		//删除
		service.deleteById(id);
		//重定向
		return "redirect:allList.do";
		
	}

3、bean对象参数绑定

//bean对象 参数绑定
	@RequestMapping("save.do")
	public String save(ItemInfo itemInfo) {
		System.out.println(itemInfo);
		//保存对象
		service.save(itemInfo);
		//重定向
		return "redirect:allList.do";
		
	}

4、包装类参数绑定

//包装类 参数绑定
	@RequestMapping("selectByVo.do")
	public String selectByVo(ItemInfoVo vo, Model model) {
		System.out.println("ItemInfoVo:"+vo.getItemInfo());
		//获取到对象参数
		List<ItemInfo> itemList = service.selectByVo(vo);
		//查询
		model.addAttribute("itemList", itemList);
		//设置视图名
		return "item_list";
	}

5、解决参数绑定中post提交方法中的“中文乱码”问题--web.xml

  <!-- 拦截器 解决post提交 中文乱码问题 -->
  <filter>
  	<filter-name>encoding</filter-name>
  	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  	<init-param>
  		<param-name>encoding</param-name>
  		<param-value>utf-8</param-value>
  	</init-param>
  </filter>
  <filter-mapping>
  	<!-- 拦截规则  拦截全部 /*-->
	<filter-name>encoding</filter-name>
	<url-pattern>*.do</url-pattern>
  </filter-mapping>
  

 

### 光流法C++源代码解析与应用 #### 光流法原理 光流法是一种在计算机视觉领域中用于追踪视频序列中运动物体的方法。它基于亮度不变性假设,即场景中的点在时间上保持相同的灰度值,从而通过分析连续帧之间的像素变化来估计运动方向和速度。在数学上,光流场可以表示为像素位置和时间的一阶导数,即Ex、Ey(空间梯度)和Et(时间梯度),它们共同构成光流方程的基础。 #### C++实现细节 在给定的C++源代码片段中,`calculate`函数负责计算光流场。该函数接收一个图像缓冲区`buf`作为输入,并初始化了几个关键变量:`Ex`、`Ey`和`Et`分别代表沿x轴、y轴和时间轴的像素强度变化;`gray1`和`gray2`用于存储当前帧和前一帧的平均灰度值;`u`则表示计算出的光流矢量小。 #### 图像处理流程 1. **初始化和预处理**:`memset`函数被用来清零`opticalflow`数组,它将保存计算出的光流数据。同时,`output`数组被填充为白色,这通常用于可视化结果。 2. **灰度计算**:对每一像素点进行处理,计算其灰度值。这里采用的是RGB通道平均值的计算方法,将每个像素的R、G、B值相加后除以3,得到一个近似灰度值。此步骤确保了计算过程的鲁棒性和效率。 3. **光流向量计算**:通过比较当前帧和前一帧的灰度值,计算出每个像素点的Ex、Ey和Et值。这里值得注意的是,光流向量的小`u`是通过`Et`除以`sqrt(Ex^2 + Ey^2)`得到的,再乘以10进行量化处理,以减少计算复杂度。 4. **结果存储与阈值处理**:计算出的光流值被存储在`opticalflow`数组中。如果`u`的绝对值超过10,则认为该点存在显著运动,因此在`output`数组中将对应位置标记为黑色,形成运动区域的可视化效果。 5. **状态更新**:通过`memcpy`函数将当前帧复制到`prevframe`中,为下一次迭代做准备。 #### 扩展应用:Lukas-Kanade算法 除了上述基础的光流计算外,代码还提到了Lukas-Kanade算法的应用。这是一种更高级的光流计算方法,能够提供更精确的运动估计。在`ImgOpticalFlow`函数中,通过调用`cvCalcOpticalFlowLK`函数实现了这一算法,该函数接受前一帧和当前帧的灰度图,以及窗口小等参数,返回像素级别的光流场信息。 在实际应用中,光流法常用于目标跟踪、运动检测、视频压缩等领域。通过深入理解和优化光流算法,可以进一步提升视频分析的准确性和实时性能。 光流法及其C++实现是计算机视觉领域的一个重要组成部分,通过对连续帧间像素变化的精细分析,能够有效捕捉和理解动态场景中的运动信息
微信小程序作为腾讯推出的一种轻型应用形式,因其便捷性与高效性,已广泛应用于日常生活中。以下为该平台的主要特性及配套资源说明: 特性方面: 操作便捷,即开即用:用户通过微信内搜索或扫描二维码即可直接使用,无需额外下载安装,减少了对手机存储空间的占用,也简化了使用流程。 多端兼容,统一开发:该平台支持在多种操作系统与设备上运行,开发者无需针对不同平台进行重复适配,可在一个统一的环境中完成开发工作。 功能丰富,接口完善:平台提供了多样化的API接口,便于开发者实现如支付功能、用户身份验证及消息通知等多样化需求。 社交整合,传播高效:小程序深度嵌入微信生态,能有效利用社交关系链,促进用户之间的互动与传播。 开发成本低,周期短:相比传统应用程序,小程序的开发投入更少,开发周期更短,有助于企业快速实现产品上线。 资源内容: “微信小程序-项目源码-原生开发框架-含效果截图示例”这一资料包,提供了完整的项目源码,并基于原生开发方式构建,确保了代码的稳定性与可维护性。内容涵盖项目结构、页面设计、功能模块等关键部分,配有详细说明与注释,便于使用者迅速理解并掌握开发方法。此外,还附有多个实际运行效果的截图,帮助用户直观了解功能实现情况,评估其在实际应用中的表现与价值。该资源适用于前端开发人员、技术爱好者及希望拓展业务的机构,具有较高的参考与使用价值。欢迎查阅,助力小程序开发实践。资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多啦CCCC梦

你的鼓励将是我最大的创作动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值