idea中传统SSM+jsp项目的搭建 |
您所在的位置:网站首页 › idea运行jsp文件 › idea中传统SSM+jsp项目的搭建 |
idea中传统SSM+jsp项目的搭建
创建ss项目创建一个普通java项目改造项目测试配置tomcat
整合jsp在pom.xml中导入jsp依赖在Spring-servlet.xml中配置视图在web.xml中配置一下过滤器测试
整合mybaties在pom.xml中添加mybaties依赖创建db.properties在applicationContext中配置事务、连接池、mybaties测试
创建ss项目
创建一个普通java项目
改造项目 在pom.xml里设置打包 配置web 在pom里面加入依赖 org.springframework spring-webmvc 5.0.8.RELEASE org.springframework spring-jdbc 5.0.8.RELEASE org.aspectj aspectjrt 1.8.12 org.aspectj aspectjweaver 1.8.12 mysql mysql-connector-java 5.1.27 com.alibaba druid 1.1.10在resources里面新建两个配置文件 创建controller等文件 重启idea在之前创建的applicationContext中配置包扫描 在spring-servlet中配置 在web.xml里面配置 contextConfigLocation classpath:applicationContext.xml org.springframework.web.context.ContextLoaderListener springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:Spring-servlet.xml springmvc / 测试在controller里面新建HelloController和HelloService package org.touxian.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.touxian.service.HelloService; /** * @author 偷闲 * @date 2019/5/15 11:07 */ @RestController public class HelloController { @Autowired HelloService helloService; @RequestMapping("/hello") public String hello(){ return helloService.hello(); } } package org.touxian.service; import org.springframework.stereotype.Service; /** * @author 偷闲 * @date 2019/5/15 11:05 */ @Service public class HelloService { public String hello(){ return "hello"; } } 配置tomcat运行tomcat通过http://localhost:8022/touxianT_war_exploded/hello请求如果出现hello说明ss配置成功 整合jsp 在pom.xml中导入jsp依赖 javax.servlet javax.servlet-api 4.0.1 javax.servlet.jsp javax.servlet.jsp-api 2.3.1 jstl jstl 1.2 在Spring-servlet.xml中配置视图 在web.xml中配置一下过滤器 encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceRequestEcoding true forceResponseEconding true encodingFilter /* 测试在controller下创建IndexController 代码如下 package org.touxian.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** * @author 偷闲 * @date 2019/5/15 15:28 */ @Controller public class IndexController { @RequestMapping("index") public String index(){ return "index"; } }在WEN-INF下新建index.jsp Title 你好,创建者启动项目,通过http://localhost:8022/touxianT_war_exploded/index访问如果出现jsp内容表示jsp整合成功 整合mybaties 在pom.xml中添加mybaties依赖 org.mybatis mybatis 3.4.6 org.mybatis mybatis-spring 1.3.2 创建db.properties url=jdbc:mysql://localhost:3306/testdemo?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 username=root password=root driverClassName=com.mysql.jdbc.Driver filters=stat maxActive=20 initialSize=1 maxWait=60000 minIdle=10 maxIdle=15 timeBetweenEvictionRunsMillis=60000 minEvictableIdleTimeMillis=300000 validationQuery=SELECT 'x' testWhileIdle=true testOnBorrow=false testOnReturn=false maxOpenPreparedStatements=20 removeAbandoned=true removeAbandonedTimeout=1800 logAbandoned=true 在applicationContext中配置事务、连接池、mybaties在applicationContext中 配置连接池 classpath:db.properties配置事务 配置mybaties classpath*:/mybaties/*/*.xml 测试创建一个数据库testdemo CREATE TABLE `book_type` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type_name` varchar(255) DEFAULT NULL, `sort` int(11) DEFAULT NULL, `remark` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;添加一些数据 创建book_type类 package org.touxian.vo; /** * @author 偷闲 * @date 2019/4/28 16:00 */ public class Book_type { private Integer id; private String type_name; private Integer sort; private String remark; @Override public String toString() { return "Book_type{" + "id=" + id + ", type_name='" + type_name + '\'' + ", sort=" + sort + ", remark='" + remark + '\'' + '}'; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getType_name() { return type_name; } public void setType_name(String type_name) { this.type_name = type_name; } public Integer getSort() { return sort; } public void setSort(Integer sort) { this.sort = sort; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } }创建mapper package org.touxian.service.Book; import org.touxian.vo.Book_type; import java.util.List; /** * @author 偷闲 * @date 2019/4/28 15:25 */ public interface Book_typeMapper { List getalltype(); }在resources下创建mybaties select * from book_type;添加typeController package org.touxian.controller; /** * @author 偷闲 * @date 2019/5/7 10:02 */ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.touxian.service.Book.Book_typeMapper; import org.touxian.vo.Book_type; import java.util.List; @Controller public class TypeController { @Autowired Book_typeMapper book_typeservice; @RequestMapping("type") public String hello(Model mod){ List alltype= book_typeservice.getalltype(); mod.addAttribute("alltype",alltype); return "type_list"; } }新建type_list.jsp Title 序号 名称 备注 ${var.sort} ${var.type_name} ${var.remark}启动项目使用http://localhost:8022/touxianT_war_exploded/type访问 整合成功 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |