三期_day05_Dao层的准备工作_II

原创 2015年07月09日 09:04:04

工作目录:



实体类: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层后面在总结。


我是菜鸟,我在路上。


版权声明:have a nice day! 举报

相关文章推荐

三期_day05_Dao层的准备工作_II

工作目录: 实体类:UserInfo.java  package com.yc.crm.entity; import java.util.Date; public class UserIn...

myflag初期准备工作

这一次,我代表我们组进行答辩,通过了学校的创新项目立项。这次项目的要求比较高,严格按照软件开发的过程来准备,我们自然是全心全意准备。 作为队长的我,担负起了组织队伍的责任。我们首先开了一次碰头会,把基...

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

安装Puppet前期的准备工作

在安装Puppet之前是需要做很多预备工作的,比如网络地址规范、主机名、certname名、时间等等,也只有这些准备好了,才不至于在安装好puppet之后发现问题而后悔莫及。  PS:接下来的整套文档...

准备工作

实现步骤: 1.新建一个javaweb项目,导入相应的jar包,jar包在百度云里面,下次使用直接下载。 2.引入相应的配置文件     Struts2框架的配置文件:            ...

类加载的三个准备工作

1、加载,这是由类加载器执行的。该步骤将查找字节码(通常在classpath所指定的路径中查找,但这并非是必需的),并从这些字节码中创建一个Class对像。 2、链接。在链接阶段将验证类中的字节码,为...

Android准备工作

本人最近对Android兴致大起,打算就此操练起来,特写此类文章纪念一下,日后也好拿出来偷着乐一下。 这里就记述一下从裸机(夸张说法,其实已经穿了一个内裤)到第一个HelloWorld跑起来的过程。...

找工作准备

找工作是一个长期准备的过程,突击是没什么效果的。准备时间越长,准备就越充分,就越容易拿到好的offer。我基本上从研究生一入学就一直在准备找工作的东西,看书、研究研究笔试面试题、在线编程训练、参加实习...

Bootstrap 准备工作

Starter Template for Bootstrap ...

欢迎使用CSDN-markdown编辑器

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和...

01 准备工作

微信开发博主也是刚开始学习,如果又不准确的地方大家可以一起讨论哈QQ:838414520 ,加时请注明来源。谢谢微信开发首先需要自己准备一个域名用于访问 这里博主我准备是一个免费的花生壳域名: ...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)