In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the role of orm in Spring". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the role of orm in Spring"?
ORM in Spring 2019.04.18 09:19:25
ORM introduces object-relational mapping, which is a program technology used to realize the conversion of data between different types of systems in object-oriented programming languages. In effect, it actually creates a virtual object database that can be used in programming languages. ORM's methodology is based on three core principles:
Simple: modeling data accessibility in the most basic form: database structure can be understood by anyone to document the accuracy of the language: based on the data model to create a correct standardized structure Spring ORM framework support spring framework that supports ORM are hibernate, mybatis, JPA and so on. But JPA is a specification, and both hibernate and mybatis follow the JPA specification. In application:
Create new modules and add dependencies
Image adds files to connect to the database and configures jdbc.properties in the resource bundle
Jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/db_spring?useUnicode=true&useSSL=false&characterEncoding=utf-8 jdbc.username=root jdbc.password=root
Spring_mybatis.xml
Mappers = com.spring.orm.dao.BaseDAO IDENTITY = MYSQL
Finish writing User in the class
@ Table (name = "t_user") / / name of the form @ Data public class User {/ / label primary key and primary key generation strategy @ Id @ GeneratedValue (strategy = GenerationType.IDENTITY) private Long id; private String account; private String password; private Integer credits;}
BaseDAO public interface BaseDAO extends Mapper, MySqlMapper {}
UserDAO public interface UserDAO extends BaseDAO {}
UserService List selectUsers (); / / query all int addUsers (User user); / / insert int deleteUser (long id); / / delete int updateUser (User user); / / update User selectOneUser (long id); / / query according to id
UserServiceImpl / / Mark that this class is a Service component @ Service / / start a transaction @ Transactional public class UserServiceImpl implements UserService {@ Autowired private UserDAO userDAO; @ Override public List selectUsers () {return userDAO.selectAll ();} @ Override public int addUsers (User user) {return userDAO.insert (user);} @ Override public int deleteUser (long id) {return userDAO.deleteByPrimaryKey (id);} @ Override public int updateUser (User user) {return userDAO.updateByPrimaryKey (user) at the Service layer @ Override public User selectOneUser (long id) {return userDAO.selectByPrimaryKey (id);}}
At this point, I believe you have a deeper understanding of "what is the role of orm in Spring". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.