博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
三期_day05_Dao层的准备工作_II
阅读量:5222 次
发布时间:2019-06-14

本文共 7028 字,大约阅读时间需要 23 分钟。

工作文件夹:

实体类:UserInfo.java 

package com.yc.crm.entity;import java.util.Date;public class UserInfo {	    private Integer uid;    private String email;    private String passwords;    private String cname;    private String phone;    private Integer sex;    private Integer age;    private String address;    private Integer level;    private Integer pl;    private Business bussiness;    private Date createdate;	public Integer getUid() {		return uid;	}	public void setUid(Integer uid) {		this.uid = uid;	}	public String getEmail() {		return email;	}	public void setEmail(String email) {		this.email = email;	}	public String getPasswords() {		return passwords;	}	public void setPasswords(String passwords) {		this.passwords = passwords;	}	public String getCname() {		return cname;	}	public void setCname(String cname) {		this.cname = cname;	}	public String getPhone() {		return phone;	}	public void setPhone(String phone) {		this.phone = phone;	}	public Integer getSex() {		return sex;	}	public void setSex(Integer sex) {		this.sex = sex;	}	public Integer getAge() {		return age;	}	public void setAge(Integer age) {		this.age = age;	}	public String getAddress() {		return address;	}	public void setAddress(String address) {		this.address = address;	}	public Integer getLevel() {		return level;	}	public void setLevel(Integer level) {		this.level = level;	}	public Integer getPl() {		return pl;	}	public void setPl(Integer pl) {		this.pl = pl;	}	public Business getBussiness() {		return bussiness;	}	public void setBussiness(Business bussiness) {		this.bussiness = bussiness;	}	public Date getCreatedate() {		return createdate;	}	public void setCreatedate(Date createdate) {		this.createdate = createdate;	}	@Override	public String toString() {		return "UserInfo [uid=" + uid + ", email=" + email + ", passwords="				+ passwords + ", cname=" + cname + ", phone=" + phone				+ ", sex=" + sex + ", age=" + age + ", address=" + address				+ ", level=" + level + ", pl=" + pl + ", bussiness="				+ bussiness + ", createdate=" + createdate + "]";	}}

2.配置文件UserInfoMapper.xml

> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.yc.crm.mapper.UserInfoMapper"> <resultMap id="BaseResultMap" type="com.yc.crm.entity.UserInfo"> <id column="CRM_ID" property="uid" /> <result column="EMAIL" property="email" /> <result column="PASSWORDS" property="passwords" /> <result column="CNAME" property="cname" /> <result column="PHONE" property="phone" /> <result column="SEX" property="sex" /> <result column="AGE" property="age" /> <result column="ADDRESS" property="address" /> <result column="USERLEVEL" property="level" /> <result column="PL" property="pl" /> <result column="CREATEDATE" property="createdate" /> <association property="bussiness" resultMap="com.yc.crm.mapper.BusinessMapper.BaseResultMap" /> </resultMap> <delete id="deleteUserByUid" parameterType="int"> delete crm_user_info where crm_id=#{uid} </delete> <update id="modify" parameterType="UserInfo"> update crm_user_info <set> <if test="passwords!=null and passwords!=''"> passwords=#{passwords}, </if> phone=#{phone},sex=#{sex},"AGE"=#{age},userlevel=#{level},address=#{address} where email=#{email} </set> </update> <select id="getUserInfoById" parameterType="int" resultMap="BaseResultMap"> select * from crm_user_info u join crm_business b on u.bussiness_id=b.business_id where u.crm_id=#{id} </select> <select id="vailEmail" resultType="int"> select count(*) from crm_user_info where email=#{email} </select> <select id="findUser" parameterType="UserInfo" resultMap="BaseResultMap"> select * from crm_user_info u join crm_business b on u.bussiness_id=b.business_id where u.email=#{email} and u.passwords=#{passwords} </select> <update id="updateUserInfoDate" parameterType="UserInfo"> update crm_user_info set createdate=sysdate where email=#{email} </update> <insert id="insertUserInfo" parameterType="UserInfo"> <selectKey resultType="int" order="BEFORE" keyProperty="uid"> SELECT SEQ_CRM_USER_INFO_SEQ.Nextval from DUAL </selectKey> insert into crm_user_info values(#{uid},#{email},#{passwords},#{cname},#{phone},#{sex},#{age},#{address},#{level},#{pl},#{bussiness.businessId},sysdate) </insert> </mapper>

 

