目录
Mybatis注解开发
对于简单的sql语句,可以在UserMapper接口中的方法上添加注解。
@Select(value = "select * from tb_user where id = #{id}")
public User select(int id);
注解是用来替换映射配置文件方式配置的,所以使用了注解,就不需要再映射配置文 件中书写对应的 statement。
Mybatis参数传递
1)多个参数:需要使用 @Param 注解。
底层是封装成Map,@param就是map中key,参数就是Map中的value.
User select(@Param("username") String username,
@Param("password") String password);
<select id="select" resultType="user">
select *
from tb_user
where
username=#{username}
and password=#{password}
</select>
java-字符串与日期格式转换
字符串转日期
Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2005-06-09");
日期转字符串
String now = new SimpleDateFormat("yyyy年MM月dd日").format(date);