1.我们都知道在struts2中为防止浏览器绕过struts过滤器直接请求页面,所以我们都会配置一个拦截所有页面的action,如下:

    <action name="*">
<result>/{1}.jsp</result>
</action>

springmvc中同样可以有这种类似配置如下:

package com.mi.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class TestController { @RequestMapping("/{init}")
public String go(@PathVariable String init){
System.out.println(init);
return init;
}
}

我的请求路径可以是如下类型,http://localhost:8080/ssm(项目名)/xxx.do   这样会请求到名字为xxx页面的jsp上去,很好用,利用@PathVariable注解,在此记录下

2.关于mybatis中xml文件的sql语句的参数类型处置,当sql参数类型为多种不同的基本类型时,比如 id,name,age,这时参数类型应该是parameterType="int,string,int"实际会报错,这里按照此种写法应该写成

parameterType="java...."全类型写法,但是在此可以不用这么麻烦,代码如下

在dao的接口中定义的sql的方法时:

package com.mi.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import com.mi.entity.User; @Repository
public interface UserInfoMapper {
public List<User> queryUserInfo(@Param("beginIndex") int beginIndex,@Param("pageSize") int pageSize);
}

使用@Param参数注解提供声明参数的功能,同时给出参数类型及参数名,即可解决xml中的参数类型声明问题

<?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.mi.dao.UserInfoMapper"> <select id="queryUserInfo" resultType="com.mi.entity.User">
SELECT id,user_name userName,age FROM user_t where 1=1 limit #{beginIndex},#{pageSize}
</select> <!-- <insert id="addUser" parameterType="com.mi.entity.User"
flushCache="true">
INSERT INTO user_t (id,user_name,password,age) VALUES
(#{id},#{userName},#{password},#{age})
</insert> <delete id="deleteUser" parameterType="com.mi.entity.User" flushCache="true">
DELETE FROM user_t where id=#{id}
</delete> <update id="updateUser" parameterType="com.mi.entity.User" flushCache="true">
UPDATE user_t SET user_name = 'zzxy' WHERE id=#{id}
</update> --> </mapper>

关于mybatis的参数2个使用经验(类似于struts2的通配所有页面的action配置,xmlsq语句参数类型为基本类型时的快捷指定办法)的更多相关文章

  1. 获取页面的checkbox,并给参数赋值

    需求: 需要发送的请求:

  2. MyBatis绑定Mapper接口参数到Mapper映射文件sql语句参数

    一.设置paramterType 1.类型为基本类型 a.代码示例 映射文件: <select id="findShopCartInfoById" parameterType ...

  3. 浩哥解析MyBatis源码(十)——Type类型模块之类型处理器

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6715063.html 1.回顾 之前的两篇分别解析了类型别名注册器和类型处理器注册器,此二 ...

  4. MyBatis源码解析(十)——Type类型模块之类型处理器TypeHandler

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6715063.html 1.回顾 之前的两篇分别解析了类型别名注册器和类型处理器注册器,此二 ...

  5. 浩哥解析MyBatis源码(九)——Type类型模块之类型处理器注册器(TypeHandlerRegistry)

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6709157.html 1.回顾 上一篇研究的是类型别名注册器TypeAliasRegist ...

  6. 使用MyBatis时接收值和返回值选择Map类型或者实体类型

    MyBatis作为现近JavaEE企业级项目开发中常用的持久层框架之一,以其简洁高效的ORM映射和高度的SQL的自由性被广大开发人员认可.Mybatis在接收系统传来的参数和返回的参数时主要可以有Ma ...

  7. MyBatis源码解析(九)——Type类型模块之类型处理器注册器(TypeHandlerRegistry)

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6709157.html 1.回顾 上一篇研究的是类型别名注册器TypeAliasRegist ...

  8. mybatis 需要注意的点 MyBatis 插入空值时,需要指定JdbcType (201

    转自:https://blog.csdn.net/snakemoving/article/details/76052875 前天遇到一个问题 异常显示如下: 引用 Exception in threa ...

  9. 自己挖的坑自己填--Mybatis mapper文件if标签中number类型及String类型的坑

    1.现象描述 (1)使用 Mybatis 在进行数据更新时,大部分时候update语句都需要通过动态SQL进行拼接.在其中,if标签中经常会有 xxx !='' 这种判断,若 number 类型的字段 ...

随机推荐

  1. Qt获取组合键

    CTRL+Enter发送信息的实现 在现在的即时聊天程序中,一般都设置有快捷键来实现一些常用的功能,类似QQ可以用CTRL+Enter来实现信息的发送. 在QT4中,所有的事件都继承与QEvent这个 ...

  2. Socket通信原理探讨(C++为例) good

    http://www.cnblogs.com/xufeiyang/articles/4878096.html http://www.cnblogs.com/xufeiyang/articles/453 ...

  3. mongoDB安装学习

    一: 下载安装 上MongoDB官网 ,下载之后安装 安装好了之后在对应的安装目录下就会看到安装的文件 二:启动 微软徽标+R,输入cmd,首先找到“mongodb”的路径,然后运行mongod开启命 ...

  4. There has been an error processing your request magento

    如果使用magento的过程中,出现以下页面: 说明出现了错误,但是亲,不用紧张,请根据"Error record number:xxxxxxxxx"的数字在网站根目录下的var/ ...

  5. LeetCode Shortest Palindrome

    原题链接在这里:https://leetcode.com/problems/shortest-palindrome/ 题目: Given a string S, you are allowed to ...

  6. How to Detect and Track Object With OpenCV

    http://www.intorobotics.com/how-to-detect-and-track-object-with-opencv/

  7. Speed-BI 云平台视频观看频道

    数据分析的关键,首先是要有数据进行透视分析.大家一般在使用EXCEL透视表进行数据分析时,会通过某个系统,导出类似视频中的数据底稿,然后在此基础上进行各种维度的变换与指标的改变.奥威思必得也有一个类似 ...

  8. Android --Search界面样式

    Lay_Weight 权重属性的使用 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  9. Python模块(MySQLdb)

    MySQLdb模块是python用来连接mysql的第三方模块,安装 pip install mysql-python 连接mysql: 主要两步,建立mysql连接对象.游标对象.再操作数据库 im ...

  10. [OpenCV](1)安装与测试

    1.安装包下载地址:http://opencv.org/downloads.html 2.解压缩到D:\Program Files (x86) 3.添加环境变量:D:\Program Files (x ...