Commit 2a71c759 by shj

差旅费数据库添加数据

parent d6679a63
package handlers; package handlers;
import beans.Budget; import beans.*;
import beans.Consultation;
import beans.Equipment;
import beans.Labour;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import dao.IConsultationDao; import dao.IConsultationDao;
import dao.IEquipmentDao; import dao.IEquipmentDao;
import dao.ILabourDao; import dao.ILabourDao;
import dao.ITravelDao;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -104,4 +102,37 @@ public class DatabaseQueryHandler { ...@@ -104,4 +102,37 @@ public class DatabaseQueryHandler {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Autowired
private ITravelDao travelDao;
@RequestMapping("/Travel")
public void queryTravel(HttpServletRequest request, HttpServletResponse response){
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
List<Travel> travels = travelDao.selectAll();
List<JSONObject> list=new LinkedList<>();
for (Travel item : travels) {
JSONObject obj=new JSONObject();
obj.put("id",item.getId());
obj.put("name",item.getName());
obj.put("price",item.getPrice());
obj.put("food",item.getFood());
obj.put("traffic",item.getTraffic());
obj.put("accommodation",item.getAccommodation());
obj.put("people",item.getPeople());
obj.put("days",item.getDays());
obj.put("nums",0);
list.add(obj);
}
object.put("data",list);
writer.write(JSON.toJSONString(object));
} catch (IOException e) {
e.printStackTrace();
}
}
} }
...@@ -290,6 +290,27 @@ ...@@ -290,6 +290,27 @@
<button class="btn btn-success" @click="add(sample)">添加</button> <button class="btn btn-success" @click="add(sample)">添加</button>
</td> </td>
</tr> </tr>
<tr class="info" v-if="database.length>0">
<td>
<select v-model="selectedIndex" class="form-control">
<option v-for="(record,i) in database" :value="i">
{{record.name}}
</option>
</select>
</td>
<td>
<input type="number" v-model="database[selectedIndex].price" class="form-control">
</td>
<td><input type="number" v-model="database[selectedIndex].food" class="form-control"></td>
<td><input type="number" v-model="database[selectedIndex].traffic" class="form-control"></td>
<td><input type="number" v-model="database[selectedIndex].accommodation" class="form-control"></td>
<td><input type="number" v-model="database[selectedIndex].people" class="form-control"></td>
<td><input type="number" v-model="database[selectedIndex].days" class="form-control"></td>
<td>
<button class="btn btn-success" @click="add(database[selectedIndex])">添加</button>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
...@@ -850,7 +871,9 @@ ...@@ -850,7 +871,9 @@
el: "#travel", el: "#travel",
data: { data: {
items: [], items: [],
sample: {name: "sample", price: 0, food: 0, accommodation: 0, traffic: 0, days: 0, people: 0, nums: 0} sample: {name: "sample", price: 0, food: 0, accommodation: 0, traffic: 0, days: 0, people: 0, nums: 0},
database:[{name: "sample", price: 0, food: 0, accommodation: 0, traffic: 0, days: 0, people: 0, nums: 0}],
selectedIndex:0
}, },
methods: { methods: {
update: function (item) { update: function (item) {
...@@ -867,7 +890,27 @@ ...@@ -867,7 +890,27 @@
function (data) { function (data) {
this.items = data.body.data; this.items = data.body.data;
console.log("showlist"); console.log("showlist");
updateBudgetPage("travel") updateBudgetPage("travel");
this.showDatabase();
}, function (error) {
console.log(error)
}
)
},
showDatabase:function(){
this.$http.get("${pageContext.request.contextPath}/Database/Query/Travel").then(
function (data) {
var tmp= data.body.data;
for(var i=0;i<tmp.length;i++)
{
if(inItems(tmp[i],this.items)){
console.log("inItems:true, "+tmp[i].name);
tmp.splice(i,1);
i--;
}
}
this.database=tmp;
console.log("show database");
}, function (error) { }, function (error) {
console.log(error) console.log(error)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment