生产po、mapper相关文件,看图。
如何通过mybatis逆向工程生成,见链接。后续更新
测试类 mybatis框架测试在src/test/java下面进行创建包com.flyme.service,在此下面进行创建CourseServiceImplTest测试类,以用来测试mybatis框架是否搭建成功。
CourseServiceImplTest.java package com.flyme.service; import com.flyme.po.Course; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class CourseServiceImplTest { private ApplicationContext applicationContext; @Before public void setUp() throws Exception { applicationContext = new ClassPathXmlApplicationContext(new String[]{"spring/applicationContext-dao.xml", "spring/applicationContext-service.xml"}); } @Test public void findById() throws Exception { CourseService courseService = (CourseService) applicationContext.getBean("courseServiceImpl"); Course course = courseService.findById(1); System.out.println(course.toString()); } }运行findById()方法,出现以下图,证明搭建成功
在src/main/java,com.flyme.controller包下面创建AdminController.java,以用来测SpringMVC框架是否搭建成功。
package com.flyme.controller; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/myController") public class AdminController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name = req.getParameter("name"); req.setAttribute("name", name); System.out.println(name); req.getRequestDispatcher("index.jsp").forward(req, resp); } } idex.jsp <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <form action="myController" method="post"> <input> return:${name} <input value="提交" type="submit"> </form> </body> </html>运行项目
配置Tomcat最后选择OK,即可。
浏览器输入 :8010/ (因为笔者改动了端口号,灵活应用)
输入:“我是”
结果:
配置成功 问题集锦如有问题欢迎评论
...