In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Build MyBatis Generator Plugin Environment
a. Add plug-in dependency pom.xml
org.mybatis.generator mybatis-generator-maven-plugin 1.3.2 src/main/resources/generatorConfig.xml true true Generate MyBatis Artifacts org.mybatis.generator mybatis-generator-core 1.3.2
b. Configuration file generatorConfig.xml
c. Database profile jdbc.properties
jdbc_driverLocation=D:\\Program Files\\Repository\\mysql\\mysql-connector-java\\5.1.38\\mysql-connector-java-5.1.38.jarjdbc_driverClass=com.mysql.jdbc.Driverjdbc_url=jdbc:mysql://localhost:3306/db_test? useUnicode=true&characterEncoding=utf-8jdbc_user=rootjdbc_pwd=123456validationQuery = select 1
d. Configure plug-in startup items
back to top
2. Project combat
The User class is an ordinary entity class that defines the fields corresponding to the database and the set/get methods.
Mybatis introduces the Example class to encapsulate database query criteria.
a. For example, in a project, we want to delete the information of a certain user under a certain group
public int deleteUserApplyInfo(long user_id,long team_id){ StudyTeamUserApplyInfoExample ue = new StudyTeamUserApplyInfoExample(); ue.createCriteria().andUserIdEqualTo(new BigDecimal(user_id)).andTeamIdEqualTo(new BigDecimal(team_id)); return studyTeamUserApplyInfoDAO.deleteByExample(ue); }
2. Update group information based on group ID (non-primary key)
public int updateStudyTeamInfo(StudyTeamInfo st){ StudyTeamInfoExample ste = new StudyTeamInfoExample(); ste.createCriteria().andTeamIdEqualTo(st.getTeamId()); return studyTeamInfoDAO.updateByExampleSelective(st,ste); }
3. (1) Fuzzy queries and sorting (2) queries with a score greater than or equal to and less than a score
public List getStudyTeamInfoByName(String team_name){ StudyTeamInfoExample se = new StudyTeamInfoExample(); se.createCriteria().andTeamNameLike("%"+team_name+"%").andEnableEqualTo((short)1); se.setOrderByClause("team_score desc"); List ls = studyTeamInfoDAO.selectByExample(se); if(ls!= null&&ls.size()>0){ return ls; } return null; }
public StudyTeamLevel getStudyTeamLevel(long score){ StudyTeamLevelExample le = new StudyTeamLevelExample(); le.createCriteria().andNeedScoreLessThanOrEqualTo(score).andUpScoreGreaterThan(score); List ls = studyTeamLevelDAO.selectByExample(le); if(ls!= null&&ls.size()>0){ return ls.get(0); } return null; }
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.