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());
}
}
相關文章
- SpringMVC專案模組淺析SpringMVC
- SpringMVC的專案架構思想SpringMVC架構
- SpringBoot專案建立流程--SpringMVCSpring BootSpringMVC
- java-springmvc4-web專案搭建JavaSpringMVCWeb
- spring-springmvc專案介紹SpringMVC
- 降魔篇之springmvc專案開發SpringMVC
- IDEA建立SpringMVC+Gradle專案IdeaSpringMVCGradle
- spring-springmvc-mybatis專案介紹SpringMVCMyBatis
- Spirng+SpringMVC+Maven+Mybatis+MySQL專案搭建SpringMVCMavenMyBatisMySql
- 爬蟲小專案爬蟲
- 飛機小專案
- 小專案模組外包
- Maven搭建SpringMVC+Mybatis專案詳解【轉】MavenSpringMVCMyBatis
- 小程式專案之填坑小記
- 考勤系統+(小專案)
- Mysql-cluster小專案MySql
- 小程式專案總結
- 初步建立小程式專案
- 小程式專案-總結
- 續專案管理小結專案管理
- 微信小程式上手專案微信小程式
- SpringMVC——HTTP請求專案實踐整理總結SpringMVCHTTP
- SpringMVC框架詳細教程(二)_建立動態Web專案SpringMVC框架Web
- ssm專案的搭建:使用到框架 spring springmvc mybatisSSM框架SpringMVCMyBatis
- GitHub 搜尋專案小技巧Github
- vue專案技術小記Vue
- 專案實戰小問題:
- 爬蟲小專案(一)淘寶爬蟲
- 前端練手專案小結前端
- vue全家桶上手小專案Vue
- 小專案跟蹤記錄
- IntelliJ IDEA 建立Spring+SpringMVC+mybatis+maven專案IntelliJIdeaSpringMVCMyBatisMaven
- Spring+SpringMvc+Mybatis框架整合搭建教程一(專案建立)SpringMVCMyBatis框架
- springMVC專案國際化(i18n)實現方法SpringMVC
- 圖書管理系統專案(初學者必看的小專案)
- 兩小時手寫springmvc框架SpringMVC框架
- 使用 webpack 構建小程式專案Web
- 分享個 golang 開源小專案Golang