发表于: 2020-06-14 23:09:30
1 1765
今天完成的事情:今天继续在完成作者模块的编写,然后着手写分类的时候,还没搞懂递归查询类目,有点绕,哈哈。
明天计划的事情:完成留言模块。
遇到的问题:暂无
收获:
测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-biz.xml")
public class AuthorTest {
@Resource
private AuthorService authorService;
@Test
public void addAuthor(){
Author author= new Author();
author.setName("张茹娟");
author.setIntro("宠辱不惊,看庭前花开花落,去留无意,望天上云卷云舒。");
author.setCreateAt(new Date().getTime());
author.setUpdateAt(new Date().getTime());
author.setUpdateBy("超级管理员");
author.setCreateBy("超级管理员");
int num = authorService.addAuthor(author);
System.out.println(num);
}
@Test
public void findAuthor(){
Author author = authorService.findAuthor(2L);
System.out.println(author);
}
@Ignore
public void updateAuthor(){
Author author= new Author();
author.setId(1);
author.setName("沈红");
author.setIntro("人生恰如三月花,倾我一生一世念。来如飞花散似烟,醉里不知年华限。");
author.setUpdateAt(new Date().getTime());
author.setUpdateBy("超级管理员");
int num = authorService.updateAuthor(author);
System.out.println(num);
}
@Ignore
public void deleteAuthor(){
int num = authorService.deleteAuthor(2L);
System.out.println(num);
}
}
service和impl
@Service("authorService")
public interface AuthorService {
Author findAuthor(Long id);
int updateAuthor(Author author);
int addAuthor(Author author);
int deleteAuthor(Long id);
}
@Service
public class AuthorServiceImpl implements AuthorService {
@Resource
private AuthorDao authorDao;
@Override
public Author findAuthor(Long id) { return authorDao.findAuthor(id); }
@Override
public int updateAuthor(Author author) {return authorDao.updateAuthor(author); }
@Override
public int addAuthor(Author author) {return authorDao.addAuthor(author); }
@Override
public int deleteAuthor(Long id) {return authorDao.deleteAuthor(id); }
}
Dao层
@Repository("authorDao")
public interface AuthorDao {
Author findAuthor(Long id);
int updateAuthor(Author author);
int addAuthor(Author author);
int deleteAuthor(Long id);
}
<?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.hyx.dao.AuthorDao">
<resultMap id="forAuthor" type="Author">
<id column="id" property="id" javaType="Integer"></id>
<result column="create_at" property="createAt" javaType="Long"></result>
<result column="update_at" property="updateAt" javaType="Long"></result>
<result column="create_by" property="createBy" javaType="String"></result>
<result column="create_by" property="updateBy" javaType="String"></result>
</resultMap>
<select id="findAuthor" resultMap="forAuthor" parameterType="Long">
select * from author where id=#{id}
</select>
<insert id="addAuthor" parameterType="Author" useGeneratedKeys="true" keyProperty="id">
insert into author (
name,intro,create_at,update_at,create_by,update_by)
value (#{name},#{intro},#{createAt},#{updateAt},#{createBy},#{updateBy})
</insert>
<update id="updateAuthor" >
update banner set intro=#{intro},update_at=#{updateAt},update_by=#{updateBy} where id=#{id}
</update>
<delete id="deleteAuthor" parameterType="Long">
delete from banner id = #{id}
</delete>
</mapper>
评论