vue.js 操作mysql_idea开发工具springmvc加vue.js实现MySQL数据库的查询操作

项目目录:

e489e3e16678d4e34130bab50f50d2ba.png

User.java:

packagecom.nf.entity;import javax.persistence.*;

@Entity

@Table(name= "user", schema = "lib", catalog = "")public classUser {private intid;privateString name;privateString address;privateString phone;publicUser(){}public User(intid, String name, String address, String phone) {this.id =id;this.name =name;this.address =address;this.phone =phone;

}

@Id

@Column(name= "id")public intgetId() {returnid;

}public void setId(intid) {this.id =id;

}

@Basic

@Column(name= "name")publicString getName() {returnname;

}public voidsetName(String name) {this.name =name;

}

@Basic

@Column(name= "address")publicString getAddress() {returnaddress;

}public voidsetAddress(String address) {this.address =address;

}

@Basic

@Column(name= "phone")publicString getPhone() {returnphone;

}public voidsetPhone(String phone) {this.phone =phone;

}

@Overridepublic booleanequals(Object o) {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;

User that=(User) o;if (id != that.id) return false;if (name != null ? !name.equals(that.name) : that.name != null) return false;if (address != null ? !address.equals(that.address) : that.address != null) return false;if (phone != null ? !phone.equals(that.phone) : that.phone != null) return false;return true;

}

@Overridepublic inthashCode() {int result =id;

result= 31 * result + (name != null ? name.hashCode() : 0);

result= 31 * result + (address != null ? address.hashCode() : 0);

result= 31 * result + (phone != null ? phone.hashCode() : 0);returnresult;

}

}

UserDao.java

packagecom.nf.dao;importcom.nf.entity.User;importjava.util.List;public interfaceUserDao {public ListgetAllUsers() ;

}

UserDaoImpl.java

packagecom.nf.dao;importcom.nf.entity.User;importorg.hibernate.Session;importorg.hibernate.SessionFactory;importorg.hibernate.query.Query;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Repository;importjava.util.List;

@Repositorypublic class UserDaoImpl implementsUserDao {

@AutowiredprivateSessionFactory sessionFactory;public ListgetAllUsers() {

Session session=sessionFactory.getCurrentSession();

Query query = session.createQuery("from User", User.class);returnquery.getResultList();

}

}

UserService.java

packagecom.nf.service;importcom.nf.entity.User;importjava.util.List;public interfaceUserService {public ListgetAllUsers() ;

}

UserServiceImpl.java

packagecom.nf.service;importcom.nf.dao.UserDao;importcom.nf.entity.User;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importjavax.transaction.Transactional;importjava.util.List;

@Servicepublic class UserServiceImpl implementsUserService {

@AutowiredprivateUserDao userDao;

@Transactionalpublic ListgetAllUsers() {returnuserDao.getAllUsers();

}

}

UserAction.java

packagecom.nf.action;importcom.nf.service.UserService;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.ResponseBody;importjava.util.HashMap;importjava.util.Map;

@Controller

@RequestMapping("/user")public classUserAction {

@AutowiredprivateUserService userService ;

@RequestMapping("/query")public@ResponseBody

Mapquery(){

Map hashMap = new HashMap();

hashMap.put("userList",userService.getAllUsers());returnhashMap;

}

}

applicationContext.xml;

org.hibernate.dialect.MySQL57InnoDBDialect

true

true

false

spring-servlet.xml

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd

">

jdbc.properties

driverClass=com.mysql.cj.jdbc.Driver

jdbcUrl=jdbc:mysql://localhost:3306/lib?serverTimezone=UTCuser=root

password=123456

web.xml

OpenSessionInViewFilter

org.springframework.orm.hibernate5.support.OpenSessionInViewFilter

flushMode

AUTO

OpenSessionInViewFilter

/*

spring

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring-servlet.xml

1

spring

/

characterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

characterEncodingFilter

/*

contextConfigLocation

classpath:applicationContext.xml

org.springframework.web.context.ContextLoaderListener

qianduan,.jsp

显示所有的新闻信息

{{art.id}}

{{art.name}}

{{art.address}}

{{art.phone}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值