Use configuration in Vue.js (included with the SSH framework)

Source: Internet
Author: User

Before this! Please create a Lib database in the database!

+++++++++++++++++++++++++++++++++++++++++++++++++++++

--------------------------------------------------------------------------------------------

"Package name Com.nf.action"

(File name Bookaction.java)

Package com.nf.action;

Import Com.nf.entity.Book;
Import Com.nf.service.BookService;
Import Com.opensymphony.xwork2.ActionContext;
Import Com.opensymphony.xwork2.ActionSupport;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.context.annotation.Scope;
Import Org.springframework.stereotype.Controller;

Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

@Controller
@Scope ("prototype")
public class Bookaction extends Actionsupport {

This jsonmap is used to store data in JSON format
Private map<string,object> Jsonmap = new HashMap ();
Public map<string, Object> Getjsonmap () {
return jsonmap;
}
public void Setjsonmap (map<string, object> jsonmap) {
This.jsonmap = Jsonmap;
}

@Autowired
Private Bookservice Bookservice;

Public String Getallbook () {
List<book> Booklist = Bookservice.getallbook ();
Jsonmap.put ("Booklist", Booklist);
return "Jsonok";
}
}

==============================================

----------------------------------------------------------------------------------

"Package name Com.nf.dao"

{Interface Name Bookdao.java}

Package Com.nf.dao;

Import Com.nf.entity.Book;

Import java.util.List;

Public interface Bookdao {

Public list<book> Getallbook ();

}

----------------------------------------------------------------------------------

"Package name Com.nf.dao"

(File name Bookdaoimpl.java)

Package Com.nf.dao;

Import Com.nf.entity.Book;
Import org.hibernate.Session;
Import Org.hibernate.SessionFactory;
Import Org.hibernate.query.Query;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.context.annotation.Scope;
Import Org.springframework.stereotype.Repository;

Import java.util.List;

@Repository
@Scope ("prototype")
public class Bookdaoimpl implements Bookdao {

@Autowired
Private Sessionfactory sessionfactory;

Public list<book> Getallbook () {
Session session = Sessionfactory.getcurrentsession ();
query<book> query = Session.createquery ("From book", Book.class);
List<book> Booklist = Query.getresultlist ();


return Booklist;
}
}

==============================================

----------------------------------------------------------------------------------

"Com.nf.entity"

(Book.java)

Package com.nf.entity;

Import javax.persistence.*;

@Entity
@Table (name = "book")
public class Book {
    private Integer ID;
    private String name;
    private Integer price;
   
    @Id
    @GeneratedValue (strategy= generationtype.identity)
    @Column (name= "id")
 public Integer getId () {
   return ID;
 }
 public void setId (Integer id) {
  this.id = ID;
 }
 
  @Column (name = "Name", length = 50,nullable = False)
 public String getName () {
& Nbsp; return name;
 }
 public void SetName (String name) {
  this.name = name;
 }
 
  @Column (name = "Price", nullable = False)
 public Integer GetPrice () {
   return Price;
 }
 public void Setprice (Integer price) {
  this.price = Price;
 }
  
}

==============================================

----------------------------------------------------------------------------------

"Com.nf.service"

{Bookservice.java}

Package com.nf.service;

Import Com.nf.entity.Book;

Import java.util.List;

Public interface Bookservice {

Public list<book> Getallbook ();
}

--------------------------------------------------------------------------------

"Com.nf.service"

(Bookserviceimpl.java)

Package com.nf.service;

Import Com.nf.dao.BookDao;
Import Com.nf.entity.Book;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.context.annotation.Scope;
Import Org.springframework.stereotype.Service;
Import org.springframework.transaction.annotation.Transactional;

Import java.util.List;

@Service
@Scope ("prototype")
public class Bookserviceimpl implements Bookservice {

@Autowired
Private Bookdao Bookdao;

@Transactional
Public list<book> Getallbook () {
List<book> Booklist = Bookdao.getallbook ();
Write game rules (business logic code: no database Operations)
return Booklist;
}

}

////////////////////////////////////////////////////////////////////////

Database configuration (MySQL) change it yourself!

#database Information
Driverclass=com.mysql.cj.jdbc.driver
Jdbcurl=jdbc:mysql://localhost:3306/lib?servertimezone=utc
User=root
Password=root

///////////////////////////////////////////////////////////////////////

Not finished yet to be edited!

Use configuration in Vue.js (included with the SSH framework)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.