ExtJS4,Spring JPA,Restful服务,Hibernate应用程序

时间:2016-03-19 20:07:56

标签: java spring hibernate jpa extjs4.2

我正在使用ExtJS4,Spring JPA,Restful服务和Hibernate技术开发书籍存储库应用程序。我需要在Extjs中创建一个gridpanel,在加载页面时列出所有书籍,并且网格下面应该有一个表格,可以添加书籍。一旦用户点击表单上的“添加”按钮,网格就会自动刷新并显示新书。

从头开始构建所有东西对我来说是一种挑战。我已经构建了服务器端代码并​​获得了listBooks和saveBook方法的响应。现在我需要构建一个ExtJS页面来调用我在Spring中定义的服务来显示书籍列表并添加一本书。我正在努力将ExtJS与服务器端集成在一起。我无法通过extjs调用服务。我将衷心感谢您的帮助!我附上一些截图。我也为他们各自的Impl类创建了Dao和Service类。



Ext.onReady(function(){

	Ext.create(Ext.window.Window, {
      title   : 'Add Book',
      width   : 350,
      x : 50,
      y : 275,
      layout  : 'fit',
      resizable: false,
      closeAction: 'hide',
      modal   : true,
      config  : {
        recordIndex : 0,
        action : ''
      },
      items   : [{
        xtype : 'form',
        layout: 'anchor',
        bodyStyle: {
          background: 'none',
          padding: '10px',
          border: '0'
        },
        defaults: {
          xtype : 'textfield',
          anchor: '100%'
        },
        items : [{
          name  : 'isbn',
          fieldLabel: 'ISBN'
        },{
          name: 'title',
          fieldLabel: 'Title'
        },{
          name: 'author',
          fieldLabel: 'Author'
        },{
          name: 'genre',
          fieldLabel: 'Genre'
        },{
          name: 'details',
          fieldLabel: 'Details'
        }]
      }],
      buttons: [{
        text: 'Add Book',
        action: 'add'
       /* handler : function(){
        	click : this.doAddBook(),
        
        	doAddBook: function(){
        	
        	Ext.window.MessageBox("Hello");
        	
        	}
        
        }*/
        
      }]
    }).show();
     renderTo: Ext.getBody();
});


Ext.define('BookModel', { 
	extend : 'Ext.data.Model',
	fields : [
	{name: 'isbn', type : 'int'},
	{name: 'title', type : 'string'},
	{name: 'author', type : 'string'},
	{name: 'genre', type : 'string'},
	{name: 'details', type : 'string'}
	]
});



Ext.define('Bookstore', {
	
	extend : 'Ext.data.Store',
	storeId : 'bookStore',
	model : 'BookModel',
	fields : ['isbn', 'title', 'author','genre', 'details'],
	proxy : { 
		type : 'ajax',
		url : 'http://localhost:2016/SpringRestServiceNew/book/list',
		reader : { 
			type : 'json',
			root : 'books'
		}
	},
	autoLoad : true

});


Ext.define('BooksList', {
	extend : 'Ext.grid.Panel',
	title: 'Books List',
	store : 'Bookstore',
	columns : [
	{header : 'ISBN', dataIndex: 'isbn', flex: 1},
	{header: 'Title', dataIndex: 'title'},
	{header: 'Author', dataIndex: 'author'},
	{header: 'Genre', dataIndex: 'genre'},
	{header: 'Details', dataIndex: 'details'}],
	
	height : 250,
	width : 400,
	renderTo : Ext.getBody()
});

<!-- 
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Library Application</title>
<link rel="stylesheet"
	href="http://cdn.sencha.io/try/extjs/4.1.0/resources/css/ext-all-gray.css" />