3.与配置文件相应的接口UserInfoMapper.java

package com.yc.crm.mapper;import com.yc.crm.entity.UserInfo;public interface UserInfoMapper {    UserInfo getUserInfoById(int id);    int insertUserInfo(UserInfo userInfo);	UserInfo findUser(UserInfo userInfo);	int updateUserInfoDate(UserInfo userInfo);	int vailEmail(String email);	int modify(UserInfo userInfo);	int deleteUserByUid(int uid);}
4.測试类  

package com.yc.crm.test.conn;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.yc.crm.biz.UserInfoService;import com.yc.crm.entity.Business;import com.yc.crm.entity.UserInfo;import com.yc.crm.utils.Encrypt;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:spring.xml")public class TestUserInfoImplTest {	@Autowired	private UserInfoService userInfoService;	@Test	public void testDelete(){		UserInfo ui=new UserInfo();		ui.setUid(84);		int result=userInfoService.deleteUserInfo(ui);		System.out.println(result);	}		/*	 * UserInfo [uid=1116, email=testadd6@qq.com,	 * passwords=900150983cd24fb0d6963f7d28e17f72, cname=測试加入6,	 * phone=15211441233, sex=1, age=21, address=USCofChina, level=0, pl=0,	 * bussiness=Business [businessId=104, businessName=奔驰4S,	 * businessType=<200], createdate=Wed Jun 24 16:47:02 CST 2015]	 */	@Test	public void testModify() {		UserInfo ui = userInfoService.getInfo(1116);		ui.setAddress("这是新的。看看能成功吗");		ui.setPasswords("hehe");		ui = userInfoService.modify(ui);		System.out.println(ui);	}	@Test	public void testVailEmail() {		int re = userInfoService.vailEmail("chenjian@qq.com");		System.out.println(re);	}	@Test	public void testLogin() {		UserInfo ui = new UserInfo();		ui.setEmail("chenjian@qq.com");		ui.setPasswords(Encrypt.md5("abc"));		ui = userInfoService.login(ui);		System.out.println(ui);	}	@Test	public void testGetUserInfoById() {		UserInfo ui = userInfoService.getInfo(1116);		System.out.println(ui);	}	@Test	public void testInsertUserInfo() {		UserInfo userinfo = new UserInfo();		userinfo.setAddress("纽约");		userinfo.setAge(23);		Business b = new Business();		b.setBusinessId(102);		userinfo.setBussiness(b);		userinfo.setCname("淡定淡定淡定");		userinfo.setEmail("che@qq.com");		userinfo.setLevel(4);		userinfo.setPasswords("abc");		userinfo.setPhone("15544778788");		userinfo.setPl(0);		userinfo.setSex(0);		System.out.println(userinfo);		boolean isSucccess = userInfoService.register(userinfo, 1005);		int id = userinfo.getUid();		System.out.println("isSucccess is :" + isSucccess);		System.out.println("id is :" + id);	}}
已经完毕了Dao层和Model层,Service和Action层后面在总结。

我是菜鸟。我在路上。

转载于:https://www.cnblogs.com/gccbuaa/p/7210678.html

你可能感兴趣的文章
HTML5触摸事件演化tap事件
查看>>
git使用记录
查看>>
国外物联网平台初探(二) ——微软Azure IoT
查看>>
Java中集合Set的用法
查看>>
Android瀑布流照片墙实现,体验不规则排列的美感
查看>>
Swift - 使用arc4random()、arc4random_uniform()取得随机数
查看>>
android Json解析详解
查看>>
Android应用程序窗口(Activity)与WindowManagerService服务的连接过程分析
查看>>
《大道至简》第五章读后感
查看>>
Python之 continue继续循环
查看>>
JVM常见配置汇总
查看>>
HDU 5278 PowMod 数论公式推导
查看>>
MIT研发的新型匿名网络Riffle,下一个Tor
查看>>
怎样编写高质量的java代码
查看>>
django 连接mssql 数据库(django 1.11.11 sql server 2008 R2)
查看>>
python subprocess 小例子
查看>>
第8910章
查看>>
ORACLE 取字段值首字母
查看>>
Access-Control-Allow-Origin跨域请求处理
查看>>
STM32个人笔记
查看>>