后台搭建
搭的比较简单,刚开始就是对文章的增删查改而已,这里用到了mybatis的逆向工程,可以自动生成bean,mapper和对应的xml.
然后是对数据库的增删查改工作
package com.yjf.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yjf.bean.Article;
import com.yjf.bean.ArticleExample;
import com.yjf.dao.ArticleMapper;
import com.yjf.service.ArticleService;
@Service
public class ArticleServiceImpl implements ArticleService {
@Autowired
ArticleMapper articleMapper;
@Override
public List<Article> listByCid(Integer cid) {
ArticleExample example = new ArticleExample();
example.createCriteria().andCidEqualTo(cid);
List<Article> as = articleMapper.selectByExample(example);
return as;
}
@Override
public List<Article> listByLid(Integer Lid) {
ArticleExample example = new ArticleExample();
example.createCriteria().andCidEqualTo(Lid);
List<Article> as = articleMapper.selectByExample(example);
return as;
}
@Override
public Article get(Integer id) {
return articleMapper.selectByPrimaryKey(id);
}
@Override
public void add(Article article) {
articleMapper.insert(article);
}
@Override
public void delete(Integer id) {
articleMapper.deleteByPrimaryKey(id);
}
@Override
public void update(Article article) {
articleMapper.updateByPrimaryKeySelective(article);
}
@Override
public List<Article> list() {
ArticleExample example = new ArticleExample();
example.setOrderByClause("id desc");
List<Article>as = articleMapper.selectByExample(example);
return as;
}
}
这样对数据库的增删查改就可以了.