forked from qiurunze123/miaosha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55fbc8d
commit 87c7ac9
Showing
41 changed files
with
640 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,72 @@ | ||
package com.geekq.miaosha; | ||
|
||
import com.geekq.miaosha.domain.MiaoshaUser; | ||
import org.apache.ibatis.io.Resources; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* mybatis xml 写法的配置测试类 | ||
*/ | ||
public class Test { | ||
public static void main(String[] args) throws IOException { | ||
public static List<Double> list = new ArrayList<Double>(); | ||
|
||
//读取配置文件 | ||
Reader reader = Resources.getResourceAsReader("config.xml"); | ||
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); | ||
public static void main(String[] args) { | ||
double[] keys = {1, 2,3}; | ||
System.err.println(getNum(keys, 5)); | ||
|
||
|
||
SqlSession session = sessionFactory.openSession(); | ||
// 举例:3 个元素:a, b, c。所以有2 ^ 3 = 8 个组合结果:所以i = 0, 1, 2,....7.对应应输出 a, b, ab, c...abc(注意a表示001,不是100.) | ||
// | ||
// 将i变成2进制: | ||
// i = 1 = 001 | ||
// i = 2 = 010 | ||
// i = 3 = 011 | ||
// | ||
// (1) j = 0 (1) j = 0 (1) j = 0 | ||
// 移1位:1 << j == 001 1 << j == 001 1 << j == 001 | ||
// 和i = 001 相与,两个位都为1,返回1 与i无相同位 和i = 001 相与,两个位都为1,返回1 | ||
// 输出:a 输出a | ||
// | ||
// (2) j = 1 (2) j = 1 (2) j = 1 | ||
// 再移一位:1 << j == 010 1 << j == 010 1 << j == 010 | ||
// 与i = 001 相与。无相同1 和i相与,两个位都为1,返回1 和i相与,两个位都为1,返回1 | ||
// 输出b 输出b | ||
// | ||
// (3) j = 2 3)j = 2 (3) j = 2 | ||
// 移一位 1 << j == 100 1 << j == 100 | ||
// 与i无相同位 与i无相同位 与i无相同位 | ||
// | ||
// 所以i = 001, 只输出a.所以i = 010, 只输出b.所以011,输出ab | ||
// | ||
// ************************************* | ||
// *可见上面每一个数字i, 只会判断判断3次,因为只需要移三次位,二进制就遍历完了 | ||
|
||
String statement = "com.geekq.miaosha.dao.UserMapper.getMiaoShaUserById" ; | ||
MiaoshaUser user = session.selectOne(statement,"18612766134"); | ||
} | ||
|
||
System.out.println(user.toString()); | ||
static List<Double> getNum(double[] keys, double kill) { | ||
int n = keys.length;//数字长度 | ||
System.out.println(n); | ||
int nbit = 1 << n; // 8 | ||
System.out.println(nbit); | ||
double in; | ||
List<Double> list = new ArrayList<Double>(); | ||
for (int i = 0; i < nbit; i++) { | ||
System.out.println("nbit======="+i); | ||
in = 0; | ||
list.clear(); | ||
for (int j = 0; j < n; j++) { | ||
System.out.println("j======"+j); | ||
int tmp = 1 << j; // 由0到n右移位 | ||
System.out.println("tmp===="+tmp); | ||
if ((tmp & i) != 0) { // 与运算,同为1时才会是1 | ||
System.out.println("keys[j]=========="+keys[j]); | ||
in += keys[j]; | ||
list.add(keys[j]); | ||
} | ||
} | ||
if (in == kill){ | ||
return list; | ||
} | ||
} | ||
return list; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,20 @@ | ||
package com.geekq.miaosha.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.Date; | ||
|
||
@Setter | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class MiaoshaGoods { | ||
private Long id; | ||
private Long goodsId; | ||
private Integer stockCount; | ||
private Date startDate; | ||
private Date endDate; | ||
public Long getId() { | ||
return id; | ||
} | ||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
public Long getGoodsId() { | ||
return goodsId; | ||
} | ||
public void setGoodsId(Long goodsId) { | ||
this.goodsId = goodsId; | ||
} | ||
public Integer getStockCount() { | ||
return stockCount; | ||
} | ||
public void setStockCount(Integer stockCount) { | ||
this.stockCount = stockCount; | ||
} | ||
public Date getStartDate() { | ||
return startDate; | ||
} | ||
public void setStartDate(Date startDate) { | ||
this.startDate = startDate; | ||
} | ||
public Date getEndDate() { | ||
return endDate; | ||
} | ||
public void setEndDate(Date endDate) { | ||
this.endDate = endDate; | ||
} | ||
} |
Oops, something went wrong.