仿掘金项目之分类管理

create table category_info(
id int not null PRIMARY key auto_increment,
category_name varchar(100) not null DEFAULT ''
)ENGINE=INNODB;

INSERT INTO category_info VALUES ('1', '前端');
INSERT INTO category_info VALUES ('2', '后端');
INSERT INTO category_info VALUES ('3', '阅读');
public class CategoryInfo {
private int id;
private String category_name;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getCategory_name() {
    return category_name;
}

public void setCategory_name(String category_name) {
    this.category_name = category_name;
}

}
public interface CategoryService {
List getAllCategroies();

}
@Service
public class CategoryInfoImpl implements CategoryService {
@Autowired
CategoryMapper categoryMapper;
@Override
public List getAllCategroies() {
return categoryMapper.getAllCategroies();
}
}
public interface CategoryMapper {
List getAllCategroies();
}

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">



@Controller
public class HomeController {

@Autowired
ArticleService articleService;
@Autowired
CategoryService categoryService;

@RequestMapping("/")
public ModelAndView home()
{
    List> mapList = articleService.getAllArticles();
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("article_infos",mapList);

    List categoryInfoList = categoryService.getAllCategroies();
    modelAndView.addObject("cates",categoryInfoList);
    modelAndView.setViewName("index");
    return modelAndView;
}

@RequestMapping("/error")
public String error()
{
    return "404";
}

}
<%--分类导航--%>

你可能感兴趣的:(仿掘金项目之分类管理)