学了一段时间的小程序,现在记录一下
之前写了jsp和servlet之间是怎么传输数据和返回数据的,那么微信小程序和servlet是怎么进行交互的,前端怎么进入后台。
开发准备:
微信开发工具:4090
IDE: Eclipse Mars Release (4.5.0)
jdk:1.8.0_171
Tomcat:v7.0
MySQL:5.7(mysql-connector-java-5.1.26)
后台项目结构
新建com.syrinx.order包,结构如上图
1、建立连接类DBUtil
package com.syrinx.order;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class DBUtil {
static private String classDriver;
static private String url;
static private String userName;
static private String passWord;
static {
try {
ClassLoader classLoader = DBUtil.class.getClassLoader()
InputStream is = classLoader.getResourceAsStream("jdbc.properties"); //通过字节输入流读取配置文件
Properties props = new Properties();
props.load(is); //加载配置文件
//得到配置文件中的值
classDriver = props.getProperty("classDriver");
url = props.getProperty("url");
userName = props.getProperty("userName");
passWord = props.getProperty("passWord");
} catch (IOException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection conn = null;
try {
Class.forName(classDriver);
conn = DriverManager.getConnection(url, userName, passWord);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
}
jdbc.propertices
#userName=root
#passWord=
classDriver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/syrinxsysorder?useUnicode=true&characterEncoding=UTF-8
2、建立user实体类
package com.syrinx.modules.video;
public class VideoBean {
private int id;
private String title;
private String videoUrl;
private String imageUrl;
private String downloadTimes;
private String previewTimes;
private String createTime;
private String updateTime;
private String headLine;
private int type_id;
public int getType_id() {
return type_id;
}
public void setType_id(int type_id) {
this.type_id = type_id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getHeadLine() {
return headLine;
}
public void setHeadLine(String headLine) {
this.headLine = headLine;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getVideoUrl() {
return videoUrl;
}
public void setVideoUrl(String videoUrl) {
this.videoUrl = videoUrl;
}
public String getImageUrl() {
return imageUrl;
}