1.代码
@Autowired private SqlSessionFactoryBean sqlSessionFactory ; @RequestMapping(value = "f3") public String f3( @RequestBody Mapmap,HttpServletRequest request, HttpServletResponse response) throws Exception { SqlSessionFactory object = sqlSessionFactory.getObject(); SqlSession session = null; try { session = object.openSession(); Object selectOne = session.selectOne("test.get2", map); MappedStatement mappedStatement = session.getConfiguration().getMappedStatement("test.get2"); String jsonString = JsonMapper.toJsonString(selectOne); System.out.println(11); } finally { session.close(); } return "f1"; }
2.前台
$.ajax({ url :'${ctx}/test/testData/f3?book=java', type: 'post', dataType : "json", contentType:'application/json;charset=UTF-8',//关键是要加上这行 data : JSON.stringify( {id:'22',remarks:'aaa'}), async : false, // 同步请求 success : function(data) { debugger ; } });
3,转成json ,在数据库就转成 json
<select id="get2" resultType="map">
SELECT id,user_id, date_format(create_date,'%Y-%m-%d') as cdate FROM test_data a WHERE a.id = #{id} </select>
4, 数据对比
a.id AS "id", a.user_id AS "user.id", a.office_id AS "office.id", a.area_id AS "area.id", a.name AS "name", a.sex AS "sex", a.in_date AS "inDate", a.create_by AS "createBy.id", date_format(create_date,'%Y-%m-%d') AS "createDate", a.update_by AS "updateBy.id", date_format(update_date,'%Y-%m-%d') AS "updateDate", a.remarks AS "remarks", testint, a.del_flag AS "delFlag"
上面可以重新 封装成map