This commit is contained in:
zhuangqian 2016-11-24 19:02:38 +08:00
parent de41f59917
commit 8f191859a2
2 changed files with 121 additions and 118 deletions

View File

@ -1,113 +1,113 @@
package com.smallchill.platform.controller; package com.smallchill.platform.controller;
import java.util.Map; import java.util.Map;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.smallchill.common.base.BaseController; import com.smallchill.common.base.BaseController;
import com.smallchill.common.tool.SysCache; import com.smallchill.common.tool.SysCache;
import com.smallchill.core.plugins.dao.Blade; import com.smallchill.core.plugins.dao.Blade;
import com.smallchill.core.plugins.dao.Md; import com.smallchill.core.plugins.dao.Md;
import com.smallchill.core.toolbox.Paras; import com.smallchill.core.toolbox.Paras;
import com.smallchill.core.toolbox.ajax.AjaxResult; import com.smallchill.core.toolbox.ajax.AjaxResult;
import com.smallchill.core.toolbox.kit.JsonKit; import com.smallchill.core.toolbox.kit.JsonKit;
import com.smallchill.platform.model.Notice; import com.smallchill.platform.model.Notice;
@Controller @Controller
@RequestMapping("/notice") @RequestMapping("/notice")
public class NoticeController extends BaseController { public class NoticeController extends BaseController {
private static String CODE = "notice"; private static String CODE = "notice";
private static String PREFIX = "TB_YW_TZGG"; private static String PREFIX = "TB_YW_TZGG";
private static String DATA_SOURCE = "notice.data"; private static String DATA_SOURCE = "notice.data";
private static String LIST_SOURCE = "notice.list"; private static String LIST_SOURCE = "notice.list";
private static String BASE_PATH = "/platform/notice/"; private static String BASE_PATH = "/platform/notice/";
@RequestMapping(KEY_MAIN) @RequestMapping(KEY_MAIN)
public String index(ModelMap mm) { public String index(ModelMap mm) {
mm.put("code", CODE); mm.put("code", CODE);
return BASE_PATH + "notice.html"; return BASE_PATH + "notice.html";
} }
@RequestMapping(KEY_ADD) @RequestMapping(KEY_ADD)
public String add(ModelMap mm) { public String add(ModelMap mm) {
mm.put("code", CODE); mm.put("code", CODE);
return BASE_PATH + "notice_add.html"; return BASE_PATH + "notice_add.html";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@RequestMapping(KEY_EDIT + "/{id}") @RequestMapping(KEY_EDIT + "/{id}")
public String edit(@PathVariable String id, ModelMap mm) { public String edit(@PathVariable String id, ModelMap mm) {
Map map = Md.selectOne(DATA_SOURCE, Paras.create().set("id", id), Map.class); Map map = Md.selectOne(DATA_SOURCE, Paras.create().set("id", id), Map.class);
mm.put("model", JsonKit.toJson(map)); mm.put("model", JsonKit.toJson(map));
mm.put("id", id); mm.put("id", id);
mm.put("code", CODE); mm.put("code", CODE);
return BASE_PATH + "notice_edit.html"; return BASE_PATH + "notice_edit.html";
} }
@RequestMapping(KEY_VIEW + "/{id}") @RequestMapping(KEY_VIEW + "/{id}")
public String view(@PathVariable String id, ModelMap mm) { public String view(@PathVariable String id, ModelMap mm) {
Notice notice = Blade.create(Notice.class).findById(id); Notice notice = Blade.create(Notice.class).findById(id);
//将javabean转化为map //将javabean转化为map
Paras ps = Paras.parse(notice); Paras ps = Paras.parse(notice);
//使用SysCache.getDictName方法从缓存中获取对应字典项的中文值 //使用SysCache.getDictName方法从缓存中获取对应字典项的中文值
ps.set("dic_f_it_lx", SysCache.getDictName(102, notice.getF_it_lx())); ps.set("dic_f_it_lx", SysCache.getDictName(102, notice.getF_it_lx()));
//将结果传回前台 //将结果传回前台
mm.put("model", JsonKit.toJson(ps)); mm.put("model", JsonKit.toJson(ps));
mm.put("id", id); mm.put("id", id);
mm.put("code", CODE); mm.put("code", CODE);
return BASE_PATH + "notice_view.html"; return BASE_PATH + "notice_view.html";
} }
@ResponseBody @ResponseBody
@RequestMapping(KEY_LIST) @RequestMapping(KEY_LIST)
public Object list() { public Object list() {
Object grid = paginate(LIST_SOURCE); Object grid = paginate(LIST_SOURCE);
return grid; return grid;
} }
@ResponseBody @ResponseBody
@RequestMapping(KEY_SAVE) @RequestMapping(KEY_SAVE)
public AjaxResult save() { public AjaxResult save() {
Notice notice = mapping(PREFIX, Notice.class); Notice notice = mapping(PREFIX, Notice.class);
boolean temp = Blade.create(Notice.class).save(notice); boolean temp = Blade.create(Notice.class).save(notice);
if (temp) { if (temp) {
return success(SAVE_SUCCESS_MSG); return success(SAVE_SUCCESS_MSG);
} else { } else {
return error(SAVE_FAIL_MSG); return error(SAVE_FAIL_MSG);
} }
} }
@ResponseBody @ResponseBody
@RequestMapping(KEY_UPDATE) @RequestMapping(KEY_UPDATE)
public AjaxResult update() { public AjaxResult update() {
Notice notice = mapping(PREFIX, Notice.class); Notice notice = mapping(PREFIX, Notice.class);
//1.使用mapper //1.使用mapper
//NoticeMapper mapper = Md.getMapper(NoticeMapper.class); //NoticeMapper mapper = Md.getMapper(NoticeMapper.class);
//boolean temp = mapper.updateTemplateById(notice) > 0; //boolean temp = mapper.updateTemplateById(notice) > 0;
//2.使用sql模板 //2.使用sql模板
//boolean temp = Md.update("notice.update", notice) > 0; //boolean temp = Md.update("notice.update", notice) > 0;
//3.使用自动生成api //3.使用自动生成api
boolean temp = Blade.create(Notice.class).update(notice); boolean temp = Blade.create(Notice.class).update(notice);
if (temp) { if (temp) {
return success(UPDATE_SUCCESS_MSG); return success(UPDATE_SUCCESS_MSG);
} else { } else {
return error(UPDATE_FAIL_MSG); return error(UPDATE_FAIL_MSG);
} }
} }
@ResponseBody @ResponseBody
@RequestMapping(KEY_REMOVE) @RequestMapping(KEY_REMOVE)
public AjaxResult remove() { public AjaxResult remove() {
int cnt = Blade.create(Notice.class).deleteByIds(getParameter("ids")); int cnt = Blade.create(Notice.class).deleteByIds(getParameter("ids"));
if (cnt > 0) { if (cnt > 0) {
return success(DEL_SUCCESS_MSG); return success(DEL_SUCCESS_MSG);
} else { } else {
return error(DEL_FAIL_MSG); return error(DEL_FAIL_MSG);
} }
} }
} }

View File

@ -21,11 +21,6 @@
<!-- 注册sqlmanager(主库) --> <!-- 注册sqlmanager(主库) -->
<bean id="sqlManager" class="org.beetl.sql.ext.spring4.SqlManagerFactoryBean"> <bean id="sqlManager" class="org.beetl.sql.ext.spring4.SqlManagerFactoryBean">
<property name="sqlLoader">
<bean class="org.beetl.sql.core.ClasspathLoader">
<property name="sqlRoot" value="/beetlsql"></property>
</bean>
</property>
<property name="nc"> <property name="nc">
<bean class="org.beetl.sql.core.DefaultNameConversion"></bean> <bean class="org.beetl.sql.core.DefaultNameConversion"></bean>
</property> </property>
@ -42,6 +37,14 @@
<property name="dbStyle"> <property name="dbStyle">
<bean class="org.beetl.sql.core.db.MySqlStyle"></bean> <bean class="org.beetl.sql.core.db.MySqlStyle"></bean>
</property> </property>
<property name="sqlLoader">
<bean class="org.beetl.sql.core.ClasspathLoader">
<property name="sqlRoot" value="/beetlsql"></property>
<property name="dbs">
<bean class="org.beetl.sql.core.db.MySqlStyle"></bean>
</property>
</bean>
</property>
<property name="configLocation" value="classpath:/config/beetlsql.properties"></property> <property name="configLocation" value="classpath:/config/beetlsql.properties"></property>
</bean> </bean>