MyBatis+MySQL 传入参数
2016-01-29 16:05
369 查看
1.String 单独传参
public List<Teacher> selectTeacher(@Param(value="id") String id,@Param(value="sex") String sex);
2,Mapper位置传参数
#{0}
#{1}
3,Map出入参数
java:
Map<String,Object> par = new HashMap<>();
par.put("userId",userId);
par.put("orderSn",orderSn);
return marketCommentDao.getCommentByUid(par);
xml:
<select id="getOrderCountForPlat" parameterType="map" >
4,传入数组参数
@RequestMapping(value = "/applyJob", method = RequestMethod.POST,consumes = "application/json")
@ResponseBody
public DataTransferObject applyJob(@RequestBody Integer[] jobIds,HttpServletRequest request) {
Integer userId = SessionUtil.getUserId(request);
return jobProxy.applyJob(jobIds,userId);
}
5,java对象中mappr属性传参
java中的代码
private Map<String, Object> params = new HashMap<String, Object>();
xml中代码
<if test="params != null">
<if test="params.get('excludeId') != null">
or n.id = ${params.get('excludeId')}
</if>
</if>
6,JsonObject传入参数
java代码:
@RequestMapping(value = "/page",method = RequestMethod.POST)
@ResponseBody
public DataTransferObject page(@RequestBody JSONObject param){
java取参数: int pageNo = Integer.valueOf(param.get("pageNo").toString());
int pageSize = Integer.valueOf(param.get("pageSize").toString());
String content = param.optString("content", ""); //推荐
Integer result = param.optInt("result", 0); //推荐
java设置参数:
param.put("start", pageNo * pageSize);
param.put("end", pageSize);
java:判断,取出数组,移除
if (param.has("attributeItemIds")) {
JSONArray attributeItemIds = param.getJSONArray("attributeItemIds");
if (null == attributeItemIds || attributeItemIds.size() == 0) {
param.remove("attributeItemIds");
}
}
entityQO对象传递:
private Integer attributeId;
private JSONArray attributeItemIds;// 兼容web端
xml取出:
1, <select id="phoneListCommodityCompleteInfo" resultType="com.uei.phone.manager.model.market.CommodityVo" parameterType="com.uei.phone.manager.model.market.CommodityQo" >
2, <select id="listCmomodityCompleteInfo" resultType="hashMap" parameterType="org.json.simple.JSONObject" >
取出与遍历
<if test="catagoryId != null and catagoryId != ''">
AND b.catagory_id = #{catagoryId}
</if>
<if test="catagoryIds != null and catagoryIds.size != 0">
AND b.catagory_id IN
<foreach item="catagoryId" index="index" collection="catagoryIds" open="(" separator="," close=")">
#{catagoryId}
</foreach>
</if>
public List<Teacher> selectTeacher(@Param(value="id") String id,@Param(value="sex") String sex);
2,Mapper位置传参数
#{0}
#{1}
3,Map出入参数
java:
Map<String,Object> par = new HashMap<>();
par.put("userId",userId);
par.put("orderSn",orderSn);
return marketCommentDao.getCommentByUid(par);
xml:
<select id="getOrderCountForPlat" parameterType="map" >
4,传入数组参数
@RequestMapping(value = "/applyJob", method = RequestMethod.POST,consumes = "application/json")
@ResponseBody
public DataTransferObject applyJob(@RequestBody Integer[] jobIds,HttpServletRequest request) {
Integer userId = SessionUtil.getUserId(request);
return jobProxy.applyJob(jobIds,userId);
}
5,java对象中mappr属性传参
java中的代码
private Map<String, Object> params = new HashMap<String, Object>();
xml中代码
<if test="params != null">
<if test="params.get('excludeId') != null">
or n.id = ${params.get('excludeId')}
</if>
</if>
6,JsonObject传入参数
java代码:
@RequestMapping(value = "/page",method = RequestMethod.POST)
@ResponseBody
public DataTransferObject page(@RequestBody JSONObject param){
java取参数: int pageNo = Integer.valueOf(param.get("pageNo").toString());
int pageSize = Integer.valueOf(param.get("pageSize").toString());
String content = param.optString("content", ""); //推荐
Integer result = param.optInt("result", 0); //推荐
java设置参数:
param.put("start", pageNo * pageSize);
param.put("end", pageSize);
java:判断,取出数组,移除
if (param.has("attributeItemIds")) {
JSONArray attributeItemIds = param.getJSONArray("attributeItemIds");
if (null == attributeItemIds || attributeItemIds.size() == 0) {
param.remove("attributeItemIds");
}
}
entityQO对象传递:
private Integer attributeId;
private JSONArray attributeItemIds;// 兼容web端
xml取出:
1, <select id="phoneListCommodityCompleteInfo" resultType="com.uei.phone.manager.model.market.CommodityVo" parameterType="com.uei.phone.manager.model.market.CommodityQo" >
2, <select id="listCmomodityCompleteInfo" resultType="hashMap" parameterType="org.json.simple.JSONObject" >
取出与遍历
<if test="catagoryId != null and catagoryId != ''">
AND b.catagory_id = #{catagoryId}
</if>
<if test="catagoryIds != null and catagoryIds.size != 0">
AND b.catagory_id IN
<foreach item="catagoryId" index="index" collection="catagoryIds" open="(" separator="," close=")">
#{catagoryId}
</foreach>
</if>
相关文章推荐
- MySQL Split String Function
- MySQL字段名与保留字冲突
- MySQL中InnoDB全文检索
- mysql启动不起来了!
- MySql优化--使用索引优化
- mysql数据库连接数
- Mysql 数据库密码管理
- MySQL常用命令(备查)
- MySQL触发器的作用
- windows下QMYSQL driver not loaded的解决方案
- 【MySQL存储引擎】MyISAM、InnoDB和MEMORY特性对比
- Mysql主主
- MYSQL Windows 主从配置
- Mysql Limit用法
- MySQL Cluster在线备份和恢复
- 总是忘记的场景:MySQL InnoDB四个事务级别 与 脏读、不重复读、幻读
- MySQL日期数据类型和时间类型使用总结
- sas与mysql连接方法
- MySql的注释
- mysql命令行数据导出