maven 환경 구축 및 첨삭 검사 기능, 페이지 나 누 기
42451 단어 자바
4.0.0
AntSource
AntSource
war
0.0.1-SNAPSHOT
AntSource Maven Webapp
http://maven.apache.org
javax.servlet
javax.servlet-api
3.1.0
provided
org.springframework
spring-context
4.3.11.RELEASE
org.springframework
spring-web
4.3.11.RELEASE
org.springframework
spring-webmvc
4.3.11.RELEASE
org.springframework
spring-jdbc
4.3.11.RELEASE
org.mybatis
mybatis
3.4.1
org.mybatis
mybatis-spring
1.3.1
mysql
mysql-connector-java
5.1.38
javax.servlet
jstl
1.2
com.google.code.gson
gson
2.8.1
javax.annotation
javax.annotation-api
1.3.1
jsptags
pager-taglib
2.0
org.aspectj
aspectjweaver
1.8.10
AntSource
resources 에서 새 spring. xml
mybatis. xml 설정
generator Config. xml 설정
Java
kohgylw.model Department.java
package kohgylw.model;
public class Department {
private Integer departmentId;
private String pId;
private String departmentName;
private String departmentTel;
private String departmentDesc;
private String departmentGer;
private String departmentType;
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public String getpId() {
return pId;
}
public void setpId(String pId) {
this.pId = pId;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getDepartmentTel() {
return departmentTel;
}
public void setDepartmentTel(String departmentTel) {
this.departmentTel = departmentTel;
}
public String getDepartmentDesc() {
return departmentDesc;
}
public void setDepartmentDesc(String departmentDesc) {
this.departmentDesc = departmentDesc;
}
public String getDepartmentGer() {
return departmentGer;
}
public void setDepartmentGer(String departmentGer) {
this.departmentGer = departmentGer;
}
public String getDepartmentType() {
return departmentType;
}
public void setDepartmentType(String departmentType) {
this.departmentType = departmentType;
}
}
보조 페이지 플러그 인
DepartmentPager.java package kohgylw.model;
import java.util.List;
//
public class DepartmentPager {
private int total;//
private int totalRecords;//
private List listDepartments;//
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
public List getListDepartments() {
return listDepartments;
}
public void setListDepartments(List listDepartments) {
this.listDepartments = listDepartments;
}
@Override
public String toString() {
return "DepartmentPager [total=" + total + ", totalRecords=" + totalRecords + ", listDepartments="
+ listDepartments + "]";
}
}
kohgylw. mapper 아래 인터페이스 구축 DepartmentMapper.java package kohgylw.mapper;
import java.util.List;
import java.util.Map;
import kohgylw.model.Department;
public interface DepartmentMapper {
int deleteByPrimaryKey(Integer departmentId);
int insert(Department record);
int insertSelective(Department record);
Department selectByPrimaryKey(Integer departmentId);
int updateByPrimaryKeySelective(Department record);
int updateByPrimaryKey(Department record);
//
int queryDepartmentNum(Map totalMap);
List querydepartmentPage(Map map);
//
Department selectByDepartmentId(Integer departmentId);
}
kohgylw. mapper. xml 아래 인터페이스 구현 클래스 DepartmentMapper.xml
department_id, p_id, department_name, department_tel, department_desc, department_ger,
department_type
delete from department
where department_id = #{departmentId,jdbcType=INTEGER}
insert into department (department_id, p_id, department_name,
department_tel, department_desc, department_ger,
department_type)
values (#{departmentId,jdbcType=INTEGER}, #{pId,jdbcType=VARCHAR}, #{departmentName,jdbcType=VARCHAR},
#{departmentTel,jdbcType=VARCHAR}, #{departmentDesc,jdbcType=VARCHAR}, #{departmentGer,jdbcType=VARCHAR},
#{departmentType,jdbcType=VARCHAR})
insert into department
department_id,
p_id,
department_name,
department_tel,
department_desc,
department_ger,
department_type,
#{departmentId,jdbcType=INTEGER},
#{pId,jdbcType=VARCHAR},
#{departmentName,jdbcType=VARCHAR},
#{departmentTel,jdbcType=VARCHAR},
#{departmentDesc,jdbcType=VARCHAR},
#{departmentGer,jdbcType=VARCHAR},
#{departmentType,jdbcType=VARCHAR},
update department
p_id = #{pId,jdbcType=VARCHAR},
department_name = #{departmentName,jdbcType=VARCHAR},
department_tel = #{departmentTel,jdbcType=VARCHAR},
department_desc = #{departmentDesc,jdbcType=VARCHAR},
department_ger = #{departmentGer,jdbcType=VARCHAR},
department_type = #{departmentType,jdbcType=VARCHAR},
where department_id = #{departmentId,jdbcType=INTEGER}
update department
set p_id = #{pId,jdbcType=VARCHAR},
department_name = #{departmentName,jdbcType=VARCHAR},
department_tel = #{departmentTel,jdbcType=VARCHAR},
department_desc = #{departmentDesc,jdbcType=VARCHAR},
department_ger = #{departmentGer,jdbcType=VARCHAR},
department_type = #{departmentType,jdbcType=VARCHAR}
where department_id = #{departmentId,jdbcType=INTEGER}
kohgylw. service. impl 아래 인터페이스 구축 DepartmentService.java package kohgylw.service.impl;
import kohgylw.model.Department;
public interface DepartmentService {
//
int insertDepartment(Department department);
//
int deleteMember(Department department);
//
String getDepartmentServicePage(String pageNumber, String departmentType, String departmentName);
//
int updateDepartment(Department department);
//
Department selectByDepartmentId(Integer departmentId);
}
kohgylw. service. impl 아래 건설 실현 류 DepartmentServiceImpl.java package kohgylw.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import kohgylw.mapper.DepartmentMapper;
import kohgylw.model.Department;
import kohgylw.model.DepartmentPager;
// ( mapper )
@Service
public class DepartmentServiceImpl implements DepartmentService {
@Resource
private DepartmentMapper departmentMapper;
//
public int insertDepartment(Department department) {
return departmentMapper.insert(department);
}
//
public int deleteMember(Department department) {
return departmentMapper.deleteByPrimaryKey(department.getDepartmentId());
}
//
public String getDepartmentServicePage(String pno, String departmentType, String departmentName) {
System.out.println("pno"+pno);
System.out.println("departmentType"+departmentType);
System.out.println("departmentName"+departmentName);
// 6
int pageSize=6;
//
Map totalMap = new HashMap();
totalMap.put("departmentType", "%" + departmentType + "%");
totalMap.put("departmentName", departmentName);
//
int totalRecords = departmentMapper.queryDepartmentNum(totalMap);
System.out.println("totalRecords-----1-->"+totalRecords);
//
int totalPage = 0;
Gson gson = new Gson();
//
DepartmentPager departmentPager = new DepartmentPager();
//
departmentPager.setTotalRecords(totalRecords);
//
if (totalRecords % pageSize > 0) {
totalPage = totalRecords / pageSize + 1;
} else {
totalPage = totalRecords / pageSize;
}
System.out.println("totalPage -----1-->"+totalPage );
departmentPager.setTotal(totalPage);
//
int n = 1;
if (pno != null && pno.length() > 0) {
n = Integer.parseInt(pno);
}
Map map = new HashMap();
map.put("pno", (n - 1) * pageSize);
map.put("num", pageSize);
map.put("departmentType", "%" + departmentType + "%");
map.put("departmentName", departmentName);
List listdepartments = departmentMapper.querydepartmentPage(map);
System.out.println(totalRecords + "**********" + pageSize);
departmentPager.setListDepartments(listdepartments);
System.out.println("departmentJson=="+gson.toJson(departmentPager));
return gson.toJson(departmentPager);
}
//
public int updateDepartment(Department department) {
return departmentMapper.updateByPrimaryKey(department);
}
//
public Department selectByDepartmentId(Integer departmentId) {
return departmentMapper.selectByDepartmentId(departmentId);
}
}
kohgylw. controller 내장 컨트롤 러 DepartmentController.java package kohgylw.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import kohgylw.model.Department;
import kohgylw.service.impl.DepartmentService;
// ( service )
@Controller
@RequestMapping("/Department")
public class DepartmentController {
@Resource
private DepartmentService departmentService;
//
@RequestMapping("/addDepartment.ajax")
@ResponseBody
public String addDepartmentr(Department department){
int rs = departmentService.insertDepartment(department);
System.out.println("insert---->"+rs);
if(rs>0){
return "dpinsertOK";
}
return "dpinsertError";
}
//
@RequestMapping("/deleteDepartment.ajax")
@ResponseBody
public String deleteDepartment(Department department) {
int rs=departmentService.deleteMember(department);
if(rs>0) {
return "deleteDepartment";
}
return "deleteDeleteDepartmentError";
}
//
@RequestMapping(value="initDepartmentPage.ajax",produces="text/html;charset=utf-8")
@ResponseBody
public String initDepartmentPage(String pageNumber, String departmentType, String departmentName){
System.out.println("pageNumber==>"+pageNumber);
System.out.println("DepartmentType==>"+departmentType);
System.out.println("DepartmentName==>"+departmentName);
String departmentJson = departmentService.getDepartmentServicePage(pageNumber, departmentType, departmentName);
return departmentJson;
}
//
@RequestMapping("/updateDepartment.ajax")
@ResponseBody
public String updateDepartment(Department department) {
int rs=departmentService.updateDepartment(department);
System.out.println("rs"+rs);
if(rs>0) {
return "updateD";
}
return "updateError";
}
//
@RequestMapping("/queryDepartmentById.do")
public String queryDepartmentById(HttpServletRequest request,Integer departmentId) {
Department departments=departmentService.selectByDepartmentId(departmentId);
System.out.println("department===="+departments);
request.setAttribute("department", departments);
return "view/department/department-update";
}
}
webapp/view/department 에서
department-list.jsp
:
//
$(function(){
//
getDepartmentPage(1);
});
//
function getDepartmentPage(pageNumber) {
//
var DepartmentType = $("#DepartmentType").val();
//
var DepartmentName = $("#DepartmentName").val();
$.ajax({
type : 'POST',//
dataType : 'text',//
data : {//
pageNumber : pageNumber,
DepartmentType : DepartmentType,
DepartmentName : DepartmentName
},
url : 'Department/initDepartmentPage.ajax',// url
success : function(result) {
//
var departmentJson = eval("(" + result + ")");
var listDepartments = departmentJson.listDepartments;
$("#totalRecords").text(departmentJson.totalRecords);//
showDepartmentPage(listDepartments);//
initKkpager(departmentJson.total, departmentJson.totalRecords);//
},
error : function() {
}
});
};
//
function showDepartmentPage(departmentinfos) {
$("#tbody").html("");
$.each(departmentinfos,function(n, value) {
var row = "<tr id='tr_"+value.pId+"'><td>"
+ value.pId
+ "</td><td>"
+ value.departmentName
+ "</td><td>"
+ value.departmentTel
+ "</td><td>"
+ value.departmentDesc
+ "</td><td>"
+ value.departmentGer
+ "</td><td>"
+ value.departmentType
+ "</td>"
+ "<td class='td-manage'><a οnclick=\"updatedepartment('"+value.departmentId+"')\""
+ "title=' '> <i class='layui-icon'></i>"
+ "</a> <a title=' ' οnclick=\"department_del('"+value.departmentId+"')\""
+ "> <i class='layui-icon'></i>"
+ "</a></td></tr>"
$("#tbody").append(row);
if(value.memberStatus=="disable"){
$("#tr_"+value.memberLoginid).css("background-color","#C0C0C0")
}else{
$("#tr_"+value.memberLoginid).css("background-color","#FFFFFF")
}
});
}
/* */
function initKkpager(total, totalRecords) {
//
var kkpagerSetting={
pno : '1',
mode : 'click', // click
//
total : String(total),
//
totalRecords : String(totalRecords),
// 、 、 、 click
// , ajax
click : function(n) {
//
getDepartmentPage(n);
// selectPage
this.selectPage(n);
},
//getHref click , ,
getHref : function(n) {
return '#';
}
};
kkpager.generPageHtml(kkpagerSetting);// json
}
/* - */
function department_del(departmentId) {
layer.confirm(' ?', function() {
$.ajax({
type:'POST',
dataType:'text',
data:{
departmentId:departmentId
},
url:'Department/deleteDepartment.ajax',
success:function(result){
if(result=="deleteDepartment"){
location.reload();
}
},
error:function(){
alert(" , !");
}
});
//
layer.msg(' !', {
icon : 1,
time : 500
});
});
}
/* */
function updatedepartment(departmentId) {
x_admin_show(' ','Department/queryDepartmentById.do?departmentId='+departmentId,500,500);
}
department
-add.jsp