Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to simplify database operation

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to simplify database operation". In daily operation, I believe many people have doubts about how to simplify database operation. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to simplify database operation"! Next, please follow the editor to study!

When we write code, what makes us suffer the most? I think most people would say repetitive work, but what does repetitive work mean? I thought it might include the following points:

Entity class

Build annotation mappings for sqlMapper.xml, or other frameworks

Build DAO to associate with sqlMapper.xml, or replace sql with code

Controller

So I was thinking, if you don't need entity classes, don't need sqlMapper.xml, don't need Controller, so if you need to develop a back-end function, you just need to write Service, and this section is almost the most interesting part of programming (only application-level programming, low-level development forget what I said)

And Mars-java was born under such a train of thought.

You only need to add two comments to the parent interface of Service to provide a http interface, or you can re-create an interface+ annotation to replace Controller.

Only one line of annotations is needed to operate the database, without sqlMapper.xml

If you can accept non-entity class programming, you can use Map instead of creating entity classes.

Simple exampl

If we need to write a login interface, it only takes a few steps.

Create a DAO@MarsDaopublic abstract class UserInfoDAO {/ / you can return Map or entity class @ MarsSelect (sql = "select * from `userinfo` where uname=# {uname} and passwd=# {passwd}") public abstract List selectUserInfo (Map userInfo);} create Service

By convention, we need to write an interface and then an implementation class

Interface

Public interface UserInfoService {UserInfo login (Map userInfo);}

Implementation class

@ MarsBeanpublic interface UserInfoServiceImpl implements UserInfoService {public UserInfo login (Map userInfo) {/ / call DAO}} here to open a http interface

You only need to add two comments to UserInfoService

MarsApipublic interface UserInfoService {@ MarsReference (beanName = "userInfoServiceImpl", refName = "login") UserInfo login (Map userInfo);}

The whole process saves a lot of repetitive code, so let's focus on the Service layer

At this point, the study on "how to simplify database operation" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report