首先创建动态web项目:
接下来写代码:
web.xml代码:
springmvc
org.springframework.web.servlet.DispatcherServlet
springmvc
/
springmvc-servlet.xml代码:
实体类代码:
package com.accp.entity;
import java.util.Date;
public class edoc_entry {
private Integer id; //文档编号
private Integer categoryId; //分类编号
private String title; //文档名称
private String summary; //文档摘要
private String uploadUser; //上传人
private Date createDate; //上传时间
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getUploadUser() {
return uploadUser;
}
public void setUploadUser(String uploadUser) {
this.uploadUser = uploadUser;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
package com.accp.entity;
public class edoc_category {
private Integer id; //分类编号
private String name; //分类名称
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Dao层代码:
package com.accp.dao;
import java.util.List;
import com.accp.entity.edoc_category;
public interface edoc_categoryDao {
List seeCategoryList(); //查询分类
}
package com.accp.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.accp.entity.edoc_entry;
public interface edoc_entryDao {
List seeEntryList(@Param("categoryId")Integer categoryId); //查询列表
int insertEntry(edoc_entry entry); //添加方法
int delEntry(edoc_entry entry); //删除方法
int updEntry(edoc_entry entry); //修改方法
edoc_entry updByIdEntry(edoc_entry entry); //修改页面传值
}
mapping映射文件代码:
insert into edoc_entry
values(default,#{categoryId},#{title},#{summary},#{uploadUser},#{createDate})
delete from edoc_entry where id = #{id}
update edoc_entry
title = #{title},
summary = #{summary},
uploadUser = #{uploadUser},
createDate = #{createDate},
biz层代码:
package com.accp.biz;
import java.util.List;
import com.accp.entity.edoc_category;
public interface edoc_categoryBiz {
List seeCategoryList(); //查询分类
}
package com.accp.biz;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.accp.entity.edoc_entry;
public interface edoc_entryBiz {
List seeEntryList(@Param("categoryId")Integer categoryId); //查询列表
int insertEntry(edoc_entry entry); //添加方法
int delEntry(edoc_entry entry); //删除方法
int updEntry(edoc_entry entry); //修改方法
edoc_entry updByIdEntry(edoc_entry entry); //修改页面传值
}
biz.impl实现类代码:
package com.accp.biz.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.accp.biz.edoc_categoryBiz;
import com.accp.dao.edoc_categoryDao;
import com.accp.entity.edoc_category;
@Service
public class edoc_categoryBizImpl implements edoc_categoryBiz {
@Resource
private edoc_categoryDao categoryDao;
@Override
public List seeCategoryList() {
// TODO Auto-generated method stub
return categoryDao.seeCategoryList();
}
}
package com.accp.biz.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.accp.biz.edoc_entryBiz;
import com.accp.dao.edoc_entryDao;
import com.accp.entity.edoc_entry;
@Service
public class edoc_entryBizImpl implements edoc_entryBiz {
@Resource
private edoc_entryDao entryDao;
@Override
public List seeEntryList(Integer categoryId) {
// TODO Auto-generated method stub
return entryDao.seeEntryList(categoryId);
}
@Override
public int insertEntry(edoc_entry entry) {
// TODO Auto-generated method stub
return entryDao.insertEntry(entry);
}
@Override
public int delEntry(edoc_entry entry) {
// TODO Auto-generated method stub
return entryDao.delEntry(entry);
}
@Override
public int updEntry(edoc_entry entry) {
// TODO Auto-generated method stub
return entryDao.updEntry(entry);
}
@Override
public edoc_entry updByIdEntry(edoc_entry entry) {
// TODO Auto-generated method stub
return entryDao.updByIdEntry(entry);
}
}
control控制层代码:
package com.accp.control;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.accp.biz.edoc_categoryBiz;
import com.accp.biz.edoc_entryBiz;
import com.accp.entity.edoc_category;
import com.accp.entity.edoc_entry;
@Controller
public class edoc_entryControl {
@Resource
private edoc_entryBiz entrybiz;
@Resource
private edoc_categoryBiz categoryBiz;
@RequestMapping("/showcategory")
public String showcategory(@RequestParam(required=false,defaultValue="0")Integer categoryId,Model m) {
m.addAttribute("catList", categoryBiz.seeCategoryList());
m.addAttribute("entryList",entrybiz.seeEntryList(categoryId));
return "index";
}
@RequestMapping("/addentry")
public String addentry(edoc_entry e) {
entrybiz.insertEntry(e);
return "redirect:/showcategory";
}
@RequestMapping("/deleteentry")
public String deleteentry(edoc_entry e) {
entrybiz.delEntry(e);
return "redirect:/showcategory";
}
@RequestMapping("/updateentry")
public String updateentry(edoc_entry e) {
entrybiz.updEntry(e);
return "redirect:/showcategory";
}
@RequestMapping("/updateByIdentry")
public String updateByIdentry(edoc_entry e,Model m) {
m.addAttribute("entryMsg",entrybiz.updByIdEntry(e));
return "update";
}
}
页面代码:
首页:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Insert title here
添加
文档编号
文档名称
文档摘要
上传人
上传时间
操作
${elist.id}
${elist.title}
${elist.summary}
${elist.uploadUser}
修改 删除
添加页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Insert title here
修改页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Insert title here
效果显示: