javaweb作为服务端,容器是tomcat6,怎么配置服务器,能让小程序访问到
[@Controller](/user/Controller) //比如:影院列表:/cinema/queryCinema.action [@RequestMapping](/user/RequestMapping) ( "/cinema" ) public class CinemaController { [@Autowired](/user/Autowired) private CinemaService cinemaService; [@RequestMapping](/user/RequestMapping) ( "/queryCinema" ) public [@ResponseBody](/user/ResponseBody) Map<String, Cinema[]> queryCinema(Cinema cinema) throws Exception { List<Cinema> cinemaList=cinemaService.findCinemaList(cinema); Cinema[] cl = (Cinema[]) cinemaList.toArray( new Cinema[cinemaList.size()]); Map<String, Cinema[]> map = new HashMap<String, Cinema[]>(); map.put( "cinemas" , cl); return map; } |
这是后台controller代码 用注解@ResponseBody直接可以返回json格式的数据
小程序可以直接访问这个链接访问到数据
我没用wx.socket,把Javaweb工程发布到Tomcat,直接一个链接访问Tomcat你的项目,http://localhost:8080/wxTicket/cinema/queryCinema.action?lat=37.5285652317&lng=121.3655765023
我写成这样,不对
var connectionbol=false;
//input.js
Page({
data: {
},
onLoad:function(){
wx.connectSocket({
url: ‘ws://192.168.0.220:8080/WebScada/getPowerCurveFromApp.action’,
data: {
},
header: {
‘content-type’: ‘application/json’
},
method: ‘POST’,
success: function (msg) {
console.log(msg);
}
})
wx.onSocketOpen(function () {
connectionbol=true;
})
wx.onSocketMessage(function () {
data: “”
});
},
myquery:function(){
if (connectionbol){
wx.sendSocketMessage({
data: {
“paramid”: “M_20161017003”,
“thetype”: “t_moniterCenter”,
“starttime”: “2016-11-15”,
“datatype”: “realtime”
}
});
}
}
})