首页 > 代码库 > 三期_day05_Dao层的准备工作_II

三期_day05_Dao层的准备工作_II

工作文件夹:

技术分享


实体类: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

<?xml version="1.0" encoding="UTF-8" ?

> <!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层后面在总结。


我是菜鸟。我在路上。


三期_day05_Dao层的准备工作_II