<script src="http://cdn.sencha.io/try/extjs/4.1.0/ext-all-debug.js"></script>
<script type="text/javascript" src="mycode.js"></script>
</head>
<body>
</body>
</html>
 -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Library Application</title>
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css">
<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all-debug.js"></script>
<!--<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all.js"></script> -->
<script type="text/javascript" src="mycode.js"></script>
</head>
<body>
</body>
</html>
&#13;
&#13;
&#13; [BookController的[BookDaoImpl [BookServiceImpl [其余 - web.xml[ProjectStructure] 1 servlet.xml中

1 个答案:

答案 0 :(得分:1)

您的代码存在一些问题。

  1. 由于您希望在List之后使用表单,因此您应该创建Panel而不是Window。
  2. 您正在将表单窗口呈现给正文但不是列表
  3. 这是更新的代码。

    &#13;
    &#13;
    Ext.define('BookPanel', {
      extend: 'Ext.Panel',
      xtype: 'bookForm',
      title: 'Add Book',
      resizable: false,
      config: {
        recordIndex: 0,
        action: ''
      },
      items: [{
        xtype: 'form',
        layout: 'anchor',
        bodyStyle: {
          background: 'none',
          padding: '10px',
          border: '0'
        },
        defaults: {
          xtype: 'textfield',
          anchor: '100%'
        },
        items: [{
          name: 'isbn',
          fieldLabel: 'ISBN'
        }, {
          name: 'title',
          fieldLabel: 'Title'
        }, {
          name: 'author',
          fieldLabel: 'Author'
        }, {
          name: 'genre',
          fieldLabel: 'Genre'
        }, {
          name: 'details',
          fieldLabel: 'Details'
        }]
      }],
      buttons: [{
        text: 'Add Book',
        action: 'add'
          /* handler : function(){
             	click : this.doAddBook(),
             
             	doAddBook: function(){
             	
             	Ext.window.MessageBox("Hello");
             	
             	}
             
             }*/
      }]
    });
    
    Ext.define('BookModel', {
      extend: 'Ext.data.Model',
      fields: [{
        name: 'isbn',
        type: 'int'
      }, {
        name: 'title',
        type: 'string'
      }, {
        name: 'author',
        type: 'string'
      }, {
        name: 'genre',
        type: 'string'
      }, {
        name: 'details',
        type: 'string'
      }]
    });
    
    var data = {
      books: [{
        isbn: 1,
        title: 'Ed Spencer',
        author: '555 1234'
      }, {
        isbn: 2,
        title: 'Abe Elias',
        author: '666 1234'
      }]
    };
    
    Ext.define('BookStore', {
    
      extend: 'Ext.data.Store',
      storeId: 'bookStore',
      model: 'BookModel',
      data: data,
      proxy: {
        type: 'memory',
        reader: {
          type: 'json',
          root: 'books'
        }
      }
    
    });
    
    
    Ext.define('BookList', {
      extend: 'Ext.grid.Panel',
      xtype: 'bookList',
      title: 'Books List',
      store: new BookStore(),
      columns: [{
        header: 'ISBN',
        dataIndex: 'isbn',
        flex: 1
      }, {
        header: 'Title',
        dataIndex: 'title'
      }, {
        header: 'Author',
        dataIndex: 'author'
      }, {
        header: 'Genre',
        dataIndex: 'genre'
      }, {
        header: 'Details',
        dataIndex: 'details'
      }],
    
      height: 250,
      width: 400
    });
    
    Ext.application({
      name: 'Fiddle',
    
      launch: function() {
        Ext.create('Ext.Panel', {
          layout: 'vbox',
          items: [{
            xtype: 'bookList',
            width: '100%',
            flex: 1
          }, {
            xtype: 'bookForm',
            width: 500,
            flex: 1
          }],
          renderTo: Ext.getBody()
        });
      }
    });
    &#13;
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="utf-8" />
      <title>Library Application</title>
      <link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css">
      <script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all-debug.js"></script>
    </head>
    
    <body>
    </body>
    
    </html>
    &#13;
    &#13;
    &#13;