idea 目录结构
主要使用UserMapper/ UserModel/ LoginController/ UserMapper.xml,客户端发送请求后先到LoginController类,control控制类持有Mapper接口,根据请求的地址到相应的方法中,该方法中使用Mapper接口的查询数据库方法,然后该接口类在对应的resources包下的.xml文件,这里是关于数据库的增删改查。顺序:
LoginController->UserMapper->UserMapper.xml->LoginController
pom.xml文件:一些包的引用配置
application.yml文件:连接数据库配置及url地址,内容如下
datasource:
dbone:
# url: jdbc:oracle:thin:@132.228.226.11:1521:JSEIPDB
url: jdbc:mysql://172.16.0.218:3306/layertest?autoReconnect=true # test指数据库,另外区分mysql与oracle的url地址
# url: jdbc:mysql://172.16.0.218:3306/test?autoReconnect=true # test指数据库,另外区分mysql与oracle的url地址
username: huangjihai
password: h123456
driver-class-name: com.mysql.jdbc.Driver
# url: jdbc:oracle:thin:@172.16.241.177:1521:rjyorcl
# username: zhab
# password: zhab
# driver-class-name: oracle.jdbc.driver.OracleDriver
type: pooled
mybatis:
mapperLocations: classpath:zhab/mapping/*.xml
typeAliasesPackage: zhab.model
server:
port: 10002
# port: 3306
spring:
http:
multipart:
max-file-size: 10Mb
max-request-size: 100Mb
interfaceUrl:
ipUrl: http://132.228.226.11
# ftpUrl: http://132.228.226.11
# ftpUrl: http://172.16.214.24
ftpUrl: http://172.16.108.137 # 本机的ip
oaUrl: http://nt.jsoa.net
vedioUrl: http://58.223.251.5:8080/axis2/services/GEForMsp
model:model包下的类必须要有无参构造函数??不然请求失败
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: No constructor found in zhab.model.BasePointModel matching [java.lang.Integer, java.lang.Double, java.lang.Double, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
BasePointModel:
package zhab.model;
/**
* Created by HASEE on 2017/6/8.
*/
public class BasePointModel {
private int pointId;
private double latitude;
private double longitude;
private String az;
private String compare;
private String lapNum;
private String liveStatus;
private String selfWeak;
public BasePointModel(int pointId, double latitude, double longitude, String az, String compare, String lapNum,
String liveStatus, String selfWeak) {
this.pointId = pointId;
this.latitude = latitude;
this.longitude = longitude;
this.az = az;
this.compare = compare;
this.lapNum = lapNum;
this.liveStatus = liveStatus;
this.selfWeak = selfWeak;
}
public BasePointModel() { //貌似必须要有无参构造函数?
}
public int getPointId() {
return pointId;
}
public void setPointId(int pointId) {
this.pointId = pointId;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public String getAz() {
return az;
}
public void setAz(String az) {
this.az = az;
}
public String getCompare() {
return compare;
}
public void setCompare(String compare) {
this.compare = compare;
}
public String getLapNum() {
return lapNum;
}
public void setLapNum(String lapNum) {
this.lapNum = lapNum;
}
public String getLiveStatus() {
return liveStatus;
}
public void setLiveStatus(String liveStatus) {
this.liveStatus = liveStatus;
}
public String getSelfWeak() {
return selfWeak;
}
public void setSelfWeak(String selfWeak) {
this.selfWeak = selfWeak;
}
}
Android Studio
客户端请求数据,主要使用retrofit2。
TestService:
package com.example.rxjava20.Api;
import com.example.rxjava20.ResponseObj;
import com.example.rxjava20.bean.BasePointModel;
import com.example.rxjava20.bean.News;
import com.example.rxjava20.bean.TestStr;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
/**
* Created by HASEE on 2017/5/2 14:39
*/
public interface TestService {
@FormUrlEncoded
@POST("/")
Call<News> example(@Field("name") String name, @Field("ocupation") String ocupation);
@GET("user1/getCom")
Call<ResponseObj<String>> getCom();
@GET("user1/getPointList")
Call<ResponseObj<List<BasePointModel>>> getPointList();
@GET("user1/getStringList")
Call<ResponseObj<List<TestStr>>> getStringList();
@GET("user1/getStrs")
Call<ResponseObj<String>> getStrs();
}
ZhabServerActivity:
package com.example.rxjava20;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.example.rxjava20.Api.TestService;
import com.example.rxjava20.bean.BasePointModel;
import com.example.rxjava20.bean.TestStr;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* 与IDEA后台对接测试
*/
public class ZhabServerActivity extends AppCompatActivity {
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zhab_server);
text = (TextView) findViewById(R.id.textView);
getPointList();
// getStringList();
// getStrs(); //成功
}
public void getaaa() {
Retrofit retrofit = new Retrofit.Builder()
// .baseUrl("http://172.16.214.24:10002/")
.baseUrl("http://172.16.108.137:10002/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
TestService testService = retrofit.create(TestService.class);
testService.getCom()
.enqueue(new Callback<ResponseObj<String>>() {
@Override
public void onResponse(Call<ResponseObj<String>> call, Response<ResponseObj<String>> response) {
Toast.makeText(ZhabServerActivity.this, "获取成功", Toast.LENGTH_SHORT).show();
text.setText(response.body().data);
}
@Override
public void onFailure(Call<ResponseObj<String>> call, Throwable t) {
Toast.makeText(ZhabServerActivity.this, "获取失败", Toast.LENGTH_SHORT).show();
text.setText(t.toString());
}
});
}
public void getPointList() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://172.16.108.137:10002/")
// .baseUrl("http://172.16.214.24:10002/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
TestService testService = retrofit.create(TestService.class);
testService.getPointList()
.enqueue(new Callback<ResponseObj<List<BasePointModel>>>() {
@Override
public void onResponse(Call<ResponseObj<List<BasePointModel>>> call,
Response<ResponseObj<List<BasePointModel>>> response) {
Toast.makeText(ZhabServerActivity.this, "获取成功", Toast.LENGTH_SHORT).show();
text.setText(response.body().data.get(0).getAz());
}
@Override
public void onFailure(Call<ResponseObj<List<BasePointModel>>> call, Throwable t) {
Log.d("ZhabServerActivity", "获取失败:" + t.toString());
text.setText(t.toString());
}
});
}
public void getStringList() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://172.16.108.137:10002/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
TestService testService = retrofit.create(TestService.class);
testService.getStringList()
.enqueue(new Callback<ResponseObj<List<TestStr>>>() {
@Override
public void onResponse(Call<ResponseObj<List<TestStr>>> call,
Response<ResponseObj<List<TestStr>>> response) {
Toast.makeText(ZhabServerActivity.this, "获取成功", Toast.LENGTH_SHORT).show();
text.setText(response.body().data.get(0).getStr());
}
@Override
public void onFailure(Call<ResponseObj<List<TestStr>>> call, Throwable t) {
Log.d("ZhabServerActivity", "获取失败:" + t.toString());
text.setText(t.toString());
}
});
}
public void getStrs() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://172.16.108.137:10002/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
TestService testService = retrofit.create(TestService.class);
testService.getStrs()
.enqueue(new Callback<ResponseObj<String>>() {
@Override
public void onResponse(Call<ResponseObj<String>> call,
Response<ResponseObj<String>> response) {
Toast.makeText(ZhabServerActivity.this, "获取成功", Toast.LENGTH_SHORT).show();
text.setText(response.body().data);
}
@Override
public void onFailure(Call<ResponseObj<String>> call, Throwable t) {
Log.d("ZhabServerActivity", "获取失败:" + t.toString());
text.setText(t.toString());
}
});
}
}
网友评论