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<CategoryInfo> getAllCategroies();
}
@Service
public class CategoryInfoImpl implements CategoryService {
@Autowired
CategoryMapper categoryMapper;
@Override
public List<CategoryInfo> getAllCategroies() {
return categoryMapper.getAllCategroies();
}
}
public interface CategoryMapper {
List<CategoryInfo> getAllCategroies();
}
<?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.neusoft.mapper.CategoryMapper">
<select id="getAllCategroies" resultType="CategoryInfo">
select * from category_info
</select>
</mapper>
@Controller
public class HomeController {
@Autowired
ArticleService articleService;
@Autowired
CategoryService categoryService;
@RequestMapping("/")
public ModelAndView home()
{
List<Map<String,Object>> mapList = articleService.getAllArticles();
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("article_infos",mapList);
List<CategoryInfo> categoryInfoList = categoryService.getAllCategroies();
modelAndView.addObject("cates",categoryInfoList);
modelAndView.setViewName("index");
return modelAndView;
}
@RequestMapping("/error")
public String error()
{
return "404";
}
}
<%--分类导航--%>
<div class="uk-container uk-container-center">
<div class="uk-panel uk-panel-box app-cate">
<ul class="uk-subnav uk-position-relative">
<c:forEach items="${cates}" var="cate">
<li><a href="#">${cate.category_name}</a></li>
</c:forEach>
<li class="uk-position-absolute app-all-tag"><a href="#">标签管理</a></li>
</ul>
</div>
</div>
网友评论