当我将数据插入数据库时,我不知道为什么会有这个逗号(,)。请帮助我。
这是我的代码,用于在SQL Server上使用调用存储过程更新数据:
private void updateDevice(String ipAddress, String deviceName, String deviceLocation,
String deviceSerialNumber, Date awal, Date akhir) {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery(DEVICE_UPDATE);
query.registerStoredProcedureParameter(IP_ADDRESS, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(DEVICE_NAME, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(DEVICE_LOCATION, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(DEVICE_SN, String.class, ParameterMode.IN);
query.registerStoredProcedureParameter(AWAL, Date.class, ParameterMode.IN);
query.registerStoredProcedureParameter(AKHIR, Date.class, ParameterMode.IN);
query.setParameter(IP_ADDRESS, ipAddress);
query.setParameter(DEVICE_NAME, deviceName);
query.setParameter(DEVICE_LOCATION, deviceLocation);
query.setParameter(DEVICE_SN, deviceSerialNumber);
query.setParameter(AWAL, awal);
query.setParameter(AKHIR, akhir);
query.execute();
}
当我尝试插入数据时,结果是带逗号的New York(纽约,纽约)。 我不知道为什么会这样。
更新 控制器
@RequestMapping(value = "/device-location")
public String deviceLocation(@RequestParam(value = "deviceId", required = false) String deviceId,
@RequestParam(value = "action", required = false) String action,
@RequestParam(value = "device-name", required = false) String deviceName,
@RequestParam(value = "device-location", required = false) String deviceLocation,
@RequestParam(value = "device-serial-number", required = false) String deviceSerialNumber, Model model) {
DeviceLocation device = null;
if (action != null) {
// search
if (action.equals("search")) {
if (deviceId != null) {
device = getDevice(deviceId);
System.out.println("device id " + device.toString());
}
}
// update
if (action.equals("update")) {
updateDevice("192.168.2.10", deviceName, deviceLocation, deviceSerialNumber, datePeriod("01/01/2019"), datePeriod("03/03/2019")); }
}
model.addAttribute("result", device);
return "device-location";
}
html获取我的设置数据并获取数据
<form method="post" th:action="@{/device-location}" data-parsley-validate class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="deviceId ">Device IP Address</label>
<div class="col-md-6 col-sm-6 col-xs-12 ">
<input type="text" th:value="${result?.deviceIp}" id="deviceId" name="deviceId" class="form-control col-md-7 col-xs-12">
</div>
<button type="submit" class="btn btn-primary" name="action" value="search"> Search </button>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="device-name">Device Model</label>
<div class="col-md-6 col-sm-6 col-xs-12 ">
<input type="text" id="device-name" name="device-name" class="form-control col-md-7 col-xs-12" th:value="${result?.deviceName}">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="device-location">Device Location</label>
<div class="col-md-6 col-sm-6 col-xs-12 "> <input th:value="${result?.deviceLocation}" type="text " id="device-location" name="device-location" class="form-control col-md-7 col-xs-12"> </div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="device-serial-number">Device Serial Number</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="device-serial-number" th:value="${result?.deviceSerialNumber}" name="device-serial-number" class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12 " for="device-serial-number ">Period</label>
<div class="col-md-3 col-sm-6 col-xs-12 ">
<input type="text" placeholder="Start date" name="device-seria" class=" form-control col-md-3 col-xs-12 ">
</div>
<div class="col-md-3 col-sm-6 col-xs-12 ">
<input placeholder="End date" type="text" name="device-serial" class="form-control col-md-3 col-xs-12 ">
</div>
<div class="clearfix"></div>
</div>
<div class="ln_solid"></div>
<div class="form-group ">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 ">
<button class="btn btn-primary" type="button"> Delete </button>
<button class="btn btn-primary" type="reset ">Reset</button>
<button class="btn btn-success" type="submit" name="action" value="update"> Update </button>
</div>
</div>
</form>