mapper:
<select id="getDate" resultType="org.his.beans.OutBound">
select distinct ny from OutBound order by ny desc
</select>
controller:
@RequestMapping("/main")
@ResponseBody
public ModelAndView main(HttpServletResponse response, ModelAndView mv, HttpServletRequest request) {
try {
List<OutBound> list = service.getDate();
JSONArray jsonArray = JSONArray.fromObject(list);
mv.addObject("jsonArray",jsonArray);
System.out.println(jsonArray);
return mv;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
jsp:
<script type="text/javascript">
$(document).ready(
function() {
$.ajax({
type : "POST",
url : "main",
dataType : "json",
success : function(data) {
alert(data);
for (var i = 0; i < data.length; i++) {
$("#ny").append(
"<option>" + data[i].NY + "</option>");
}
}
});
});
</script>