0

我是 Spring roo 的新手(我正在为 jquery、bootstrap 和 databale 使用 gvnix spring roo 发行版)。我在 mysql 中创建了 3 个表

CREATE TABLE `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Category_Name` varchar(50) NOT NULL,
  `Description` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

insert  into `categories`(`id`,`Category_Name`,`Description`) values (1,'Facility','facility'),(2,'Ikare','Ikare');

CREATE TABLE `subcategories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `subcategory_name` varchar(50) NOT NULL,
  `category_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_md1atoxe8wd8bi2fhf9nnw4q0` (`category_id`),
  CONSTRAINT `FK_md1atoxe8wd8bi2fhf9nnw4q0` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

insert  into `subcategories`(`id`,`subcategory_name`,`category_id`) values (1,'room service',1),(2,'store',1),(3,'server setup',2),(4,'Travel not working',2);

并使用数据库逆向工程命令创建 bean 文件。

并使用了脚手架、jquery、bootstrap 和 dattable

现在将应用程序部署到 tomcat7 后,我可以创建类别、子类别。

我的问题是在创建新服务台时,该类别显示在下拉列表中,所有子类别都默认显示。但是我希望当我选择特定类别时,它应该显示相应的子类别,但不是所有类别的所有子类别。

而且验证不起作用意味着如果我没有在必填字段中输入任何内容,我就可以保存数据。

下面是我创建新服务的代码。

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/jquery/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/datatables" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <form:create id="fc_com_arat_roo_domain_ServiceDesk" modelAttribute="serviceDesk" path="/servicedesks" render="${empty dependencies}" z="5rY4NJcP8nJ/t0tXbZs8XZLebzs=">
        <field:select field="categoryId" id="c_com_arat_roo_domain_ServiceDesk_categoryId" itemValue="id" items="${categorieses}" path="/categorieses" z="eTrZa7tDsB6IOgAA143b/eECzgs="/>
        <field:select field="subcategoryId" id="c_com_arat_roo_domain_ServiceDesk_subcategoryId" itemValue="id" items="${subcategorieses}" path="/subcategorieses" z="WLOZ5uG2O8vxZDxYu7Gg1q0Zx9w="/>
        <field:input field="comment" id="c_com_arat_roo_domain_ServiceDesk_comment" required="true" z="h/4gHQSwuY162Ci8qehagMY7ZUY="/>
    </form:create>
    <form:dependency dependencies="${dependencies}" id="d_com_arat_roo_domain_ServiceDesk" render="${not empty dependencies}" z="zpBtjtNE7E7oXm/3C5Dw9BagNsM="/>
</div>

控制器如下:

@RequestMapping(params = "form", produces = "text/html")
    public String createForm(Model uiModel) {
        populateEditForm(uiModel, new ServiceDesk());
        return "servicedesks/create";
    }

void populateEditForm(Model uiModel, ServiceDesk serviceDesk) {
        uiModel.addAttribute("serviceDesk", serviceDesk);
        uiModel.addAttribute("categorieses", Categories.findAllCategorieses());
        uiModel.addAttribute("subcategorieses", Subcategories.findAllSubcategorieses());
    }

下面是我使用的命令的 log.roo。

// Spring Roo 1.3.1.RELEASE [rev 8cb81a3] log opened at 2016-02-06 00:33:13
project --topLevelPackage com.arat.roo --projectName ssd --java 6 --packaging WAR
// Spring Roo 1.3.1.RELEASE [rev 8cb81a3] log closed at 2016-02-06 00:33:15
// Spring Roo 1.3.1.RELEASE [rev 8cb81a3] log opened at 2016-02-06 00:34:16
osgi start --url file:///C:/Users/Arat/.m2/repository/mysql/mysql-connector-java/5.1.20/mysql-connector-java-5.1.20.jar
hint
persistence setup --database MYSQL --provider HIBERNATE --databaseName learning --userName root --password Gayathri/?@123
osgi start --url file:///C:/Users/Arat/.m2/repository/mysql/mysql-connector-java/5.1.20/mysql-connector-java-5.1.20.jar
database introspect --schema no-schema-required
database reverse engineer --schema root --package ~.domain --includeTables "categories subcategories service_desk"
web mvc setup
web mvc all --package ~.web
web mvc jquery setup
web mvc jquery all
web mvc datatables setup
web mvc bootstrap setup
web mvc bootstrap update
web mvc datatables all 
jpa gvnix setup
jpa batch all
web mvc batch setup
web mvc batch all
web mvc datatables detail add --type ~.web.CategoriesController --property subcategorieses
web mvc datatables detail add --type ~.web.ServiceDeskController --property subcategorieses
web mvc datatables detail add --type ~.web.ServiceDeskController --property categorieses

你能帮我解决这个问题吗?

4

1 回答 1

0

看看放大镜字段组件。您可以显示数据表以允许按其类别过滤选择子类别。

祝你好运!

于 2016-02-24T20:02:06.307 回答