除了jdbc.properties其他的配置文件全部都要消灭掉。
接下来第一个:我们杀UserDao.xml。
public interface UserDao {
@Insert("insert into user(userName,password,realName,gender,birthday)values(#{userName},#{password},#{realName},#{gender},#{birthday})")
public boolean save(User user);
@Update("update user set userName=#{userName},password=#{password},realName=#{realName},gender=#{gender},birthday=#{birthday} where uuid=#{uuid}")
public boolean update(User user);
@Delete("delete from user where uuid = #{uuid}")
public boolean delete(Integer uuid);
@Select("select * from user where uuid = #{uuid}")
public User get(Integer uuid);
@Select(" select * from user")
public List<User> getAll();
@Select("select * from user where userName=#{userName} and password=#{password}")
public User getByUserNameAndPassword(@Param("userName") String userName, @Param("password") String password);
}
直接把映射文件里面的东西放注解上面就好了。
第二步,我们杀applicationContext.xml文件:(我们创建config文件夹并在其目录下创建主配置类,用该主配置类来部分代替applicationContext.xml)事实上因为我们在applicationContext.xml里面配置了Spring和JDBC以及MyBatis的东西,所以这个配置文件我们是使用三个配置类来替代的(SpringConfig,JdbcConfig,MyBatisConfig)
写到这里不想写了(测试已经通过了),我就直接写下配置文件对应类的关系吧你自己去ssm_annotation module下面看吧,然后是分先后顺序的哈:
- UserDao.xml---------------------UserDao(上面写了)
- applicationContext.xml---------------------SpringConfig,JdbcConfig,MyBatisConfig
- springMVC.xml---------------------SpringMVCConfig
- web.xml---------------------ServletContainersInitConfig
这样就全部替换完成了。