标签:ring control ace log 使用 连接 ota demo 加密
package com.ssm.util; import java.security.MessageDigest; public class MD5Util { //将字节数组转成十六进制字符串 private static String byteArrayToHexString(byte b[]) { StringBuffer resultSb = new StringBuffer(); for (int i = 0; i < b.length; i++) resultSb.append(byteToHexString(b[i])); return resultSb.toString(); } //对单个字节转换成整数进行取商取余数计算 private static String byteToHexString(byte b) { int n = b; if (n < 0) n += 256; int d1 = n / 16; int d2 = n % 16; //根据下标d1,d2去数组hexDigits的数据 return hexDigits[d1] + hexDigits[d2]; } public static String MD5Encode(String origin, String charsetname) { String resultString = null; try { resultString = new String(origin); // 获得MD5摘要算法的 MessageDigest 对象 MessageDigest md = MessageDigest.getInstance("MD5"); if (charsetname == null || "".equals(charsetname)) //将加密之后的字节数据转换成16进制的字符串 resultString = byteArrayToHexString(md.digest(resultString .getBytes())); else resultString = byteArrayToHexString(md.digest(resultString .getBytes(charsetname))); } catch (Exception exception) { } return resultString; } private static final String hexDigits[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; }
demo目录结构
数据库用户表
CREATE TABLE `user` ( `id` int(20) NOT NULL AUTO_INCREMENT COMMENT ‘编号‘, `userName` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT ‘用户名‘, `password` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT ‘密码‘, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
pojo对象User.java
package com.ssm.pojo; public class User { private Integer id; private String userName; private String password; public Integer getId() { return id; } public void setId(Integer 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; } }
package com.ssm.dao; import com.ssm.pojo.User; public interface UserDao { //用户注册 public int register(User user) ; //登陆 public User login(User user); }
<?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.ssm.dao.UserDao"> <resultMap type="com.ssm.pojo.User" id="UserResult"> <result property="id" column="id" /> <result property="userName" column="userName" /> <result property="password" column="password" /> </resultMap> <select id="login" parameterType="com.ssm.pojo.User" resultMap="UserResult"> select * from user where userName=#{userName} and password=#{password} limit 1 </select> <insert id="register" parameterType="com.ssm.pojo.User"> insert into user(userName,password) values(#{userName},#{password}) </insert> </mapper>
Service层:Service层主要负责业务模块的逻辑应用设计。
UserService.java
package com.ssm.service.impl; import com.ssm.pojo.User; public interface UserService { public User login(User user); public int register(User user); }
UserServiceImpl.java
package com.ssm.service.impl; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.ssm.dao.UserDao; import com.ssm.pojo.User; @Service("userService") public class UserServiceImpl implements UserService { @Resource private UserDao userDao; public User login(User user) { // TODO Auto-generated method stub return userDao.login(user); } public int register(User user) { // TODO Auto-generated method stub return userDao.register(user); } }
RegisterController.java
标签:ring control ace log 使用 连接 ota demo 加密
原文地址:http://www.cnblogs.com/codeRose/p/7267564.html