企业项目开发--企业中的项目架构以及多环境分配(2)
此文已由作者赵计刚授权网易云社区发布。
欢迎访问网易云社区,了解更多网易技术产品运营经验。
2.2.2、ssmm0-data
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- 指定父模块 --> <parent> <groupId>com.xxx</groupId> <artifactId>ssmm0</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.xxx.ssmm0</groupId> <artifactId>ssmm0-data</artifactId> <name>ssmm0-data</name> <packaging>jar</packaging><!-- 只是作为其他模块使用的工具 --> <!-- 引入实际依赖 --> <dependencies> <!-- mysql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 数据源 --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> </dependencies> </project>
注意:<package>为jar
com.xxx.model.userManagement.Admin
package com.xxx.model.userManagement; /** * 管理员 */ public class Admin { private int id; private String username; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
com.xxx.mapper.userManagement.AdminMapper
package com.xxx.mapper.userManagement; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Results; import org.apache.ibatis.annotations.Select; import com.xxx.model.userManagement.Admin; /** * 管理员Mapper */ public interface AdminMapper { @Insert("INSERT INTO userinfo(username, password) VALUES(#{username},#{password})") public int insertAdmin(Admin admin); @Select("SELECT * FROM userinfo WHERE username = #{username} AND password = #{password}") @Results(value = { @Result(id = true, column = "id", property = "id"), @Result(column = "username", property = "username"), @Result(column = "password", property = "password") }) public Admin selectAdmin(@Param("username") String username, @Param("password") String password); }
com.xxx.dao.userManagement.AdminDao
package com.xxx.dao.userManagement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import com.xxx.mapper.userManagement.AdminMapper; import com.xxx.model.userManagement.Admin; /** * 管理员DAO */ @Repository public class AdminDao { @Autowired private AdminMapper adminMapper; public boolean register(Admin admin){ return adminMapper.insertAdmin(admin)==1?true:false; } public Admin login(String username ,String password){ return adminMapper.selectAdmin(username, password); } }
com.xxx.service.userManagement.AdminService
package com.xxx.service.userManagement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.xxx.dao.userManagement.AdminDao; import com.xxx.model.userManagement.Admin; /** * 管理员service */ @Service public class AdminService { @Autowired private AdminDao adminDao; public boolean register(Admin admin){ return adminDao.register(admin); } public Admin login(String username, String password) { return adminDao.login(username, password); } }
代码很简单,与之前的基本一样,只是名字换了而已。
值得注意的是包名:com.xxx.mapper.userManagement而非com.xxx.userManagement.mapper。
免费领取验证码、内容安全、短信发送、直播点播体验包及云服务器等套餐
更多网易技术、产品、运营经验分享请点击。
相关文章:
【推荐】 知物由学 | AI网络安全实战:生成对抗网络
【推荐】 如何实现一个IOS网络监控组件