This commit is contained in:
landaiqing 2023-11-14 15:03:36 +08:00
commit 2f3d218368
187 changed files with 27459 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
### Example user template template
### Example user template
# IntelliJ project files
.idea
*.iml
out
gen

BIN
lib/aopalliance-1.0.jar Normal file

Binary file not shown.

BIN
lib/commons-logging-1.2.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

35
resource/application.xml Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 1、引入外部 properties 文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 2、注册数据源 -->
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}" />
<property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
<property name="user" value="${jdbc.user}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!--3、配置Session工厂对象-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--4、配置扫描的包-->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="ah.com.dao"></property>
</bean>
<!--5、扫描对应的类 IOC创建对象 -->
<!--扫描注解的类-->
<context:component-scan base-package="ah.com.service.impl"></context:component-scan>
</beans>

4
resource/jdbc.properties Normal file
View File

@ -0,0 +1,4 @@
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/shop?characterEncoding=UTF-8
jdbc.user=root
jdbc.password=1611

206
shop.sql Normal file
View File

@ -0,0 +1,206 @@
/*
Navicat MySQL Data Transfer
Source Server : 127.0.0.1
Source Server Version : 50528
Source Host : localhost:3306
Source Database : chapter16
Target Server Type : MYSQL
Target Server Version : 50528
File Encoding : 65001
Date: 2019-09-03 09:17:00
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for t_cart
-- ----------------------------
DROP TABLE IF EXISTS `t_cart`;
CREATE TABLE `t_cart` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`money` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_cart
-- ----------------------------
INSERT INTO `t_cart` VALUES ('1', '4', '0');
INSERT INTO `t_cart` VALUES ('2', '5', '0');
INSERT INTO `t_cart` VALUES ('3', '6', '0');
INSERT INTO `t_cart` VALUES ('4', '7', '0');
INSERT INTO `t_cart` VALUES ('5', '1', '0');
INSERT INTO `t_cart` VALUES ('6', '9', '0');
INSERT INTO `t_cart` VALUES ('7', '10', '0');
INSERT INTO `t_cart` VALUES ('8', '13', '0');
INSERT INTO `t_cart` VALUES ('9', '14', '0');
-- ----------------------------
-- Table structure for t_cartdetail
-- ----------------------------
DROP TABLE IF EXISTS `t_cartdetail`;
CREATE TABLE `t_cartdetail` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cid` int(11) DEFAULT NULL,
`gid` int(11) DEFAULT NULL,
`num` int(11) DEFAULT NULL,
`money` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_cartdetail
-- ----------------------------
-- ----------------------------
-- Table structure for t_goods
-- ----------------------------
DROP TABLE IF EXISTS `t_goods`;
CREATE TABLE `t_goods` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`price` bigint(20) DEFAULT NULL,
`pubdate` date DEFAULT NULL,
`typeName` varchar(20) DEFAULT NULL,
`intro` varchar(200) DEFAULT NULL,
`picture` varchar(150) DEFAULT NULL,
`flag` int(11) DEFAULT NULL COMMENT '1上架 2下架',
`star` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_goods
-- ----------------------------
INSERT INTO `t_goods` VALUES ('1', '可口可乐', '32', '2018-11-25', '酒水饮料', '巴厘岛原装进口 百事可乐(Pepsi) blue 蓝色可乐 网红可乐汽水饮料 450ml*4瓶装', '201811/7b001eee-38df-4c66-9a0f-350879007402_js1.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('2', '易拉罐可口可乐', '88', '2018-11-25', '酒水饮料', '日本原装进口 可口可乐(Coca-Cola)碳酸饮料 500ml*6罐味道谁喝谁知道', '201811/f65d85f4-a622-4f6b-bbdf-2e354d7b0737_js2.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('3', '干红', '480', '2018-11-25', '酒水饮料', '自营张裕CHANGYU红酒 张裕干红葡萄酒750ml*6瓶彩龙版', '201811/fa61ef77-4adc-4895-962b-fcb084e3e809_js3.jpg', '1', '4');
INSERT INTO `t_goods` VALUES ('4', '进口红酒', '999', '2018-11-25', '酒水饮料', '法国进口红酒 拉菲LAFITE传奇波尔多干红葡萄酒 双支礼盒装带酒具 750ml*2瓶', '201811/cb233c79-2f18-4f97-afad-0d2079098345_js4.jpg', '1', '3');
INSERT INTO `t_goods` VALUES ('5', '草莓饼干', '8', '2018-11-25', '饼干糕点', '土斯Totaste 葡萄味夹层饼干(含葡萄果粒) 休闲零食蛋糕甜点心 实惠分享装360g', '201811/afdd4cd4-9782-46a5-96ed-0ba3c4036379_bg1.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('6', '蔬菜棒', '12', '2018-11-25', '饼干糕点', '土斯Totaste 混合蔬菜味棒形饼干 酥脆可口 独立包装 休闲零食蛋糕甜点心小吃 128g', '201811/8bdbdb3f-4cb6-4af8-9c6f-183411537726_bg2.jpg', '1', '4');
INSERT INTO `t_goods` VALUES ('7', '曲奇', '58', '2018-11-25', '饼干糕点', '丹麦进口 皇冠danisa丹麦曲奇精选礼盒装908g(新老包装随机发货)', '201811/db2a101d-600a-44c5-8d0f-0a3b173f81aa_bg3.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('8', '夹心饼干', '16', '2018-11-25', '饼干糕点', '马来西亚原装进口 茱蒂丝Julie\'s雷蒙德巧克力榛果夹心饼干180g×2', '201811/3b047c04-6b23-491d-bf9c-5405cf36c308_bg4.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('9', '玉米棒', '18', '2018-11-25', '休闲零食', '印尼进口 Nabati 丽芝士Richeese雅嘉 休闲零食 奶酪味 玉米棒 400g/盒 早餐下午茶', '201811/287f1938-f039-4d24-9942-3c8a456d757b_ls1.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('10', '千层酥', '8', '2018-11-25', '休闲零食', '葡韵手信 澳门特产 休闲零食 传统糕点小吃 千层酥150g 新旧包装随机发货', '201811/7570a0dc-eacb-4b61-9085-966ac322172f_ls2.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('11', '海苔', '10', '2018-11-25', '休闲零食', '泰国原装进口休闲零食 老板仔 超大片烤海苔脆紫菜 经典原味 54g/袋(新老包装随机发货)', '201811/62c5370b-2f32-450f-ba4c-401a004d5270_ls3.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('12', '提子干', '5', '2018-11-25', '休闲零食', '三只松鼠无核白葡萄干蜜饯果干休闲食品新疆特产提子干120g/袋', '201811/4e807511-5515-4ec8-9e20-41e8f49ece66_ls4.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('13', '青岛啤酒', '118', '2018-11-25', '酒水饮料', '青岛啤酒TsingTao 青岛啤酒经典10度 500ml*24听好喝又实惠', '201811/555da004-a18c-4fa9-9f23-094551928831_js5.jpg', '1', '5');
INSERT INTO `t_goods` VALUES ('14', '手撕面包', '19', '2018-11-25', '饼干糕点', '三只松鼠 手撕面包1000g整箱装零食大礼包口袋面包孕妇零食早餐食品生日蛋糕小糕点点心礼盒装', '201811/12a3f75c-8ddd-41d8-862f-93f342e5e41e_bg5.png', '1', '5');
INSERT INTO `t_goods` VALUES ('15', '开心果', '13', '2018-11-25', '休闲零食', '满199减120三只松鼠 开心果100g坚果炒货零食每日坚果 1袋装', '201811/d468a868-a7b8-4ad6-bde1-124e23c66437_ls5.jpg', '1', '5');
-- ----------------------------
-- Table structure for t_goodstype
-- ----------------------------
DROP TABLE IF EXISTS `t_goodstype`;
CREATE TABLE `t_goodstype` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`level` int(11) DEFAULT NULL COMMENT '1或2',
`parentName` varchar(20) DEFAULT NULL,
`flag` int(11) DEFAULT NULL COMMENT '1有效 2无效',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_goodstype
-- ----------------------------
INSERT INTO `t_goodstype` VALUES ('1', '酒水饮料', '1', null, '1');
INSERT INTO `t_goodstype` VALUES ('2', '饼干糕点', '1', null, '1');
INSERT INTO `t_goodstype` VALUES ('3', '休闲零食', '1', null, '1');
INSERT INTO `t_goodstype` VALUES ('4', '喂养用品', '1', null, '1');
INSERT INTO `t_goodstype` VALUES ('5', '洗护用品', '1', null, '1');
INSERT INTO `t_goodstype` VALUES ('6', '美妆个护', '1', null, '1');
INSERT INTO `t_goodstype` VALUES ('7', '', '1', null, '1');
-- ----------------------------
-- Table structure for t_order
-- ----------------------------
DROP TABLE IF EXISTS `t_order`;
CREATE TABLE `t_order` (
`id` varchar(100) NOT NULL,
`uaid` int(11) DEFAULT NULL,
`uid` int(11) DEFAULT NULL,
`createtime` datetime DEFAULT NULL,
`money` bigint(20) DEFAULT NULL,
`flag` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_order
-- ----------------------------
INSERT INTO `t_order` VALUES ('20190903091114465585f704e-e430-4d26-80ba-144e958cc7b0', '12', '13', '2019-09-03 09:11:14', '352', '1');
INSERT INTO `t_order` VALUES ('201909030912505485dde283b-f42d-43ec-a7bb-b6b949465d4f', '14', '13', '2019-09-03 09:12:50', '118', '2');
INSERT INTO `t_order` VALUES ('201909030913066619e056ba1-ed64-4688-8da3-d7c5c1a0a309', '12', '13', '2019-09-03 09:13:06', '13', '3');
INSERT INTO `t_order` VALUES ('2019090309131945984429b26-dfe6-423f-a39a-835272ea9820', '12', '13', '2019-09-03 09:13:19', '64', '4');
-- ----------------------------
-- Table structure for t_orderdetail
-- ----------------------------
DROP TABLE IF EXISTS `t_orderdetail`;
CREATE TABLE `t_orderdetail` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`gid` int(11) DEFAULT NULL,
`oid` varchar(100) DEFAULT NULL,
`money` bigint(20) DEFAULT NULL,
`num` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_orderdetail
-- ----------------------------
INSERT INTO `t_orderdetail` VALUES ('64', '2', '20190903091114465585f704e-e430-4d26-80ba-144e958cc7b0', '352', '4');
INSERT INTO `t_orderdetail` VALUES ('65', '7', '201909030912505485dde283b-f42d-43ec-a7bb-b6b949465d4f', '58', '1');
INSERT INTO `t_orderdetail` VALUES ('66', '6', '201909030912505485dde283b-f42d-43ec-a7bb-b6b949465d4f', '24', '2');
INSERT INTO `t_orderdetail` VALUES ('67', '9', '201909030912505485dde283b-f42d-43ec-a7bb-b6b949465d4f', '36', '2');
INSERT INTO `t_orderdetail` VALUES ('68', '15', '201909030913066619e056ba1-ed64-4688-8da3-d7c5c1a0a309', '13', '1');
INSERT INTO `t_orderdetail` VALUES ('69', '1', '2019090309131945984429b26-dfe6-423f-a39a-835272ea9820', '64', '2');
-- ----------------------------
-- Table structure for t_user
-- ----------------------------
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`role` int(11) DEFAULT NULL COMMENT '角色类型 0管理员 1会员',
`username` varchar(50) DEFAULT NULL,
`password` varchar(50) DEFAULT NULL,
`email` varchar(30) DEFAULT NULL,
`gender` varchar(2) DEFAULT NULL,
`createtime` datetime DEFAULT NULL,
`flag` int(11) DEFAULT NULL COMMENT '标记位 1未激活 2有效 3临时无效 4永久无效',
`activatecode` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_user
-- ----------------------------
INSERT INTO `t_user` VALUES ('1', '1', 'admin', '21232f297a57a5a743894a0e4a801fc3', 'admin', '', '2018-11-25 17:22:22', '2', null);
INSERT INTO `t_user` VALUES ('13', '1', '千锋教育', 'e10adc3949ba59abbe56e057f20f883e', '123456789@qq.com', '', '2019-09-02 15:51:55', '2', '20190902155155296351');
-- ----------------------------
-- Table structure for t_useraddress
-- ----------------------------
DROP TABLE IF EXISTS `t_useraddress`;
CREATE TABLE `t_useraddress` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`phone` varchar(20) DEFAULT NULL,
`detail` varchar(150) DEFAULT NULL,
`uid` int(11) DEFAULT NULL,
`flag` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_useraddress
-- ----------------------------
INSERT INTO `t_useraddress` VALUES ('9', '好程序员', '66666666666', '北京市海淀区西三旗校区', '9', '1');
INSERT INTO `t_useraddress` VALUES ('12', '千锋教育', '88888888888', '北京市海淀区宝盛北里西区28号智诚科创大厦4层', '13', '3');
INSERT INTO `t_useraddress` VALUES ('14', 'Java', '00000000000', '北京市昌平区', '13', '1');

View File

@ -0,0 +1,16 @@
package ah.com.common.utils;
import java.util.Base64;
/**
* 基于JDK1.8实现的BASE64编码
* 编码
* 解码*/
public class Base64Utils {
//编码
public static String encode(String msg){
return Base64.getEncoder().encodeToString(msg.getBytes());
}
//解码
public static String decode(String msg){
return new String(Base64.getDecoder().decode(msg));
}
}

