1.config
package com.zerosky.common.config;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.OracleDialect;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.zerosky.common.controller.NoticeController;
import com.zerosky.common.model.Notice;
public class MainConfig extends JFinalConfig {
/**
* 配置JFinal常量
*/
@Override
public void configConstant(Constants me) {
me.setDevMode(true);
me.setViewType(ViewType.JSP);//设置当前的视图类型
// me.setBaseViewPath("/WEB-INF/view");
}
/**
* 配置JFinal路由映射
*/
@Override
public void configRoute(Routes me) {
me.add("/",NoticeController.class);
me.add("/notice", NoticeController.class);
}
/**
* 配置JFinal插件
* 数据库连接池
* ORM
* 缓存等插件
* 自定义插件
*/
@Override
public void configPlugin(Plugins me) {
// 配置C3p0数据库连接池插件,获取驱动、数据库、用户及密码
C3p0Plugin cp = new C3p0Plugin("jdbc:oracle:thin:@localhost:1521:orcl ", "stx", "stx");
//配置Oracle驱动
cp. setDriverClass("oracle.jdbc.driver.OracleDriver");
me.add(cp);
ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
me.add(arp);
// 配置Oracle方言
arp.setDialect(new OracleDialect());
// 配置属性名(字段名)大小写不敏感容器工厂
arp.setContainerFactory(new CaseInsensitiveContainerFactory());
//映射LK_Notice表到Notice模型
arp.addMapping("LK_Notice", Notice.class);
}
/**
* 配置全局拦截器
*/
@Override
public void configInterceptor(Interceptors me) {
}
/**
* 配置全局处理器
*/
@Override
public void configHandler(Handlers me) {
}
public static void main(String[] args) {
JFinal.start("WebRoot", 80, "/", 5);
}
}
2.controller
package com.zerosky.common.controller;
import java.util.List;
import com.jfinal.core.Controller;
import com.zerosky.common.model.Notice;
public class NoticeController extends Controller {
public void index(){
// renderJsp("/index.html");
render("/index.jsp");
}
public void save() {
Notice notice = this.getModel(Notice.class);
//Oracle数据库使用序列
notice.set("id", "test_seq_notice.nextval");
notice.set("content", "插入语句!");
notice.set("state", "1");
notice.save();
forwardAction("notice/index");
}
public void get() {
Notice notice = this.getModel(Notice.class);
List<Notice> list = notice.find("select content,stime from LK_NOTICE where state=1");
renderJson("list",list);
}
}
3.js
function getNoticeList() {
$.ajax({
type: "GET",
url: "/get",
// list:{},
// data: {},
dataType: "json",
success: function (res) {
// var list = res.list;
if (res.code == 1) {//josn
var list = res.list;
for (var i = 0; i < list.length; i++) {
var html = "";
html += '<div class="part">';
html += '<div class="content-text">';
html += '<p>公告内容<span>'+ list[i].CONTENT +'</span></p>';
html += '<P>发布时间<span>'+ list[i].stime +'</span></P>';
html += '</div>';
html += '</div>';
$(".notice1").append(jsp);
}
}
}
});
}
4.jsp
<script type="text/javascript">
getNoticeList();
</script>
</head>
<body>
<div class="notice1"></div>
<script src="../js/jquery-1.9.1.min.js"></script>
<script src="../js/createList.js"></script>
</body>
</html>