In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 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.
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.