本人刚学java4个月的萌新求大佬指教!
简单的实验通过test.html中的按钮跳转支付宝支付页面test.html代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试按钮</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(function () {
$("#pay").click(function () {
var id = $("#pay").val();
$.get("paytest",{value:id},function (data) {
window.location="paytest";
})
});
})
</script>
</head>
<body>
<div>
<button type="button" class="btn btn-primary btn-lg btn-block" value="1" id="pay"
>支付宝测试按钮
</button>
</div>
</body>
</html>
通过异步点击安酒后跳转支付宝接口controller部分代码如下
@RequestMapping("/test")
public String test(){
return "test";
}
@RequestMapping(value = "/paytest",method = RequestMethod.GET)
public void testPay(HttpServletResponse response,String value){
System.out.println(value);
if (value!=null) {
try {
response.setContentType("text/html; charset=utf-8");
response.getWriter().write(alipayService.getwayPay(value));
response.getWriter().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
然后通过实现类实现数据的插入代码如下:
@Service
public class AlipayServiceImpl implements AlipayService {
@Resource
private AlipayClient alipayClient;
@Resource
private AlipayProperties aliPayProperties;
@Resource
private OrderDao orderDao;
@Override
public String getwayPay( String id) {
Order order=new Order();
Long id1=Long.parseLong(id);
order=orderDao.findById(id1).get();
AlipayTradePagePayModel model=new AlipayTradePagePayModel();
model.setOutTradeNo(order.getOutTradeNo());
model.setSubject(order.getOrderType());
model.setTotalAmount(order.getTotalAmount());
model.setBody(order.getMiaoshu());
model.setProductCode(order.getProductCode());
AlipayTradePagePayRequest pagePayRequest = new AlipayTradePagePayRequest();
pagePayRequest.setReturnUrl(aliPayProperties.getReturnUrl());
pagePayRequest.setNotifyUrl(aliPayProperties.getNotifyUrl());
pagePayRequest.setBizModel(model);
// 调用SDK生成表单, 并直接将完整的表单html输出到页面
String retStr = null;
try {
retStr = alipayClient.pageExecute(pagePayRequest).getBody();
} catch (AlipayApiException e) {
e.printStackTrace();
}
return retStr;
}
}
那么问题来了Demo用的是阿里给的 我这边只是插入数据 为什么跳转不了到阿里支付页面呢求大神指教下面贴两张控制器图
控制器代码:
Hibernate:
select
order0_.id as id1_5_0_,
order0_.out_trade_no as out_trad2_5_0_,
order0_.total_amount as total_am3_5_0_,
order0_.miaoshu as miaoshu4_5_0_,
order0_.order_type as order_ty5_5_0_,
order0_.product_code as product_6_5_0_,
order0_.state_pay as state_pa7_5_0_,
order0_.student_id as student_8_5_0_,
student1_.sid as sid1_8_1_,
student1_.address as address2_8_1_,
student1_.age as age3_8_1_,
student1_.gender as gender4_8_1_,
student1_.head as head5_8_1_,
student1_.id_card as id_card6_8_1_,
student1_.password as password7_8_1_,
student1_.sname as sname8_8_1_,
student1_.tel as tel9_8_1_
from
wu_order order0_
left outer join
wu_student student1_
on order0_.student_id=student1_.sid
where
order0_.id=?
null
说实话最后一个null没看懂 求大神指教!