View File

@ -0,0 +1,277 @@
/**
* @Title: DbUtils.java
* @Package com.qf.common
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月24日
* @version V1.0
*/
package ah.com.common.utils;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.alibaba.druid.pool.DruidDataSource;
public class DbUtils {
private static String driverclass = "com.mysql.jdbc.Driver";
private static String dburl = "jdbc:mysql://localhost:3306/shop1";
private static String username = "root";
private static String password = "root";
// 数据库连接池
private static DruidDataSource ds;
private static Connection conn;
static {
ds.setDriverClassName(driverclass);
ds.setUrl(dburl);
ds.setUsername(username);
ds.setPassword(password);
ds.setTimeBetweenEvictionRunsMillis(6000);
}
// 执行非查询语句
public static int executeUpdate(String sql, Object... vlus) {
try {
conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
for (int i = 0; i < vlus.length; i++) {
ps.setObject(i + 1, vlus[i]);
}
int r = ps.executeUpdate();
conn.close();
return r;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
// 带事务 执行多条语句
// 执行非查询语句
/**
* 开启事务执行多条SQL语句
*
* @param sqls
* 需要执行的sql语句 顺序和参数一一对应 如果没参数那是也需要添加一个null对象
* @param vals
* 对应sql语句的参数的值 不存在就是null
* @return 1 成功 0 失败
*/
public static int executeUpdateBatch(List<String> sqls, List<List<Object>> vals) {
try {
conn = ds.getConnection();
try {
// 开启事务
conn.setAutoCommit(false);
for (int i = 0; i < sqls.size(); i++) {
//System.out.println(sqls.get(i) + "--->" + vals.get(i).size());
PreparedStatement ps = conn.prepareStatement(sqls.get(i));
if (vals.get(i) != null) {
for (int j = 0; j < vals.get(i).size(); j++) {
ps.setObject(j + 1, vals.get(i).get(j));
}
}
ps.executeUpdate();
}
// 提交事务
conn.commit();
return 1;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
try {
// 回滚事务
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
return 0;
}
// 执行查询语句
public static ResultSet executeQuery(String sql, Object... vlus) {
try {
conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
for (int i = 0; i < vlus.length; i++) {
ps.setObject(i + 1, vlus[i]);
}
return ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 查询的二次封装返回泛型 单个对象
public static <T> T querySingle(String sql, Class<T> clz, Object... vlus) {
try {
// 获取数据库连接对象
conn = ds.getConnection();
// 获取操作sql对象 防止SQL注入
PreparedStatement ps = conn.prepareStatement(sql);
// 赋值 设置参数
for (int i = 0; i < vlus.length; i++) {
ps.setObject(i + 1, vlus[i]);
}
// 执行查询
ResultSet rs = ps.executeQuery();
// 从ResultSet中获取数据
if (rs.next()) {
// 通过反射创建类的对象
T obj = clz.newInstance();
// 获取类中所有的属性
Field[] arrf = clz.getDeclaredFields();
// 遍历属性
for (Field f : arrf) {
/*System.out.println(f.getName()+"-222--->"+rs.findColumn(f.getName()));
if (rs.findColumn(f.getName()) > 0) {*/
// 设置忽略访问校验
f.setAccessible(true);
try {
if (f.getName().equals("price") || f.getName().equals("money")) {
f.set(obj, rs.getLong(f.getName()) / 100.0);
} else {
// 赋值
f.set(obj, getV(rs, f.getName()));
}
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
/*}*/
}
// 关闭
rs.close();
ps.close();
conn.close();
return obj;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 根据数据库表的字段的数据类型 自动类型转换
public static Object getV(ResultSet rs, String name) {
ResultSetMetaData ma;
Object res = null;
try {
ma = rs.getMetaData();
String type = ma.getColumnTypeName(rs.findColumn(name));
//System.out.println(type);
switch (type) {
case "DATE":
Date date1 = rs.getDate(name);
res = new SimpleDateFormat("yyyy-MM-dd").format(date1);
break;
case "DATETIME":
Date date2 = rs.getDate(name);
res = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date2);
break;
/*
* case "INT": res=rs.getInt(name); break;
*/
default:
res = rs.getObject(name);
break;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return res;
}
// 查询的二次封装返回泛型 集合
// 查询的二次封装返回泛型 单个对象
public static <T> List<T> queryList(String sql, Class<T> clz, Object... vlus) {
try {
conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
for (int i = 0; i < vlus.length; i++) {
ps.setObject(i + 1, vlus[i]);
}
ResultSet rs = ps.executeQuery();
List<T> list = new ArrayList<>();
while (rs.next()) {
// 通过反射创建类的对象
T obj = clz.newInstance();
// 获取类中所有的属性
Field[] arrf = clz.getDeclaredFields();
// 遍历属性
for (Field f : arrf) {
/*System.out.println(f.getName()+"---333---->"+rs.findColumn(f.getName()));
if (rs.findColumn(f.getName()) > 0) {*/
// 设置忽略访问校验
f.setAccessible(true);
// 赋值
try {
if (f.getName().equals("price") || f.getName().equals("money")) {
f.set(obj, rs.getLong(f.getName()) / 100.0);
} else {
// 赋值
f.set(obj, getV(rs, f.getName()));
}
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
//}
list.add(obj);
}
rs.close();
ps.close();
conn.close();
return list;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 查询数量 泛型整型
public static void close(ResultSet rs) {
try {
rs.close();
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,86 @@
package ah.com.common.utils;
import java.io.UnsupportedEncodingException;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import ah.com.domain.User;
/*
* 基于JDK实现邮件发送
* 主要是实现激活码的发送
* */
public class EmailUtils {
public static void sendEmail(User user){
//邮箱
String myAccount = "lx_teach@163.com";
//授权码
String myPass = "java168";
//邮箱服务器
String SMTPHost = "smtp.163.com";
//设置属性信息
Properties prop = new Properties();
//设置协议
prop.setProperty("mail.transport.protocol", "smtp");
//邮件服务器
prop.setProperty("mail.smtp.host", SMTPHost);
//认证
prop.setProperty("mail.smtp.auth", "true");
//1创建会话
Session session = Session.getDefaultInstance(prop);
//设置是否需要调试
session.setDebug(false);
//2创建发送信息
MimeMessage message = createMsg(session,myAccount,user);
//4发送信息操作
try {
Transport tran = session.getTransport();
//连接
tran.connect(myAccount, myPass);
//发送消息
tran.sendMessage(message, message.getAllRecipients());
//关闭
tran.close();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//生成邮件消息
private static MimeMessage createMsg(Session session, String myAccount, User user) {
//创建消息对象
MimeMessage message = new MimeMessage(session);
//设置
try {
//3.1发送方
message.setFrom(new InternetAddress(myAccount, "锋迷网官方邮件", "utf-8"));
//3.2设置接收方
/*
* MimeMessage.RecipientType.TO
* MimeMessage.RecipientType.CC
* MimeMessage.RecipientType.BCC
* */
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(user.getEmail(), user.getUsername(), "utf-8"));
//3.3 设置主题
message.setSubject("锋迷网激活码","utf-8");
//获取本机的ip地址
String ip = Inet4Address.getLocalHost().getHostAddress();
String url = "http://"+ip+":8080/myshop33/activate?e="+ Base64Utils.encode(user.getEmail())+"&c="+Base64Utils.encode(user.getActivatecode());
//设置正文信息
message.setContent(user.getUsername()+",欢迎你加入我们<br>为了更好体验我们的产品,请<a href='"+url+"'>点击激活 "+url+"</a>","text/html;charset=utf-8");
//设置日期
message.setSentDate(new Date());
//保存
message.saveChanges();
} catch (UnsupportedEncodingException | MessagingException | UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return message;
}
}

View File

@ -0,0 +1,39 @@
/**
* @Title: FileUtils.java
* @Package com.qfedu.common.utils
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月29日
* @version V1.0
*/
package ah.com.common.utils;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
public class FileUtils {
//创建文件夹 一个月一个文件夹
public static File createDir(String dir) {
//子文件名称201805 201806
String month=new SimpleDateFormat("yyyyMM").format(new Date());
File dir1=new File(new File(dir).getParent(),"fmwimages");
File dir2=new File(dir1,month) ;
if(!dir2.exists()) {
dir2.mkdirs();
}
return dir2;
}
//创建唯一名称
public static String createFileName(String fn) {
if(fn.length()>30) {
fn=fn.substring(fn.length()-30);
}
return UUID.randomUUID().toString()+"_"+fn;
}
}

View File

@ -0,0 +1,21 @@
package ah.com.common.utils;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
//MD5 摘要算法 签名或者简易加解密
public class MD5Utils {
public static String md5(String password){
try {
//获取摘要对象
MessageDigest md = MessageDigest.getInstance("MD5");
//设置要签名的内容
md.update(password.getBytes());
//获取摘要结果
return new BigInteger(1, md.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,214 @@
package ah.com.common.utils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
public class PaymentUtil {
private static String encodingCharset = "UTF-8";
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>hmac<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param p0_Cmd ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param p1_MerId <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param p2_Order <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param p3_Amt ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param p4_Cur <EFBFBD><EFBFBD><EFBFBD>ױ<EFBFBD><EFBFBD><EFBFBD>
* @param p5_Pid <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param p6_Pcat <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param p7_Pdesc <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param p8_Url <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĵ<EFBFBD>ַ
* @param p9_SAF <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>ַ
* @param pa_MP <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>Ϣ
* @param pd_FrpId <EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>
* @param pr_NeedResponse Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param keyValue <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD>Կ
* @return
*/
public static String buildHmac(String p0_Cmd,String p1_MerId,
String p2_Order, String p3_Amt, String p4_Cur,String p5_Pid, String p6_Pcat,
String p7_Pdesc,String p8_Url, String p9_SAF,String pa_MP,String pd_FrpId,
String pr_NeedResponse,String keyValue) {
StringBuilder sValue = new StringBuilder();
// ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p0_Cmd);
// <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p1_MerId);
// <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p2_Order);
// ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p3_Amt);
// <EFBFBD><EFBFBD><EFBFBD>ױ<EFBFBD><EFBFBD><EFBFBD>
sValue.append(p4_Cur);
// <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p5_Pid);
// <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p6_Pcat);
// <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p7_Pdesc);
// <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĵ<EFBFBD>ַ
sValue.append(p8_Url);
// <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>ַ
sValue.append(p9_SAF);
// <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>Ϣ
sValue.append(pa_MP);
// <EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>
sValue.append(pd_FrpId);
// Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(pr_NeedResponse);
return PaymentUtil.hmacSign(sValue.toString(), keyValue);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD>hmac<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param hmac ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>
* @param p1_MerId <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param r0_Cmd ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param r1_Code ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param r2_TrxId <EFBFBD>ױ<EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><EFBFBD>
* @param r3_Amt ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param r4_Cur <EFBFBD><EFBFBD><EFBFBD>ױ<EFBFBD><EFBFBD><EFBFBD>
* @param r5_Pid <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param r6_Order <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param r7_Uid <EFBFBD>ױ<EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԱID
* @param r8_MP <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>Ϣ
* @param r9_BType <EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param keyValue <EFBFBD><EFBFBD>Կ
* @return
*/
public static boolean verifyCallback(String hmac, String p1_MerId,
String r0_Cmd, String r1_Code, String r2_TrxId, String r3_Amt,
String r4_Cur, String r5_Pid, String r6_Order, String r7_Uid,
String r8_MP, String r9_BType, String keyValue) {
StringBuilder sValue = new StringBuilder();
// <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(p1_MerId);
// ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(r0_Cmd);
// ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(r1_Code);
// <EFBFBD>ױ<EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><EFBFBD>
sValue.append(r2_TrxId);
// ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(r3_Amt);
// <EFBFBD><EFBFBD><EFBFBD>ױ<EFBFBD><EFBFBD><EFBFBD>
sValue.append(r4_Cur);
// <EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(r5_Pid);
// <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(r6_Order);
// <EFBFBD>ױ<EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԱID
sValue.append(r7_Uid);
// <EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>Ϣ
sValue.append(r8_MP);
// <EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sValue.append(r9_BType);
String sNewString = PaymentUtil.hmacSign(sValue.toString(), keyValue);
return sNewString.equals(hmac);
}
/**
* @param aValue
* @param aKey
* @return
*/
public static String hmacSign(String aValue, String aKey) {
byte k_ipad[] = new byte[64];
byte k_opad[] = new byte[64];
byte keyb[];
byte value[];
try {
keyb = aKey.getBytes(encodingCharset);
value = aValue.getBytes(encodingCharset);
} catch (UnsupportedEncodingException e) {
keyb = aKey.getBytes();
value = aValue.getBytes();
}
Arrays.fill(k_ipad, keyb.length, 64, (byte) 54);
Arrays.fill(k_opad, keyb.length, 64, (byte) 92);
for (int i = 0; i < keyb.length; i++) {
k_ipad[i] = (byte) (keyb[i] ^ 0x36);
k_opad[i] = (byte) (keyb[i] ^ 0x5c);
}
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
return null;
}
md.update(k_ipad);
md.update(value);
byte dg[] = md.digest();
md.reset();
md.update(k_opad);
md.update(dg, 0, 16);
dg = md.digest();
return toHex(dg);
}
public static String toHex(byte input[]) {
if (input == null)
return null;
StringBuffer output = new StringBuffer(input.length * 2);
for (int i = 0; i < input.length; i++) {
int current = input[i] & 0xff;
if (current < 16)
output.append("0");
output.append(Integer.toString(current, 16));
}
return output.toString();
}
/**
*
* @param args
* @param key
* @return
*/
public static String getHmac(String[] args, String key) {
if (args == null || args.length == 0) {
return (null);
}
StringBuffer str = new StringBuffer();
for (int i = 0; i < args.length; i++) {
str.append(args[i]);
}
return (hmacSign(str.toString(), key));
}
/**
* @param aValue
* @return
*/
public static String digest(String aValue) {
aValue = aValue.trim();
byte value[];
try {
value = aValue.getBytes(encodingCharset);
} catch (UnsupportedEncodingException e) {
value = aValue.getBytes();
}
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
return toHex(md.digest(value));
}
// public static void main(String[] args) {
// System.out.println(hmacSign("AnnulCard1000043252120080620160450.0http://localhost/SZXpro/callback.asp<73>?4564868265473632445648682654736324511","8UPp0KE8sq73zVP370vko7C39403rtK1YwX40Td6irH216036H27Eb12792t"));
// }
}

View File

@ -0,0 +1,20 @@
package ah.com.common.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.UUID;
//随机数
public class RandomUtils {
//生成激活码
public static String createActive(){
return getTime()+Integer.toHexString(new Random().nextInt(900)+100);
}
//设置时间戳
public static String getTime(){
return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime());
}
//生成订单编号
public static String createOrderId(){
return getTime()+UUID.randomUUID().toString();
}
}

View File

@ -0,0 +1,18 @@
package ah.com.common.utils;
//字符串的各种校验
public class StrUtils {
/**
* 是否为空的校验
* @return true false 非空*/
public static boolean empty(String...msg){
boolean res = false;
for(String s:msg){
res = (s==null|| s.length()==0);
if(res) {
break;
}
}
return res;
}
}

View File

@ -0,0 +1,54 @@
/**
* @Title: ResultBean.java
* @Package com.qf.common
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月24日
* @version V1.0
*/
package ah.com.common.vo;
/**
* @Title: ResultBean.java
* @Package com.qf.common
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月24日
* @version V1.0
* 统一的结果类
*/
public class ResultBean {
private int code;//编码 1 成功 2失败
private String msg;//内容
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
//成功
public static ResultBean setSuccess(String msg){
ResultBean bean=new ResultBean();
bean.setCode(1);
bean.setMsg(msg);
return bean;
}
//失败
public static ResultBean setError(String msg){
ResultBean bean=new ResultBean();
bean.setCode(2);
bean.setMsg(msg);
return bean;
}
}

View File

@ -0,0 +1,41 @@
/**
* @author Feri
*/
package ah.com.common.vo;
public class ViewCart {
private String name;
private double price;
private int num;
private double money;
private int gid;//商品主键
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public int getGid() {
return gid;
}
public void setGid(int gid) {
this.gid = gid;
}
}

View File

@ -0,0 +1,24 @@
package ah.com.common.vo;
import java.util.ArrayList;
import ah.com.domain.Goods;
/**
* Copyright: Copyright (c) 2018
* @ClassName: ViewGoodsIndex.java
* @Description: 该类的功能描述
* @version: v1.0.0
* @author: feri
* @date: 2018年11月25日 下午8:49:56
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2018年11月25日 feri v1.0.0 修改原因
*/
public class ViewGoodsIndex {
private int id;
private ArrayList<Goods> data;
}

View File

@ -0,0 +1,68 @@
/**
* @Title: ViewOrder.java
* @Package com.qfedu.common.vo
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月31日
* @version V1.0
*/
package ah.com.common.vo;
import java.util.List;
public class ViewOrder {
private String id;
private String createtime;
private double money;
private int flag;
private String name;
private String phone;
private String detail;
private List<ViewOrderDetail> list;//订单子项
public List<ViewOrderDetail> getList() {
return list;
}
public void setList(List<ViewOrderDetail> list) {
this.list = list;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
}

View File

@ -0,0 +1,61 @@
/**
* @Title: ViewOrderDetail.java
* @Package com.qfedu.common.vo
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月31日
* @version V1.0
*/
package ah.com.common.vo;
public class ViewOrderDetail {
private String name;
private double price;
private int num;
private int star;
private String picture;
private String pubdate;
private double money;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getStar() {
return star;
}
public void setStar(int star) {
this.star = star;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public String getPubdate() {
return pubdate;
}
public void setPubdate(String pubdate) {
this.pubdate = pubdate;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}

View File

@ -0,0 +1,57 @@
package ah.com.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ah.com.domain.Cart;
import ah.com.domain.Goods;
import ah.com.service.CartService;
@Controller
public class CartController {
@Autowired
private CartService cartService;
//新增购物车
@RequestMapping("addCart")
public String add(int gid,double price,HttpSession session) {
Goods goods=new Goods();
goods.setId(gid);
goods.setPrice(price);
if(cartService.add(((Cart)session.getAttribute("cart")).getId(), goods, 1)) {
//成功
//跳转到购物车页面
return "cartSuccess";
}else {
return "index";
}
}
//查询购物车
@RequestMapping("getCart")
public String get(HttpServletRequest req) {
Cart cart=(Cart)req.getSession().getAttribute("cart");
req.setAttribute("carts", cartService.queryCart(cart.getId()));
//转发
return "cart";
}
//购物车删除商品
@RequestMapping("clearCart")
public String clearCart(HttpServletRequest req,int gid) {
Cart cart=(Cart)req.getSession().getAttribute("cart");
cartService.deleteDetail(cart.getId(),gid);
//重定向
return "redirect:getCart";
}
//新增购物车
@RequestMapping("updateCartNum")
@ResponseBody
public int update(int gid,double price,int num,HttpServletRequest req) {
//创建商品对象
Goods gd=new Goods();
gd.setId(gid);
gd.setPrice(price);
Cart cart=(Cart)req.getSession().getAttribute("cart");
cartService.changeNum(cart.getId(), gd, num);
return 1;
}
}

View File

@ -0,0 +1,40 @@
package ah.com.controller;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.dsna.util.images.ValidateCode;
@Controller
public class CodeController {
// 验证码生成
@RequestMapping("/createcode")
public void createCode(HttpSession session, HttpServletResponse response) throws IOException {
// 创建验证码对象 参数说明 1宽度 2高度 3验证码的数量 4干扰线
ValidateCode vc = new ValidateCode(100, 30, 4, 40);
// 获取验证码
String code = vc.getCode();
// 使用会话存储生成的验证码
session.setAttribute("code", code);
// System.out.println(code);
// 响应到浏览器
vc.write(response.getOutputStream());
}
// 校验验证码是否正确
@RequestMapping("/checkcode")
@ResponseBody
public int checkCode(String code, HttpSession session) {
// 获取生成的验证码
String ccode = (String) session.getAttribute("code");
if (ccode.compareToIgnoreCase(code) == 0) {
return 1;
} else {
return 0;
}
}
}

View File

@ -0,0 +1,90 @@
package ah.com.controller;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import ah.com.common.utils.FileUtils;
import ah.com.domain.Goods;
import ah.com.service.GoodsService;
import ah.com.service.GoodsTypeService;
@Controller
public class GoodsController {
@Autowired
private GoodsService goodsService;
@Autowired
private GoodsTypeService service;
// 跳转到新增页面
@RequestMapping("toAddGoods")
public String showadd(HttpServletRequest request, Model model) {
model.addAttribute("gtlist", service.queryByLevel());
return "addGoods";
}
// 商品新增
@RequestMapping("addGoods")
public String save(MultipartFile file, Goods goods, HttpServletRequest request)
throws IllegalStateException, IOException {
File dir = FileUtils.createDir("D:\\eclipse-workspace\\chapter16\\WebContent\\fmwimages");
// File dir = FileUtils.createDir(request.getServletContext().getRealPath("/"));
File desFile = new File(dir, FileUtils.createFileName(file.getOriginalFilename()));
file.transferTo(desFile);
goods.setPicture(dir.getName() + "/" + desFile.getName());
goods.setFlag(1);//上架
if (goodsService.save(goods)) {
return "redirect:toAddGoods";
} else {
request.setAttribute("msg", "添加失败,重新再来");
return "redirect:toAddGoods";
}
}
// 查看商品详情
@RequestMapping("getGoodsById")
public String goodsbyid(int id, Model model) {
model.addAttribute("goods", goodsService.querySingle(id));
return "goodsDetail";
}
// 查看商品详情
@RequestMapping("getGoodsIndex")
@ResponseBody
public List<List<Goods>> goodsindex(HttpServletResponse response) throws IOException {
return goodsService.queryIndex();
}
// 查看商品列表
@RequestMapping("getGoodsListByTn")
public String goodsbytn(String tn, Model model) {
model.addAttribute("glist", goodsService.queryByType(tn));
return "goodsList";
}
// 查看商品列表
@RequestMapping("getGoodsList")
public String goodslist(Model model) {
model.addAttribute("goodsList", goodsService.queryAll());
return "admin/showGoods";
}
// 模糊查询商品列表
@RequestMapping("selectByName")
public String selectByName(String name, Model model) {
model.addAttribute("glist", goodsService.queryByName(name));
return "goodsList";
}
// 根据商品名称和上架时间查询商品admin
@RequestMapping("selectByNameAndPub")
public String queryNameAndPub(String name,String pubdate, Model model) {
List<Goods> goods = goodsService.queryNameAndPub(name,pubdate);
model.addAttribute("goodsList",goods );
return "admin/showGoods";
}
//删除商品
@RequestMapping("goodsDeleteById")
public String goodsDeleteById(Integer id ,Model model) {
goodsService.deleteById(id);
return "redirect:getGoodsList";
}
}

View File

@ -0,0 +1,66 @@
package ah.com.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ah.com.domain.GoodsType;
import ah.com.service.GoodsTypeService;
@Controller
public class GoodsTypeController {
@Autowired
private GoodsTypeService service;
// 跳转到新增页面
@RequestMapping("goodstypeshowadd")
public String showadd(HttpServletRequest request, Model model) {
model.addAttribute("gtlist", service.queryByLevel());
return "addGoodsType";
// return "/admin/addGoodsType";
}
// 实现新增类型
@RequestMapping("goodstypeadd")
public String add(GoodsType goodsType, HttpServletRequest request, Model model) {
if("1".equals(goodsType.getParentName())) {
goodsType.setLevel(1);
goodsType.setParentName(null);
}else {
goodsType.setLevel(2);
}
goodsType.setFlag(1);
if (service.save(goodsType)) {
return "redirect:getGoodsType";
} else {
model.addAttribute("msg", "服务器异常,请稍后再来");
return "redirect:goodstypeshowadd";
}
}
//实现删除商品类型
@RequestMapping("deleteGoodsType")
@ResponseBody
public String deleteGoodsType(HttpServletRequest req,int count) {
service.deleteType(count);
return "success";
}
// 显示类型列表
@RequestMapping("getGoodsType")
public String show(HttpServletRequest request, Model model) {
model.addAttribute("gtlist", service.queryAll());
return "/admin/showGoodsType";
}
//goodstypejson
// 显示类型
@RequestMapping("goodstypejson")
@ResponseBody
public List<GoodsType> showjson() {
return service.queryByLevel();
}
//根据商品等级和商品名称查询类型admin
@RequestMapping("selectByNameAndFlag")
public String queryNameAndFlag(String name,int flag, Model model) {
model.addAttribute("gtlist", service.queryNameAndFlag(name, flag));
return "/admin/showGoodsType";
}
}

View File

@ -0,0 +1,124 @@
package ah.com.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import ah.com.common.utils.RandomUtils;
import ah.com.common.vo.ViewCart;
import ah.com.domain.Cart;
import ah.com.domain.CartDetail;
import ah.com.domain.Goods;
import ah.com.domain.User;
import ah.com.service.CartService;
import ah.com.service.OrderService;
import ah.com.service.UserAddressService;
@Controller
public class OrderController {
@Autowired
private OrderService service;
@Autowired
private UserAddressService uaSrervice;
@Autowired
private CartService cartService;
// 下单
@RequestMapping("addOrder")
public String add(int t, int aid, HttpSession session, Model model) {
User user = (User) session.getAttribute("user");
String oid = RandomUtils.createOrderId();
boolean res = false;
if (t == 1) {// 直接下单
//res = service.insertDirect(user.getId(), oid, aid, (CartDetail) session.getAttribute("direct"));
} else {// 购物车下单
res = service.save(oid, user.getId(), aid);
}
if (res) {
// 下单成功
model.addAttribute("oid", oid);
return "pay";
} else {
return "index";
}
}
// 列表
@RequestMapping("getAllOrder")
public String all(Integer t,Integer aid,Model model) {
//model.addAttribute("orderList", service.queryAll());
return "admin/showAllOrder";
}
//直接下单
@RequestMapping("getDirectOrder")
public String direct(Goods gs, Model model, HttpSession session) {
User user = (User) session.getAttribute("user");
List<ViewCart> cds = new ArrayList<>();
ViewCart cd = new ViewCart();
cd.setGid(gs.getId());
cd.setMoney(gs.getPrice());
cd.setPrice(gs.getPrice());
cd.setNum(1);
cd.setName(gs.getName());
cds.add(cd);
CartDetail detail = new CartDetail();
detail.setGid(gs.getId());
detail.setMoney(gs.getPrice());
detail.setNum(1);
session.setAttribute("direct", detail);
model.addAttribute("cartList", cds);
//model.addAttribute("addList", uaSrervice.queryByUid(user.getId()));
model.addAttribute("type", 1);
// 转发
return "order";
}
// 查询用户的所有订单
@RequestMapping("getOrderList")
public String olist(HttpSession session, Model model) {
User user = (User) session.getAttribute("user");
//model.addAttribute("orderList", service.queryByUid(user.getId()));
return "orderList";
}
// 订单预览
@RequestMapping("getOrderView")
public String viewlist(HttpServletRequest request, Model model) {
Cart cart = (Cart) request.getSession().getAttribute("cart");
User user = (User) request.getSession().getAttribute("user");
model.addAttribute("type", 2);
request.setAttribute("cartList", cartService.queryCart(cart.getId()));
//request.setAttribute("addList", uaSrervice.queryByUid(user.getId()));
return "order";
}
// 列表
@RequestMapping("getOrderDetail")
public String list(String oid,HttpSession session, Model model) {
//model.addAttribute("od", service.queryOrderDetailById(oid));
return "orderDetail";
}
//根据用户姓名和订单的支付状态查询订单admin
@RequestMapping("selectOrderByNameAndFlag")
public String selectByNameAndFlag(String username,Integer status, Model model) {
//model.addAttribute("orderList", service.selectByNameAndFlag(username, status));
return "admin/showAllOrder";
}
//删除订单user
@RequestMapping("userDeleteOrder")
public String userDeleteOrder(String oid,HttpSession session, Model model) {
service.deleteById(oid);
return "redirect:getOrderList";
}
//修改订单admin
@RequestMapping("sendOrder")
public String sendOrder(String oid, Model model) {
service.update(oid,3);
return "redirect:getAllOrder";
}
//修改状态
@RequestMapping("changeStatus")
public String changeStatus(String oid, Model model) {
service.update(oid,5);
return "redirect:getOrderList";
}
}

View File

@ -0,0 +1,57 @@
package ah.com.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import ah.com.domain.User;
import ah.com.domain.UserAddress;
import ah.com.service.UserAddressService;
@Controller
public class UserAddressController {
@Autowired
private UserAddressService service;
@RequestMapping("userAddressDel")
public String userAddressDel(int id,HttpServletRequest req) {
//删除地址信息
service.deleteAddress(id);
return "redirect:userAddressShow";
}
@RequestMapping("userAddressAdd")
public String add(UserAddress ua,HttpServletRequest req) {
//获取登录信息
ua.setUid(((User)req.getSession().getAttribute("user")).getId());
//保存地址
if(service.insert(ua)) {
//保存成功 刷新地址列表
req.setAttribute("addList", service.queryByUid(ua.getUid()));
}
return "self_info";
}
@RequestMapping("useraddressupdate")
public String update(UserAddress ua,HttpServletRequest req) {
//保存地址
if(service.update(ua)) {
//保存成功 刷新地址列表
req.setAttribute("addList", service.queryByUid(ua.getUid()));
}
return "self_info";
}
@RequestMapping("userAddressShow")
public String show(UserAddress ua,HttpServletRequest req) {
req.setAttribute("addList", service.queryByUid(((User)req.getSession().getAttribute("user")).getId()));
return "self_info";
}
@RequestMapping("userAddressDef")
public String userAddressDef(Integer id,HttpServletRequest req) {
service.updateDea(id,((User)req.getSession().getAttribute("user")).getId());
return "redirect:userAddressShow";
}
}

View File

@ -0,0 +1,164 @@
package ah.com.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ah.com.common.utils.EmailUtils;
import ah.com.common.utils.MD5Utils;
import ah.com.common.utils.RandomUtils;
import ah.com.common.utils.StrUtils;
import ah.com.common.vo.ResultBean;
import ah.com.domain.Cart;
import ah.com.domain.User;
import ah.com.service.CartService;
import ah.com.service.UserService;
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private CartService cartService;
// 登陆
@RequestMapping("userlogin")
public String login(String username, String password, Model model, HttpSession session) {
if (!StrUtils.empty(username, password)) {
User user = userService.getUserByName(username);
System.out.println(user);
if (user != null) {
// 校验密码
if (user.getPassword().equals(MD5Utils.md5(password))) {
// 正确
// 记录登录信息到会话中
session.setAttribute("user", user);
Cart cart = cartService.queryByUid(user.getId());
if(cart == null) {
cart = new Cart();
cart.setUid(user.getId());
cart.setMoney(0);
cartService.createCart(cart);
}
session.setAttribute("cart", cartService.queryByUid(user.getId()));
// 页面跳转
return "index";
}
}
}else
model.addAttribute("loginMsg", "用户名或密码错误");
return "login";
}
// 注册
@RequestMapping("userregister")
public String register(User user, Model model, HttpSession session) {
String acode = RandomUtils.createActive();
user.setActivatecode(acode);
userService.save(user);
System.out.println(user);
// 新增成功
// session.setAttribute("acode", acode);
// 发送激活码
// EmailUtils.sendEmail(user);
return "registerSuccess";
//} else {
// model.addAttribute("registerMsg", "服务器开小差,请稍后再来");
// return "register";
//}
}
// 注销
@RequestMapping("userloginout")
public String loginout(String t, HttpSession session) {
if (t != null) {
session.removeAttribute("adminuser");
return "admin/login";
} else {
session.removeAttribute("user");
return "index";
}
}
// 校验用户名是否可用
@RequestMapping("usercheckname")
@ResponseBody
public ResultBean checkname(String name) {
// 创建激活码
if (userService.checkName(name)) {
return ResultBean.setSuccess("OK");
} else {
return ResultBean.setError("ERROR");
}
}
// 删除用户
@RequestMapping("userdel")
@ResponseBody
public int checkname(int id) {
return userService.deleteByid(id);
}
// 用户搜索
@RequestMapping("usersearch")
@ResponseBody
public List<User> usersearch(String username,String gender) {
List<User> users = userService.usersearch(username, gender);
return users;
}
// 校验邮箱是否可用
@RequestMapping("usercheckemail")
@ResponseBody
public ResultBean chakeemail(String email) {
// 创建激活码
if (userService.checkEmail(email)) {
return ResultBean.setSuccess("OK");
} else {
return ResultBean.setError("ERROR");
}
}
// 用户列表
@RequestMapping("userlist")
@ResponseBody
public List<User> list() {
return userService.selectAll();
}
// 管理员登录
@RequestMapping("adminLogin")
public String adminLogin(String username, String password, HttpServletRequest request) {
if (!StrUtils.empty(username, password)) {
User user = userService.getUserByName(username);
if (user != null) {
// 校验密码
if (user.getPassword().equals(MD5Utils.md5(password))) {
// 正确
// 记录登录信息到会话中
request.getSession().setAttribute("adminuser", user);
// 页面跳转
return "admin/admin";
}
}
}
request.setAttribute("loginMsg", "用户名或密码错误");
return "admin/login";
}
//激活激活码
@RequestMapping("/activate")
public String checkCode(String e, String c, HttpSession session) {
if (userService.activateUser(e, c)) {
// 激活成功
return "login";
} else {
return "index";
}
}
}

View File

@ -0,0 +1,53 @@
/**
* @author Feri
*/
package ah.com.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import ah.com.common.vo.ViewCart;
import ah.com.domain.Cart;
import ah.com.domain.CartDetail;
public interface CartDao {
//新增-创建购物车
@Insert("insert into t_cart(uid,money) values(#{uid},0)")
public int insert(Cart cart);
//购物车添加商品
@Insert("insert into t_cartdetail(cid,gid,num,money) values(#{cid},#{gid},#{num},#{money})")
public int insertDetail(CartDetail cd);
//修改购物车商品
@Update("update t_cart set money=#{money} where id=#{id}")
public int update(Cart cd);
//修改购物车中数量
@Update("update t_cartdetail set num=${num},money=${money} where cid=#{cid} and gid=#{gid}")
public int updateDetail(CartDetail cartdetail);
//清空购物车
@Update("update t_cart set money=0 where id=#{id}")
public int updateEmpty(int id);
//获取用户的购物车
@Select("select * from t_cart where uid=#{uid}")
@ResultType(Cart.class)
public Cart queryByUid(int uid);
//获取用户的购物车详情
@Select("select cd.* from t_cartdetail cd left join t_cart c on cd.cid=c.id where c.uid=#{uid}")
@ResultType(CartDetail.class)
public List<CartDetail> queryByDetail(int uid);
//删除购物车中的商品
@Delete("delete from t_cartdetail where cid=#{cid} and gid=#{gid}")
public int deleteDetail(@Param("cid") int cid, @Param("gid") int gid);
//清空购物车
@Delete("delete from t_cartdetail where cid=#{cid} ")
public int deleteDetailByCid(int cid);
//获取详情对象
@Select("select * from t_cartdetail where cid=#{cid} and gid=#{gid}")
@ResultType(CartDetail.class)
public CartDetail queryByCdid(@Param("cid") int cid, @Param("gid") int gid);
//购物车的数据
@Select("SELECT cd.num,cd.money,cd.gid,g.name,g.price FROM t_cartdetail cd LEFT JOIN t_goods g ON cd.gid=g.id WHERE cd.cid=#{cid}")
@ResultType(ViewCart.class)
public List<ViewCart> queryCart(int cid);
}

View File

@ -0,0 +1,53 @@
/**
* @author Feri
*/
package ah.com.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import ah.com.domain.Goods;
public interface GoodsDao {
//新增
@Insert("insert into t_goods(name,price,pubdate,typeName,intro,picture,flag,star) values(#{name},#{price},#{pubdate},#{typeName},#{intro},#{picture},1,#{star})")
public int save(Goods goods);
//查询
@Select("select * from t_goods")
@ResultType(Goods.class)
public List<Goods> queryAll();
//查询单个
@Select("select * from t_goods where id=#{id}")
@ResultType(Goods.class)
public Goods querySingle(int id);
//根据商品类型查询
@Select("select * from t_goods where flag=1 and typename=#{type}")
@ResultType(Goods.class)
public List<Goods> queryByType(String type);
//查询主页的商品信息
@Select("select * from t_goods where typename=#{type} order by star desc limit 5")
@ResultType(Goods.class)
public List<Goods> queryIndex(String type);
//根据商品名模糊查询
@Select("select * from t_goods where name LIKE CONCAT(CONCAT('%', #{name}),'%');")
@ResultType(Goods.class)
public List<Goods> queryName(String name);
//根据商品名称和上架时间查询商品admin
@Select("<script>" +
"select * from t_goods" +
"<where>" +
"<if test='name != null'>" +
"and name like concat('%', #{name}, '%')"+
"</if>"+
"<if test='pubdate != null'>" +
"and pubdate = #{pubdate}"+
"</if>"+
"</where>" +
"</script>")
@ResultType(Goods.class)
public List<Goods> queryNameAndPub(@Param("name") String name, @Param("pubdate") String pubdate);
//删除商品
@Delete("delete from t_goods where id=#{id} ")
int deleteById(int id);
}

View File

@ -0,0 +1,31 @@
/**
* @author Feri
*/
package ah.com.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import ah.com.domain.GoodsType;
public interface GoodsTypeDao {
//新增
@Insert("insert into t_goodstype(name,level,parentName,flag) values(#{name},#{level},#{parentName},1)")
int save(GoodsType gt);
//查询一级类型
@Select("select * from t_goodstype where level=1")
@ResultType(GoodsType.class)
List<GoodsType> queryByLevel();
//查询全部
@Select("select * from t_goodstype")
@ResultType(GoodsType.class)
List<GoodsType> queryAll();
//根据商品等级和商品名称查询商品admin
@Select("select * from t_goodstype where level=#{flag} and name=#{name}")
@ResultType(GoodsType.class)
public List<GoodsType> queryNameAndFlag(@Param("name") String name, @Param("flag") int flag);
//根据id删除商品类型
@Delete("delete from t_goodstype where id=#{id}")
public int deleteType(@Param("id") int tid);
}

View File

@ -0,0 +1,68 @@
/**
* @Title: OrderDao.java
* @Package com.qfedu.dao
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月31日
* @version V1.0
*/
package ah.com.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import ah.com.common.vo.ViewOrder;
import ah.com.common.vo.ViewOrderDetail;
import ah.com.domain.Order;
import ah.com.domain.OrderDetail;
public interface OrderDao {
//新增 订单详情
@Insert("insert into t_orderdetail(oid,gid,money,num) values(#{oid},#{gid},#{money},#{num})")
public int insertDetail(OrderDetail detail);
//新增 订单
@Insert("insert into t_order(id,uid,uaid,money,createtime,flag) values(#{id},#{uid},#{uaid},#{money},now(),1)")
public int insert(Order order);
//修改订单状态
@Update("update t_order set flag=#{flag} where id=#{id}")
public int update(@Param("id") String oid, @Param("flag") int flag);
//查询订单列表
@Select("select o.*,CONCAT(ua.name,'-',ua.phone,'-',ua.detail)address from t_order o left join t_useraddress ua on o.uaid=ua.id where o.uid=#{uid}")
@ResultType(Order.class)
public List<Order> queryByUid(int uid);
//查询订单
@Select("SELECT * FROM t_order o LEFT JOIN t_useraddress ua ON o.uaid=ua.id WHERE o.id=#{oid}")
@ResultType(Order.class)
public ViewOrder queryOrder(String oid);
//查询订单子项
@Select("SELECT g.*,od.num,od.money FROM t_orderdetail od LEFT JOIN t_goods g ON od.gid=g.id WHERE od.oid=#{oid}")
@ResultType(Order.class)
public List<ViewOrderDetail> queryDetailList(String oid);
//查询订单详情 较为复杂的sql
@Select("SELECT g.*,od.num,od.money,o.createtime,o.money,ua.name,ua.phone,ua.detail FROM t_orderdetail od LEFT JOIN t_goods g ON od.gid=g.id LEFT JOIN t_order o ON od.oid=o.id LEFT JOIN t_useraddress ua ON o.uaid=ua.id WHERE od.oid=#{oid}")
@ResultType(Order.class)
public ViewOrder queryDetail(String oid);
//查询全部订单
@Select("SELECT o.*,u.username FROM t_order o LEFT JOIN t_user u ON o.uid=u.id")
@ResultType(Order.class)
public List<Order> queryAll();
//根据用户姓名和订单的支付状态查询订单admin
@Select("<script>" +
"select o.*,u.username from t_order o LEFT JOIN t_user u ON o.uid=u.id" +
"<where>" +
"<if test='username != null'>" +
"and u.username like concat('%', #{username}, '%')"+
"</if>"+
"<if test='flag != null'>" +
"and o.flag = #{flag}"+
"</if>"+
"</where>" +
"</script>")
@ResultType(Order.class)
public List<Order> selectByNameAndFlag(@Param("username") String username, @Param("flag") Integer flag);
//删除订单admin
@Delete("delete from t_order where id=#{id} ")
int deleteById(@Param("id") String id);
}

View File

@ -0,0 +1,35 @@
/**
* @Title: UserAddressDao.java
* @Package com.qfedu.dao
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月31日
* @version V1.0
*/
package ah.com.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import ah.com.domain.UserAddress;
public interface UserAddressDao {
//新增
@Insert("insert into t_useraddress(name,phone,detail,uid,flag ) values(#{name},#{phone},#{detail},#{uid},1)")
public int insert(UserAddress ua);
//修改
@Update("update t_useraddress set name=#{name},phone=#{phone},detail=#{detail} where id=#{id}")
public int update(UserAddress ua);
//修改状态
@Update("update t_useraddress set flag=#{flag} where id=#{id}")
public int updateDea(@Param("id") int id, @Param("flag") int flag);
//查询地址
@Select("select * from t_useraddress where uid=#{uid} order by flag desc")
@ResultType(UserAddress.class)
public List<UserAddress> queryByUid(int uid);
//删除地址信息
@Delete("delete from t_useraddress where id=#{id} ")
int deleteById(int id);
}

View File

@ -0,0 +1,41 @@
/**
* @author Feri
*/
package ah.com.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import ah.com.domain.User;
public interface UserDao {
//新增
@Insert("insert into t_user(role ,username,password,email,gender,createtime ,flag ,activatecode) values(1,#{username},#{password},#{email},#{gender},now(),1,#{activatecode})")
int insert(User user);
//登录 用户名或密码都可以使用
@Select("select * from t_user where username=#{name} ")
@ResultType(User.class)
User select(String name);
//检查用户名是否存在
@Select("select count(*) from t_user where username=#{username}")
int checkName(String name);
//检查用户名是否存在
@Select("select count(*) from t_user where email=#{email}")
int checkEmail(String email);
//查询全部
@Select("select * from t_user where flag=2")
@ResultType(User.class)
List<User> selectAll();
//激活
@Update("update t_user set flag=2 where email=#{email} and activatecode=#{code}")
int updateAcode(@Param("email") String email, @Param("code") String code);
//删除用户
@Delete("delete from t_user where id=#{id} ")
int deleteByid(int id);
//根据用户名和性别搜索用户
@Select("select * from t_user where username like CONCAT('%',#{username},'%') and gender=#{gender}")
@ResultType(User.class)
List<User> selectsearch(@Param("username") String username, @Param("gender") String gender);
}

View File

@ -0,0 +1,30 @@
package ah.com.domain;
public class Cart {
private int id;
private int uid;
private double money;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
@Override
public String toString() {
return "Cart [id=" + id + ", uid=" + uid + ", money=" + money + "]";
}
}

View File

@ -0,0 +1,43 @@
package ah.com.domain;
public class CartDetail {
private int id;
private int cid;
private int gid;
private int num;
private double money;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getCid() {
return cid;
}
public void setCid(int cid) {
this.cid = cid;
}
public int getGid() {
return gid;
}
public void setGid(int gid) {
this.gid = gid;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
@Override
public String toString() {
return "CartDetail [id=" + id + ", cid=" + cid + ", gid=" + gid + ", num=" + num + ", money=" + money + "]";
}
}

View File

@ -0,0 +1,75 @@
/**
* @author Feri
*/
package ah.com.domain;
public class Goods {
private int id;
private String name;
private double price;
private String pubdate;
private String typeName;
private String intro;
private String picture;
private int flag;
private int star;
public int getStar() {
return star;
}
public void setStar(int star) {
this.star = star;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getPubdate() {
return pubdate;
}
public void setPubdate(String pubdate) {
this.pubdate = pubdate;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public String getIntro() {
return intro;
}
public void setIntro(String intro) {
this.intro = intro;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
@Override
public String toString() {
return "Goods [id=" + id + ", name=" + name + ", price=" + price + ", pubdate=" + pubdate + ", typeName="
+ typeName + ", intro=" + intro + ", picture=" + picture + ", flag=" + flag + ", star=" + star + "]";
}
}

View File

@ -0,0 +1,47 @@
/**
* @author Feri
*/
package ah.com.domain;
public class GoodsType {
private int id;
private String name;
private int level;
private int flag;
private String parentName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
@Override
public String toString() {
return "GoodsType [id=" + id + ", name=" + name + ", level=" + level + ", flag=" + flag + ", parentName="
+ parentName + "]";
}
}

View File

@ -0,0 +1,68 @@
/**
* @author Feri
*/
package ah.com.domain;
public class Order {
private String id;
private int uid;
private int uaid;
private String createtime;
private double money;
private int flag;
private String username;
private String address;//不是数据库的字段 记录收货地址 收货人+手机号+收货地址
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public int getUaid() {
return uaid;
}
public void setUaid(int uaid) {
this.uaid = uaid;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
@Override
public String toString() {
return "Order [id=" + id + ", uid=" + uid + ", uaid=" + uaid + ", createtime=" + createtime + ", money=" + money
+ ", flag=" + flag + ", username=" + username + ", address=" + address + "]";
}
}

View File

@ -0,0 +1,44 @@
package ah.com.domain;
public class OrderDetail {
private int id;
private String oid;
private int gid;
private int num;
private double money;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getOid() {
return oid;
}
public void setOid(String oid) {
this.oid = oid;
}
public int getGid() {
return gid;
}
public void setGid(int gid) {
this.gid = gid;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
@Override
public String toString() {
return "OrderDetail [id=" + id + ", oid=" + oid + ", gid=" + gid + ", num=" + num + ", money=" + money + "]";
}
}

View File

@ -0,0 +1,97 @@
package ah.com.domain;
public class User {
private int id;
private String username;
private String password;
private String createtime;
private int flag;
private String email;
private String gender;
private String activatecode;
private int role;
public int getId() {
return id;
}
public void setId(int 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;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getActivatecode() {
return activatecode;
}
public void setActivatecode(String activatecode) {
this.activatecode = activatecode;
}
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
/**
*
*/
public User() {
super();
}
/**
* @param username
* @param password
* @param email
* @param gender
* @param activatecode
* @param role
*/
public User(String username, String password, String email, String gender, String activatecode, int role) {
super();
this.username = username;
this.password = password;
this.email = email;
this.gender = gender;
this.activatecode = activatecode;
this.role = role;
}
@Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", password=" + password + ", createtime=" + createtime
+ ", flag=" + flag + ", email=" + email + ", gender=" + gender + ", activatecode=" + activatecode
+ ", role=" + role + "]";
}
}

View File

@ -0,0 +1,51 @@
package ah.com.domain;
public class UserAddress {
private int id;
private String name;
private String phone;
private String detail;
private int uid;
private int flag;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
@Override
public String toString() {
return "UserAddress [id=" + id + ", name=" + name + ", phone=" + phone + ", detail=" + detail + ", uid=" + uid
+ ", flag=" + flag + "]";
}
}

View File

@ -0,0 +1,21 @@
package ah.com.service;
import java.util.List;
import ah.com.common.vo.ViewCart;
import ah.com.domain.Cart;
import ah.com.domain.Goods;
public interface CartService {
// 创建购物车
public boolean createCart(Cart cart);
// 加入购物车 详情页
public boolean add(int cid, Goods gds, int num);
// 修改数量 购物车页面
public boolean changeNum(int cid, Goods gds, int num);
// 获取购物车对象
public Cart queryByUid(int uid);
// 购物车的数据
public List<ViewCart> queryCart(int cid);
// 删除购物车的商品
public int deleteDetail(int cid, int gid);
}

View File

@ -0,0 +1,23 @@
/**
* @author Feri
*/
package ah.com.service;
import java.util.List;
import ah.com.domain.Goods;
public interface GoodsService {
// 新增
boolean save(Goods goods);
// 查询
List<Goods> queryAll();
//模糊查询
List<Goods> queryByName(String name);
//根据商品类型查询
List<Goods> queryByType(String type);
// 查询单个
Goods querySingle(int id);
List<List<Goods>> queryIndex();
//根据商品名称和上架时间查询商品admin
List<Goods> queryNameAndPub(String name, String pubdate);
//删除商品
int deleteById(int id);
}

View File

@ -0,0 +1,15 @@
package ah.com.service;
import java.util.List;
import ah.com.domain.GoodsType;
public interface GoodsTypeService {
//新增
boolean save(GoodsType gt);
//查询一级类型
List<GoodsType> queryByLevel();
//查询全部
List<GoodsType> queryAll();
//删除
int deleteType(int tid);
//根据商品等级和商品名称查询类型admin
List<GoodsType> queryNameAndFlag(String name, int flag);
}

View File

@ -0,0 +1,31 @@
/**
* @Title: OrderService.java
* @Package com.qfedu.service
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月31日
* @version V1.0
*/
package ah.com.service;
import java.util.List;
import ah.com.common.vo.ViewOrder;
import ah.com.domain.CartDetail;
import ah.com.domain.Order;
public interface OrderService {
//下单
public boolean save(String oid, int uid, int uaid);
//直接下单
public boolean insertDirect(int uid, String oid, int uaid, CartDetail cd);
// 修改订单状态
public boolean update(String oid, int flag);
// 查询订单列表
public List<Order> queryByUid(int uid);
// 查询详情
public ViewOrder queryOrderDetailById(String oid);
// 查询全部订单
public List<Order> queryAll();
//根据用户姓名和订单的支付状态查询订单admin
List<Order> selectByNameAndFlag(String username, Integer flag);
//删除订单
int deleteById(String id);
}

View File

@ -0,0 +1,19 @@
/**
* @author Feri
*/
package ah.com.service;
import java.util.List;
import ah.com.domain.UserAddress;
public interface UserAddressService {
// 新增
public boolean insert(UserAddress ua);
// 修改
public boolean update(UserAddress ua);
// 查询地址
public List<UserAddress> queryByUid(int uid);
//删除地址
public int deleteAddress(int id);
//修改状态
public int updateDea(int id, int uid);
}

View File

@ -0,0 +1,26 @@
/**
* @author Feri
*/
package ah.com.service;
import java.util.List;
import ah.com.domain.User;
public interface UserService {
//新增
boolean save(User user);
//根据名称 用户名或者邮箱
User getUserByName(String name);
//查询全部
List<User> selectAll();
//校验用户名是否存在 注册页面
boolean checkName(String name);
//校验邮箱是否存在 注册页面
boolean checkEmail(String email);
//检查登录用户是否存在 可能是邮箱 也可能是用户名
boolean checkLogin(String name);
//激活
boolean activateUser(String email, String code);
//删除用户
int deleteByid(int id);
//用户搜索
List<User> usersearch(String username, String gender);
}

View File

@ -0,0 +1,81 @@
/**
* @author Feri
*/
package ah.com.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ah.com.common.vo.ViewCart;
import ah.com.dao.CartDao;
import ah.com.domain.Cart;
import ah.com.domain.CartDetail;
import ah.com.domain.Goods;
import ah.com.service.CartService;
@Service
public class CartServiceImpl implements CartService{
@Autowired
private CartDao dao;
@Override
public boolean createCart(Cart cart) {
// TODO Auto-generated method stub
return dao.insert(cart)>0;
}
/* 在商品详情页面 加入购物车*/
@Override
public boolean add(int cid,Goods gds,int num) {
// TODO Auto-generated method stub
CartDetail detail=dao.queryByCdid(cid,gds.getId());
//判断是新增还是修改
if(detail==null) {
//第一次
CartDetail cd=new CartDetail();
cd.setCid(cid);
cd.setGid(gds.getId());
cd.setNum(num);
cd.setMoney(num*gds.getPrice());
return dao.insertDetail(cd)>0;
}else {
//N次
detail.setMoney(detail.getMoney()+gds.getPrice());
detail.setNum(detail.getNum()+1);
return dao.updateDetail(detail)>0;
}
}
//更改数量
@Override
public boolean changeNum(int cid, Goods gds, int num) {
// TODO Auto-generated method stub
CartDetail detail=dao.queryByCdid(cid,gds.getId());
if(num==-1) {
gds.setPrice(-gds.getPrice());
detail.setNum(detail.getNum()-1);
}else {
detail.setNum(detail.getNum()+1);
}
detail.setMoney(detail.getMoney()+gds.getPrice());
return dao.updateDetail(detail)>0;
}
//查询
@Override
public Cart queryByUid(int uid) {
// TODO Auto-generated method stub
return dao.queryByUid(uid);
}
//详情查询
@Override
public List<ViewCart> queryCart(int cid) {
// TODO Auto-generated method stub
return dao.queryCart(cid);
}
//删除购物车中的商品
@Override
public int deleteDetail(int cid, int gid) {
if(gid == 0) {//清空购物车
return dao.deleteDetailByCid(cid);
}else {
return dao.deleteDetail(cid,gid);
}
}
}

View File

@ -0,0 +1,67 @@
/**
* @author Feri
*/
package ah.com.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ah.com.dao.GoodsDao;
import ah.com.domain.Goods;
import ah.com.service.GoodsService;
@Service
public class GoodsServiceImpl implements GoodsService{
@Autowired
private GoodsDao dao;
@Override
public boolean save(Goods goods) {
// TODO Auto-generated method stub
goods.setPrice(goods.getPrice());
return dao.save(goods)>0;
}
@Override
public List<Goods> queryAll() {
// TODO Auto-generated method stub
return dao.queryAll();
}
@Override
public Goods querySingle(int id) {
// TODO Auto-generated method stub
return dao.querySingle(id);
}
@Override
public List<Goods> queryByType(String type) {
// TODO Auto-generated method stub
return dao.queryByType(type);
}
@Override
public List<List<Goods>> queryIndex() {
// TODO Auto-generated method stub
List<List<Goods>> list=new ArrayList<List<Goods>>();
list.add(dao.queryIndex("酒水饮料"));
list.add(dao.queryIndex("饼干糕点"));
list.add(dao.queryIndex("休闲零食"));
return list;
}
@Override
public List<Goods> queryByName(String name) {
//模糊查询
return dao.queryName(name);
}
@Override
public List<Goods> queryNameAndPub(String name, String pubdate) {
if(name != null && "".equals(name)) {
name = null;
}
if(pubdate != null && "".equals(pubdate)) {
pubdate = null;
}
// 根据商品名称和上架时间查询商品admin
return dao.queryNameAndPub(name, pubdate);
}
@Override
public int deleteById(int id) {
// 删除商品
return dao.deleteById(id);
}
}

View File

@ -0,0 +1,41 @@
/**
* @author Feri
*/
package ah.com.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ah.com.dao.GoodsTypeDao;
import ah.com.domain.GoodsType;
import ah.com.service.GoodsTypeService;
@Service
public class GoodsTypeServiceImpl implements GoodsTypeService {
@Autowired
private GoodsTypeDao dao;
@Override
public boolean save(GoodsType gt) {
// TODO Auto-generated method stub
return dao.save(gt)>0;
}
@Override
public List<GoodsType> queryByLevel() {
// TODO Auto-generated method stub
return dao.queryByLevel();
}
@Override
public List<GoodsType> queryAll() {
// TODO Auto-generated method stub
return dao.queryAll();
}
@Override
public List<GoodsType> queryNameAndFlag(String name,int flag) {
// 根据商品等级和商品名称查询商品admin
return dao.queryNameAndFlag(name,flag);
}
//根据id删除商品类型
@Override
public int deleteType(int tid) {
// TODO Auto-generated method stub
return dao.deleteType(tid);
}
}

View File

@ -0,0 +1,111 @@
/**
* @Title: OrderServiceImple.java
* @Package com.qfedu.service.imple
* @Description: TODO(用一句话描述该文件做什么)
* @author Feri
* @date 2018年5月31日
* @version V1.0
*/
package ah.com.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ah.com.common.vo.ViewOrder;
import ah.com.dao.CartDao;
import ah.com.dao.OrderDao;
import ah.com.domain.CartDetail;
import ah.com.domain.Order;
import ah.com.domain.OrderDetail;
import ah.com.service.OrderService;
@Service
public class OrderServiceImpl implements OrderService{
@Autowired
private OrderDao dao;
@Autowired
private CartDao cartDao;
//新增订单
@Override
public boolean save(String oid, int uid, int uaid) {
List<CartDetail> cds=cartDao.queryByDetail(uid);
double sum = 0;
// 添加到订单详情表
for (int i = 0; i < cds.size(); i++) {
OrderDetail detail=new OrderDetail();
detail.setGid(cds.get(i).getGid());
detail.setOid(oid);
detail.setNum(cds.get(i).getNum());
detail.setMoney(cds.get(i).getMoney());
dao.insertDetail(detail);
sum+=cds.get(i).getMoney();
}
Order order=new Order();
order.setId(oid);
order.setUaid(uaid);
order.setUid(uid);
order.setMoney(sum);
dao.insert(order);
cartDao.deleteDetailByCid(cds.get(0).getCid());
cartDao.updateEmpty(cds.get(0).getCid());
return true;
}
//更改订单状态
@Override
public boolean update(String oid, int flag) {
// TODO Auto-generated method stub
return dao.update(oid, flag)>0;
}
//查询用户的所有订单
@Override
public List<Order> queryByUid(int uid) {
// TODO Auto-generated method stub
return dao.queryByUid(uid);
}
//查询订单详情
@Override
public ViewOrder queryOrderDetailById(String oid) {
// TODO Auto-generated method stub
ViewOrder vo=dao.queryOrder(oid);
vo.setList(dao.queryDetailList(oid));
return vo;
}
//查询所有订单
@Override
public List<Order> queryAll() {
// TODO Auto-generated method stub
return dao.queryAll();
}
//直接下单
@Override
public boolean insertDirect(int uid, String oid, int uaid, CartDetail cd) {
Order order=new Order();
order.setId(oid);
order.setUaid(uaid);
order.setUid(uid);
order.setMoney(cd.getMoney());
dao.insert(order);
OrderDetail detail=new OrderDetail();
detail.setGid(cd.getGid());
detail.setOid(oid);
detail.setNum(cd.getNum());
detail.setMoney(cd.getMoney());
dao.insertDetail(detail);
return true;
}
@Override
public List<Order> selectByNameAndFlag(String username, Integer flag) {
if(username != null && "".equals(username)) {
username = null;
}
if(flag != null && 0 == flag) {
flag = null;
}
//根据用户姓名和订单的支付状态查询订单admin
return dao.selectByNameAndFlag(username, flag);
}
@Override
public int deleteById(String id) {
// 删除订单
return dao.deleteById(id);
}
}

View File

@ -0,0 +1,50 @@
package ah.com.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ah.com.dao.UserAddressDao;
import ah.com.domain.UserAddress;
import ah.com.service.UserAddressService;
@Service
public class UserAddressServiceImpl implements UserAddressService{
@Autowired
private UserAddressDao dao;
//新增收货地址
@Override
public boolean insert(UserAddress ua) {
// TODO Auto-generated method stub
return dao.insert(ua)>0;
}
//查询收货地址
@Override
public List<UserAddress> queryByUid(int uid) {
// TODO Auto-generated method stub
return dao.queryByUid(uid);
}
//修改地址
@Override
public boolean update(UserAddress ua) {
// TODO Auto-generated method stub
return dao.update(ua)>0;
}
//删除地址信息
@Override
public int deleteAddress(int id) {
// TODO Auto-generated method stub
return dao.deleteById(id);
}
//修改为默认
@Override
public int updateDea(int id,int uid) {
List<UserAddress> queryByUid = queryByUid(uid);
if(queryByUid != null && !queryByUid.isEmpty()) {
for(UserAddress userAddress : queryByUid) {
if(userAddress.getFlag() == 3) {
dao.updateDea(userAddress.getId(),1);//将以前的默认修改为普通
}
}
}
return dao.updateDea(id,3);
}
}

View File

@ -0,0 +1,74 @@
/**
* @author Feri
*/
package ah.com.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ah.com.common.utils.Base64Utils;
import ah.com.common.utils.MD5Utils;
import ah.com.common.utils.StrUtils;
import ah.com.dao.UserDao;
import ah.com.domain.User;
import ah.com.service.UserService;
@Service
public class UserServiceImpl implements UserService{
@Autowired
private UserDao dao;
@Override
public boolean save(User user) {
// TODO Auto-generated method stub
//密码使用密文
user.setPassword(MD5Utils.md5(user.getPassword()));
return dao.insert(user)>0;
}
@Override
public User getUserByName(String name) {
// TODO Auto-generated method stub
return dao.select(name);
}
@Override
public List<User> selectAll() {
// TODO Auto-generated method stub
return dao.selectAll();
}
/* 检查用户名
* true 表示存在 false不存在*/
@Override
public boolean checkName(String name) {
return dao.checkName(name)>0;
}
/* 检查邮箱
* true 表示存在 false不存在*/
@Override
public boolean checkEmail(String email) {
return dao.checkEmail(email)>0;
}
@Override
public boolean activateUser(String email, String code) {
// TODO Auto-generated method stub
if(!StrUtils.empty(email,code)){
return dao.updateAcode(Base64Utils.decode(email), Base64Utils.decode(code))>0;
}else {
return false;
}
}
/* @Return true存在 false不存在
*/
@Override
public boolean checkLogin(String name) {
// TODO Auto-generated method stub
return dao.select(name)!=null;
}
@Override
public int deleteByid(int id) {
return dao.deleteByid(id);
}
//搜索用户根据username和gender
@Override
public List<User> usersearch(String username, String gender) {
return dao.selectsearch(username, gender);
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
web/WEB-INF/lib/jstl.jar Normal file

Binary file not shown.

BIN
web/WEB-INF/lib/mail.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More