登录思路:   前台发送一个请求,然后通过spring的自己主动注參注入username和password,将password加密后与数据库中查找的做比較。返回是否通过。

这里还使用了EasyUI的校验控件。不得不说,使用框架真快。不须要写那么多繁杂的脚本代码。

1.页面代码

<form id="ff" method="post" action="UserInfo_login">
<div><label for="name">邮箱:</label> <input id="name" name="email" type="text" /></div>
<div><label for="email">密码:</label> <input id="pwd" name="passwords" type="password"/></div>
</form>

2.脚本代码

<script>
$(function() {
$('#login').dialog({
title : 'CRM后台登录',
modal : true,
closable : false,
draggable:false,
buttons : [ {
text : '登录',
iconCls : 'icon-ok',
handler : function() {
var isValid = $('#ff').form('validate');
if (!isValid){
return false;
}else{
$('#ff').submit();
}
}
} ],
});
start();
}); function start() {
$('#name').validatebox({
required : true,
validType : 'email',
missingMessage : "邮箱为空 ",
invalidMessage : "请输入正确的邮箱"
});
$('#pwd').validatebox({
required : true,
missingMessage : "password为空 "
});
}
</script>

3.Action层代码

注解:

@Controller("userInfoAction")
public class UserInfoAction implements ModelDriven<UserInfo>, SessionAware { @Autowired
private UserInfoService userInfoService;
private UserInfo userInfo;
private String result;
private Map<String, Object> session;
private Object jsondata;

解释一下:

UserInfoService: 通过spring的自己主动注參能够取到业务类对象。

UserInfo: 通过模型驱动,实现getModel方法。就可以获取页面上的输入控件的值,仅仅要name为userInfo中的属性就可以。

result: 是为了转发的,比如登录失败。多种情况时。

session: session的取得是通过实现SessionAware接口,还要实现一个setSession方法。

当然也有ActionContext和ServletActionContext,这样的原理是基于IOC(控制反转)为Action注入參数。其原理就是反射。

jsondata: 这个是为了转发json数据而存在的。

简单来说,这里面的东西就是一个大容器。到处都是spring的自己主动注參。特别是service层,action层,数据持久层,连structs转发也有它的身影。

mybatis+spring+structs2

public String login() {
String password = userInfo.getPasswords(); // 原密码
userInfo.setPasswords(Encrypt.md5(userInfo.getPasswords()));
userInfo = userInfoService.login(userInfo);
if (userInfo != null) {
userInfo.setPasswords(password); // 在页面上显示的是未加密的密码,便于改动
session.put(CrmConstants.USERINFO, userInfo); //存入session中
result = "";
if (userInfo.getPl() == 2) { // 老板
result += "boss/frame"; // ${result}.jsp -> workers/frame.jsp
} else if (userInfo.getPl() == 1) { // 员工
result += "workers/frame";
} else if (userInfo.getPl() == 0) { // 客户
result += "customers/frame";
} else if (userInfo.getPl() == 3) { // 超级管理员
result += "workers/frame";
}
return "login_success";
} else {
return "fail";
}
}

4.Service业务层代码

@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService{ <span style="white-space:pre"> </span>@Autowired
<span style="white-space:pre"> </span>private UserInfoMapper userInfoMapper;

方法

public UserInfo login(UserInfo userInfo) {
return userInfoMapper.findUser(userInfo);
}

5.数据持久层

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);
}

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>
<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>
</mapper>

说明的是:    1. 数据库不同。编写的语句也不同。比如mysql的获取自增主键ID和oracle不同,这个问题至少困扰了几天。

2. 查询的时候。由于实体类和数据库中的字段不同,比如字段为企业ID,而实体类中属性为企业实体类,这个时候查询须要使用join将business表联合起来,否则获取的business实体对象除了ID。其余属性皆为空。

3.假设在这里使用了keyword,不必惊慌。能够加上"UID"来解决。加了"UID"必须大写。

4.mybatis中的标签要合理使用,比如update时候使用if-set标签。if标签的整形推断条件,以下来几个坑过我的样例。

eg 1.0

<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>

eg 1.1

<select id="find" parameterType="OrderDetail" resultMap="BaseResultMap">
select * from crm_order_detail det
join crm_order de on det.o_id=de.o_id
join crm_user_info cu on cu.crm_id=de.c_id
join crm_gods gods on gods.g_id=det.g_id
where de.e_id=#{order.worker.uid}
<if test="state!=null and state>=0">
and det.state=#{state}
</if>
<if test="god!=null and god.name!=null and god.name!='' ">
and gods.g_name like '%'||#{god.name}||'%'
</if>
<!--<if test="odate!=null and udate!=null"> <![CDATA[ >= ]]>
and odate between to_date(#{odate},'yyyy-mm-dd') and to_date(#{udate},'yyyy-mm-dd')
</if> -->
<if test="order!=null and order.customer!=null and order.customer.cname!=null and order.customer.cname!=''">
and cu.cname like '%'||#{order.customer.cname}||'%'
</if>
</select>

1.须要说明的是,上面的日期我还没解决。从前台控件取的日期,到action层为java.util.Date,而数据库的是java.sql.Date,这倆者须要在oracle比較。

2.上面的推断条件不是一步到位,而是一步一步的推断是否为空。

order!=null and order.customer!=null and order.customer.cname!=null and order.customer.cname!=''

3.like查询使用了字符拼接。使用自带函数我没有成功过。

至于找回password,发送请求,后台发送一封邮件至客户邮箱,这个技术不是非常难。

我是菜鸟,我在路上。

最新文章

  1. Process Explorer使用图文教程
  2. Hadoop_HDFS HA 及解决方案
  3. Yii2-redis
  4. [转]Java中的回车换行符/n /r /t
  5. 【转】Yeoman:Web 应用开发流程与工具
  6. ASP.NET5 中静态文件的各种使用方式
  7. Oracle常用几种Sql用法
  8. Visual studio 内存不足的解决方案(out of memory)
  9. php中echo(),print(),print_r()用法
  10. 使用MVC4,Ninject,EF,Moq,构建一个真实的应用电子商务SportsStore
  11. C# backgroundworker使用方法
  12. Linux时间转标准时间
  13. 【NOI 2009】诗人小G
  14. 【c++基础】从json文件提取数据
  15. 安装hyperledger fabric V1.0.1
  16. Prim算法和Kruskal算法求最小生成树
  17. 个推-推送hello world
  18. dubbo_rpc原理
  19. onethink判断是否是手机访问?
  20. mac安装软件提示没有权限

热门文章

  1. C#中动态读取配置
  2. 看懂SqlServer执行计划
  3. HIVE 命令记录
  4. QT设计UI:QT模式对话框打开文件
  5. Python3中替代Python2中cmp()函数的新函数(gt,ge,eq,le,lt)
  6. RN-第三方之react-native-pull 下拉刷新、上拉加载
  7. Object.assign和序列/反序列
  8. js俄罗斯方块
  9. Windows上架设自己的ssh代理 — copSSH
  10. mysql主从机制的部署与应用