1. 程式人生 > >JEECG開發第一個菜單現實設備列表

JEECG開發第一個菜單現實設備列表

一個 varchar ava list fit name ngs 設備 編碼

一、新建設備表(t_base_device)

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for t_base_device
-- ----------------------------
DROP TABLE IF EXISTS `t_base_device`;
CREATE TABLE `t_base_device` (
  `deviceid` int(10) NOT NULL,
  `devicecode` varchar(50) DEFAULT NULL,
  `devicename` 
varchar(50) DEFAULT NULL, `deviceclassno` varchar(10) DEFAULT NULL, `status` varchar(10) DEFAULT NULL, `username` varchar(50) DEFAULT NULL, `userdept` varchar(200) DEFAULT NULL, PRIMARY KEY (`deviceid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of t_base_device
-- ---------------------------- INSERT INTO `t_base_device` VALUES (10001, STPC201711001, 華碩X550, 0101, 使用中, 謝紅衛, 軟件研發部); INSERT INTO `t_base_device` VALUES (10002, STPC201711002, 聯想T440P, 0101, 庫存, null, null);

二、實體類(BaseDevice.java)

package net.xhw.device.entity;

import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @SuppressWarnings("serial") @Entity @Table(name = "t_base_device") public class BaseDevice implements java.io.Serializable{ private int deviceid; private String devicecode; private String devicename; private String deviceclassno; private String status; private String username; private String userdept; @Id @Column(name = "deviceid", length = 10) public int getDeviceid() { return deviceid; } @Column(name = "devicecode", length = 50) public String getDevicecode() { return devicecode; } @Column(name = "devicename", length = 50) public String getDevicename() { return devicename; } @Column(name = "deviceclassno", length = 10) public String getDeviceclassno() { return deviceclassno; } @Column(name = "status", length = 10) public String getStatus() { return status; } @Column(name = "username", length = 50) public String getUsername() { return username; } @Column(name = "userdept", length = 200) public String getUserdept() { return userdept; } public void setDeviceid(int deviceid) { this.deviceid = deviceid; } public void setDevicecode(String devicecode) { this.devicecode = devicecode; } public void setDevicename(String devicename) { this.devicename = devicename; } public void setDeviceclassno(String deviceclassno) { this.deviceclassno = deviceclassno; } public void setStatus(String status) { this.status = status; } public void setUsername(String username) { this.username = username; } public void setUserdept(String userdept) { this.userdept = userdept; } }

三、action控制類(DeviceController.java)

package net.xhw.device.ctrl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import net.xhw.device.entity.BaseDevice;


@Controller
@RequestMapping("/deviceController")
public class DeviceController extends BaseController {
    
    private SystemService systemService;
    
    @Autowired
    public void setSystemService(SystemService systemService) {
        this.systemService = systemService;
    }

    @RequestMapping(params = "deviceList")
    public ModelAndView deviceList(HttpServletRequest request) {
        return new ModelAndView("device/deviceList");
    }
    
    @RequestMapping(params = "datagrid")
    public void datagrid(BaseDevice basedevice, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {        
        CriteriaQuery cq = new CriteriaQuery(BaseDevice.class, dataGrid);
        this.systemService.getDataGridReturn(cq, true);
        TagUtil.datagrid(response, dataGrid);
    }
    
}

四、頁面文件(deviceList.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>

<t:datagrid name="deviceList" title="設備信息列表" actionUrl="deviceController.do?datagrid" 
    fit="true" fitColumns="true" idField="deviceid" queryMode="group">
    <t:dgCol title="設備ID" field="deviceid" hidden="true"></t:dgCol>
    <t:dgCol title="設備編碼" field="devicecode" query="false" width="100"></t:dgCol>
    <t:dgCol title="設備名稱" field="devicename" query="false" width="100"></t:dgCol>
    <t:dgCol title="狀態" field="status" query="false" width="100"></t:dgCol>
    <t:dgCol title="使用人" field="username" query="false" width="100"></t:dgCol>
</t:datagrid>

五、修改配置文件

  1、修改spring-mvc.xml,添加掃描控制類包    

<context:component-scan base-package="org.jeecgframework.web.*,com.jeecg.*,net.xhw.*">
  <context:exclude-filter type="annotation"
     expression="org.springframework.stereotype.Service" />
</context:component-scan>

  2、修改spring-mvc-hibernate.xml,添加註解方式配置

<!-- 註解方式配置 -->
<property name="packagesToScan">
  <list>
     <value>org.jeecgframework.web.system.pojo.*</value>
     <value>org.jeecgframework.web.test.entity.*</value>
    <value>org.jeecgframework.web.autoform.*</value>
    <value>org.jeecgframework.web.cgform.entity.*</value>     <value>org.jeecgframework.web.cgreport.entity.*</value>     <value>org.jeecgframework.web.cgdynamgraph.entity.*</value>     <value>org.jeecgframework.web.graphreport.entity.*</value>     <value>org.jeecgframework.web.system.sms.*</value>     <value>com.jeecg.*</value>     <value>net.xhw.*</value> </list> </property>

六、菜單配置及結果

技術分享

技術分享

JEECG開發第一個菜單現實設備列表