springmvc小專案
package com.zxp.domain;
import java.util.Date;
/**
* @author zxp
*/
public class Items {
private Integer id;
private String name;
private Double price;
private String pic;
private Date createtime;
private String detail;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
}
package com.zxp.dao;
import com.zxp.domain.Items;
/**
-
@author zxp
*/
public interface ItemsDao {public Items findById(Integer id);
}
package com.zxp.service;
import com.zxp.domain.Items;
/**
* @author zxp
*/
public interface ItemsServiceDao {
public Items findById(Integer id);
}
```package com.zxp.service.impl;
import com.zxp.dao.ItemsDao;
import com.zxp.domain.Items;
import com.zxp.service.ItemsServiceDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author zxp
*/
@Service
public class ItemsServiceImpl implements ItemsServiceDao {
@Autowired
private ItemsDao itemsDao;
public Items findById(Integer id) {
return itemsDao.findById(id);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zxp.dao.ItemsDao">
<select id="findById" parameterType="int" resultType="items">
select * from items where id =#{id}
</select>
</mapper>
package com.zxp.controller;
import com.zxp.domain.Items;
import com.zxp.service.ItemsServiceDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author zxp
*/
@Controller
@RequestMapping("/items")
public class ItemsController {
@Autowired
private ItemsServiceDao itemsServiceDao;
@RequestMapping("/findDetials")
public String findDetials(Model model){
Items byId = itemsServiceDao.findById(1);
model.addAttribute("item",byId);
return "itemDetail";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--dao配置檔案開始-->
<!--配置連線池-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/maven?serverTimezone=UTC"></property>
<property name="username" value="root"></property>
<property name="password" value="zp1536338"></property>
</bean>
<!--Sqlsession-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--掃描pojo包,給包下所有pojo物件起別名-->
<property name="typeAliasesPackage" value="com.zxp.domain"></property>
</bean>
<!--掃描介面包路徑,生成包所有介面的代理物件,放入容器中-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.zxp.dao"></property>
</bean>
<!--dao配置檔案結束-->
<!--配置元件掃描配置-->
<context:component-scan base-package="com.zxp.service"/>
<!--配置事務管理器-->
<bean id="transactionManager" class=" org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--配置事務通知-->
<tx:advice id="advice">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="find*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!--配置切面-->
<aop:config>
<aop:pointcut id="poincut" expression= "execution(* com.zxp.service.impl.*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="advice" pointcut-ref="poincut"/>
</aop:config>
</beans>
# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE debug info warn error fatal
log4j.rootCategory=debug, CONSOLE, LOGFILE
# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=d:\axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.zxp.controller"/>
<mvc:annotation-driven />
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp" />
</bean>
<mvc:default-servlet-handler />
</beans>
package com.zxp.test;
import com.zxp.dao.ItemsDao;
import com.zxp.domain.Items;
import com.zxp.service.ItemsServiceDao;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author zxp
*/
public class ItemTest {
@Test
public void findById(){
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
// ItemsDao itemsDao = ac.getBean(ItemsDao.class);
Items byId = itemsDao.findById(1);
System.out.println(byId.getName());
ItemsServiceDao bean = ac.getBean(ItemsServiceDao.class);
Items byId = bean.findById(1);
System.out.println(byId.getName());
}
}
相關文章
- SpringBoot專案建立流程--SpringMVCSpring BootSpringMVC
- SpringMVC的專案架構思想SpringMVC架構
- IDEA建立SpringMVC+Gradle專案IdeaSpringMVCGradle
- IntelliJ IDEA 建立Spring+SpringMVC+mybatis+maven專案IntelliJIdeaSpringMVCMyBatisMaven
- SpringMVC——HTTP請求專案實踐整理總結SpringMVCHTTP
- ssm專案的搭建:使用到框架 spring springmvc mybatisSSM框架SpringMVCMyBatis
- 飛機小專案
- 爬蟲小專案爬蟲
- SpringMVC框架詳細教程(二)_建立動態Web專案SpringMVC框架Web
- Mysql-cluster小專案MySql
- 考勤系統+(小專案)
- 小程式專案-總結
- 初步建立小程式專案
- 小程式專案總結
- 小程式專案之填坑小記
- 專案實戰小問題:
- GitHub 搜尋專案小技巧Github
- vue專案技術小記Vue
- Python 專案開發小技巧Python
- 兩小時手寫springmvc框架SpringMVC框架
- 建立一個簡單的初級SpringMVC專案(非註解版)SpringMVC
- SpringMVC之檔案上傳SpringMVC
- SpringMvc本地上傳檔案SpringMVC
- 使用 webpack 構建小程式專案Web
- Vue SPA專案優化小記Vue優化
- PLC300四個小專案
- 專案小組成員介紹
- 小程式視訊專案筆記筆記
- 分享個 golang 開源小專案Golang
- 專案管理小結(如何做好一個百萬級專案甚至千萬級別的專案)專案管理
- 《SpringMVC從入門到放肆》十五、SpringMVC之上傳檔案SpringMVC
- SpringMvc+Spring+mybatis配置檔案SpringMVCMyBatis
- 專案需求討論 – 定位功能小結
- 小程式雲開發專案實戰
- 小程式的專案結構設計
- 專案需求討論 - 定位功能小結
- 小專案不想引入 MQ?試試 Debezium!MQ
- IDEA匯入專案有個小JIdea