几个框架的注意点

@param注解

@Update({“update book set mainPic=#{param2} where isbn=#{param1}”})
int updatePic(String isbn, Integer pictureId);

按照传入参数的顺序,mybatis框架会有为参数生成隐藏的可用参数,如param1就对应第一个接收形参isbn。也可以指定参数名,如下:

@Update({“update book set mainPic=#{forpic} where isbn=#{forisbn}”})
int updatePic(@param(“forisbn”)String isbn, @(“forpic”)Integer pictureId);


模糊查询concat

@Select({“select book.isbn isbn, title from book where book.title like concat(concat(‘%’, #{title}), ‘%’)”})
List selectByKey(String title);

因为mybatis不能识别%,所以要concat()函数连接。


传收参数

1 首先可以直接在跳转路径加参数名,然后springMVC框架会根据参数名,在形参上查找同名的,对应填值;如果形参是对象,会进入对象查看是否有同名属性,对应填值。

2

@Controller
public class IndexController {

@RequestMapping("/index/{username}")  
public String index(@PathVariable</span>("username") String username) {  
    System.out.print(username);  
    return "index";  
}  

}

这是跳转路径没有指明参数,使用{}传入页面参数,使用@PathVariable 获取传入参数。